Skip to content

Commit

Permalink
Réorganisation des imports et amélioration de la lisibilité du code d…
Browse files Browse the repository at this point in the history
…ans App.tsx
  • Loading branch information
MovingLive committed Dec 15, 2024
1 parent abc91b3 commit 64d1081
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import React, { useState } from 'react';
import { FileJson } from 'lucide-react';
import { JsonInput } from './components/JsonInput';
import { JsonOutput } from './components/JsonOutput';
import { isValidJson, generateTemplate, formatJson } from './utils/jsonUtils';
import type { JsonTemplateState } from './types/json';
import { FileJson } from "lucide-react";
import { useState } from "react";
import { JsonInput } from "./components/JsonInput";
import { JsonOutput } from "./components/JsonOutput";
import type { JsonTemplateState } from "./types/json";
import { formatJson, generateTemplate } from "./utils/jsonUtils";

function App() {
const [state, setState] = useState<JsonTemplateState>({
sourceJson: '',
templateJson: '',
sourceJson: "",
templateJson: "",
error: null,
isProcessing: false,
});

const handleJsonChange = (value: string) => {
setState(prev => ({
setState((prev) => ({
...prev,
sourceJson: value,
error: null,
Expand All @@ -32,25 +32,25 @@ function App() {

const handleGenerate = () => {
try {
setState(prev => ({ ...prev, isProcessing: true, error: null }));
setState((prev) => ({ ...prev, isProcessing: true, error: null }));

if (!state.sourceJson.trim()) {
throw new Error('Please enter some JSON first');
throw new Error("Please enter some JSON first");
}

const parsedJson = JSON.parse(state.sourceJson);
const template = generateTemplate(parsedJson);
const formattedTemplate = formatJson(template);

setState(prev => ({
setState((prev) => ({
...prev,
templateJson: formattedTemplate,
isProcessing: false,
}));
} catch (err) {
setState(prev => ({
setState((prev) => ({
...prev,
error: err instanceof Error ? err.message : 'Invalid JSON format',
error: err instanceof Error ? err.message : "Invalid JSON format",
isProcessing: false,
}));
}
Expand Down Expand Up @@ -89,13 +89,11 @@ function App() {
</button>
</div>

{state.templateJson && (
<JsonOutput value={state.templateJson} />
)}
{state.templateJson && <JsonOutput value={state.templateJson} />}
</div>
</div>
</div>
);
}

export default App;
export default App;

0 comments on commit 64d1081

Please sign in to comment.