Skip to content

Commit b19dd05

Browse files
committed
featconvert form json to excels sheet
1 parent e06a177 commit b19dd05

6 files changed

Lines changed: 224 additions & 26 deletions

File tree

package-lock.json

Lines changed: 105 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,20 @@
99
"lint": "next lint"
1010
},
1111
"dependencies": {
12+
"next": "15.3.0",
1213
"react": "^19.0.0",
1314
"react-dom": "^19.0.0",
14-
"next": "15.3.0"
15+
"xlsx": "^0.18.5"
1516
},
1617
"devDependencies": {
17-
"typescript": "^5",
18+
"@eslint/eslintrc": "^3",
19+
"@tailwindcss/postcss": "^4",
1820
"@types/node": "^20",
1921
"@types/react": "^19",
2022
"@types/react-dom": "^19",
21-
"@tailwindcss/postcss": "^4",
22-
"tailwindcss": "^4",
2323
"eslint": "^9",
2424
"eslint-config-next": "15.3.0",
25-
"@eslint/eslintrc": "^3"
25+
"tailwindcss": "^4",
26+
"typescript": "^5"
2627
}
2728
}

public/.~lock.tools.xlsx#

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
,shadilrayyan,pop-os,04.07.2025 01:33,file:///home/shadilrayyan/.config/libreoffice/4;

public/tools.xlsx

9.24 KB
Binary file not shown.

src/app/page.tsx

Lines changed: 89 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,95 @@
11
'use client';
2-
import { useState } from "react";
3-
import Image from "next/image"; // make sure this is at the top
4-
import toolsData, { OS, PkgManager } from "@/data/tool";
52

3+
import { useEffect, useState } from "react";
4+
import * as XLSX from "xlsx";
5+
import Image from "next/image";
6+
7+
type OS = "windows" | "macos" | "linux";
8+
type WindowsPkg = "choco" | "winget" | "scoop";
9+
type MacPkg = "homebrew";
10+
type LinuxPkg = "apt" | "dnf" | "pacman";
11+
type PkgManager = WindowsPkg | MacPkg | LinuxPkg;
12+
13+
interface Tool {
14+
name: string;
15+
iconsrc: string;
16+
install: Partial<Record<PkgManager, string>>;
17+
}
18+
19+
interface ToolCategory {
20+
category: string;
21+
tools: Tool[];
22+
}
623

724
const osOptions: OS[] = ["windows", "macos", "linux"];
825
const pkgManagers: Record<OS, PkgManager[]> = {
926
windows: ["choco", "winget", "scoop"],
1027
macos: ["homebrew"],
11-
linux: ["apt", "dnf", "pacman"]
28+
linux: ["apt", "dnf", "pacman"],
1229
};
1330

14-
15-
1631
export default function ScriptGenerator() {
32+
const [toolsData, setToolsData] = useState<ToolCategory[]>([]);
1733
const [selectedOS, setSelectedOS] = useState<OS>("windows");
1834
const [selectedPkg, setSelectedPkg] = useState<PkgManager>("choco");
1935
const [selectedTools, setSelectedTools] = useState<string[]>([]);
36+
const [loading, setLoading] = useState(true);
37+
38+
// Load and parse Excel on mount
39+
useEffect(() => {
40+
const fetchAndParse = async () => {
41+
try {
42+
const res = await fetch("/tools.xlsx");
43+
const arrayBuffer = await res.arrayBuffer();
44+
const workbook = XLSX.read(arrayBuffer, { type: "array" });
45+
46+
// Assuming sheet 1 contains your data in a suitable format.
47+
const sheetName = workbook.SheetNames[0];
48+
const worksheet = workbook.Sheets[sheetName];
49+
// Parse sheet to JSON
50+
const jsonData: any[] = XLSX.utils.sheet_to_json(worksheet, { defval: "" });
51+
52+
// Transform flat rows into structured ToolCategory[]
53+
// Adjust this logic according to your Excel structure.
54+
// Here is an example assuming columns: category, name, iconsrc, install_choco, install_apt, etc.
55+
56+
const categoriesMap: Record<string, ToolCategory> = {};
57+
58+
jsonData.forEach((row) => {
59+
const category = row.category || "Uncategorized";
60+
61+
if (!categoriesMap[category]) {
62+
categoriesMap[category] = { category, tools: [] };
63+
}
64+
65+
const install: Partial<Record<PkgManager, string>> = {};
66+
67+
// Check all known package manager columns, adjust to your Excel headers
68+
const pkgCols = ["choco", "winget", "scoop", "homebrew", "apt", "dnf", "pacman"];
69+
pkgCols.forEach((pkg) => {
70+
const colName = `install_${pkg}`;
71+
if (row[colName]) {
72+
install[pkg as PkgManager] = row[colName];
73+
}
74+
});
75+
76+
categoriesMap[category].tools.push({
77+
name: row.name,
78+
iconsrc: row.iconsrc,
79+
install,
80+
});
81+
});
82+
83+
setToolsData(Object.values(categoriesMap));
84+
setLoading(false);
85+
} catch (error) {
86+
console.error("Failed to load Excel data", error);
87+
setLoading(false);
88+
}
89+
};
90+
91+
fetchAndParse();
92+
}, []);
2093

2194
const handleToolSelect = (toolName: string) => {
2295
setSelectedTools((prev) =>
@@ -55,6 +128,14 @@ export default function ScriptGenerator() {
55128
document.body.removeChild(link);
56129
};
57130

131+
if (loading) {
132+
return (
133+
<div className="text-white font-sans text-center mt-20">
134+
Loading tools data...
135+
</div>
136+
);
137+
}
138+
58139
return (
59140
<div className="bg-[#0d1117] min-h-screen text-white font-sans">
60141
<div className="max-w-screen mx-auto px-4 py-10">
@@ -128,13 +209,8 @@ export default function ScriptGenerator() {
128209
onChange={() => handleToolSelect(tool.name)}
129210
className="mb-3 w-5 h-5 accent-indigo-500"
130211
/>
131-
<Image
132-
src={tool.iconsrc}
133-
alt={tool.name}
134-
width={40}
135-
height={40}
136-
className="object-contain mb-2"
137-
/>
212+
<img src={tool.iconsrc} alt={tool.name} width={40} height={40} />
213+
138214
<span className="text-sm text-center">{tool.name}</span>
139215
</label>
140216
);

tsconfig.json

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
{
22
"compilerOptions": {
33
"target": "ES2017",
4-
"lib": ["dom", "dom.iterable", "esnext"],
4+
"lib": [
5+
"dom",
6+
"dom.iterable",
7+
"esnext"
8+
],
59
"allowJs": true,
610
"skipLibCheck": true,
7-
"strict": true,
8-
"noEmit": true,
11+
// "strict": true,
12+
// "noEmit": true,
913
"esModuleInterop": true,
1014
"module": "esnext",
1115
"moduleResolution": "bundler",
@@ -19,9 +23,21 @@
1923
}
2024
],
2125
"paths": {
22-
"@/*": ["./src/*"]
23-
}
26+
"@/*": [
27+
"./src/*"
28+
]
29+
},
30+
"strict": false,
31+
"noEmit": true
2432
},
25-
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
26-
"exclude": ["node_modules"]
33+
"include": [
34+
"next-env.d.ts",
35+
"**/*.ts",
36+
"**/*.tsx",
37+
".next/types/**/*.ts",
38+
"src/app/page.tsx"
39+
],
40+
"exclude": [
41+
"node_modules"
42+
]
2743
}

0 commit comments

Comments
 (0)