Skip to content

Commit 88b6b64

Browse files
committed
Update code tool navigation
1 parent 80c81d8 commit 88b6b64

2 files changed

Lines changed: 35 additions & 6 deletions

File tree

src/App.jsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ const MENU_GROUPS = [
5151
label: 'Formatting',
5252
items: [
5353
{ id: 'jsonbeautifier', label: 'JSON Beautifier', icon: Braces },
54-
{ id: 'codetools', label: 'Code Tools', icon: Code },
54+
{ id: 'codetools-js', label: 'JS Beautifier/Minifier', icon: Code },
55+
{ id: 'codetools-css', label: 'CSS Beautifier/Minifier', icon: Code },
56+
{ id: 'codetools-html', label: 'HTML Beautifier/Minifier', icon: Code },
57+
{ id: 'codetools-yaml', label: 'YAML Beautifier/Minifier', icon: Code },
5558
]
5659
},
5760
{
@@ -82,6 +85,13 @@ const NAV_ITEMS = MENU_GROUPS.flatMap(group => group.items);
8285
/**
8386
* Feature component mapping
8487
*/
88+
const CODE_TOOL_ROUTES = {
89+
javascript: '/codetools-js',
90+
css: '/codetools-css',
91+
html: '/codetools-html',
92+
yaml: '/codetools-yaml',
93+
};
94+
8595
const FEATURE_COMPONENTS = {
8696
debezium: DebeziumDiff,
8797
jwt: JwtDebugger,
@@ -95,7 +105,10 @@ const FEATURE_COMPONENTS = {
95105
smtp: SmtpChecker,
96106
json2env: JsonToEnv,
97107
jsonbeautifier: JsonBeautifier,
98-
codetools: CodeTools,
108+
'codetools-js': () => <CodeTools initialLanguage="javascript" languageRoutes={CODE_TOOL_ROUTES} />,
109+
'codetools-css': () => <CodeTools initialLanguage="css" languageRoutes={CODE_TOOL_ROUTES} />,
110+
'codetools-html': () => <CodeTools initialLanguage="html" languageRoutes={CODE_TOOL_ROUTES} />,
111+
'codetools-yaml': () => <CodeTools initialLanguage="yaml" languageRoutes={CODE_TOOL_ROUTES} />,
99112
};
100113

101114
/**
@@ -140,4 +153,4 @@ const App = () => {
140153
);
141154
};
142155

143-
export default App;
156+
export default App;

src/features/CodeTools.jsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import React, { useState, useEffect } from 'react';
22
import { Copy, Check, Trash2, Wand2, Minimize2 } from 'lucide-react';
33
import beautify from 'js-beautify';
44
import yaml from 'js-yaml';
5+
import { useNavigate } from 'react-router-dom';
56

6-
const CodeTools = () => {
7+
const CodeTools = ({ initialLanguage = 'javascript', languageRoutes = null }) => {
8+
const navigate = useNavigate();
79
const [input, setInput] = useState('');
810
const [output, setOutput] = useState('');
9-
const [language, setLanguage] = useState('javascript');
11+
const [language, setLanguage] = useState(initialLanguage);
1012
const [mode, setMode] = useState('beautify'); // 'beautify' or 'minify'
1113
const [spaces, setSpaces] = useState(2);
1214
const [copied, setCopied] = useState(false);
@@ -19,6 +21,11 @@ const CodeTools = () => {
1921
{ id: 'yaml', label: 'YAML' },
2022
];
2123

24+
useEffect(() => {
25+
setLanguage(initialLanguage);
26+
setError(null);
27+
}, [initialLanguage]);
28+
2229
useEffect(() => {
2330
if (!input.trim()) {
2431
setOutput('');
@@ -107,6 +114,15 @@ const CodeTools = () => {
107114
setError(null);
108115
};
109116

117+
const handleLanguageChange = (nextLanguage) => {
118+
if (languageRoutes?.[nextLanguage]) {
119+
navigate(languageRoutes[nextLanguage]);
120+
return;
121+
}
122+
123+
setLanguage(nextLanguage);
124+
};
125+
110126
return (
111127
<div className="flex flex-col gap-4 h-full">
112128
<div className="flex flex-wrap items-center justify-between gap-4 bg-slate-900/50 p-4 rounded-xl border border-slate-800">
@@ -116,7 +132,7 @@ const CodeTools = () => {
116132
<span className="text-sm font-medium text-slate-400">Language:</span>
117133
<select
118134
value={language}
119-
onChange={(e) => setLanguage(e.target.value)}
135+
onChange={(e) => handleLanguageChange(e.target.value)}
120136
className="bg-slate-800 text-slate-200 text-sm font-bold rounded-lg px-3 py-1.5 border border-slate-700 focus:border-blue-500 outline-none cursor-pointer"
121137
>
122138
{LANGUAGES.map((l) => (

0 commit comments

Comments
 (0)