From 160aea61283a9c06665c9f7be2ae18de05a3a499 Mon Sep 17 00:00:00 2001 From: Matthieu Date: Mon, 11 Aug 2025 22:30:36 +0200 Subject: [PATCH] refacto react component --- src/App.tsx | 7 +++---- src/components/ConfigVariablesEditor.tsx | 5 ++--- src/components/DialogueEditor.tsx | 19 +++++++++++-------- src/components/ImportExport.tsx | 12 ++++++------ src/components/JSONPreview.tsx | 10 +++++----- src/components/NPCBasicSettings.tsx | 5 ++--- src/components/NPCBattleConfiguration.tsx | 5 ++--- src/components/NPCInteractionEditor.tsx | 5 ++--- src/components/NPCPartyBuilder.tsx | 6 +++--- src/components/ValidationPanel.tsx | 11 ++++++----- 10 files changed, 42 insertions(+), 43 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index cd31c9e..f5691c3 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import { useState, useEffect } from 'react'; import { Settings, MessageSquare, Sword, Users, Code, FileText, Upload } from 'lucide-react'; import type { NPCConfiguration, DialogueConfiguration } from './types/npc'; import { NPCBasicSettings } from './components/NPCBasicSettings'; @@ -26,8 +26,7 @@ function App() { const [dialogueConfig, setDialogueConfig] = useState(null); - // Handle dialogue creation when interaction type changes to dialogue - React.useEffect(() => { + useEffect(() => { if (npcConfig.interaction.type === 'dialogue' && !dialogueConfig) { const newDialogue: DialogueConfiguration = { speakers: { @@ -49,7 +48,7 @@ function App() { }; setDialogueConfig(newDialogue); } - }, [npcConfig.interaction.type, dialogueConfig]); + }, [npcConfig.interaction.type]); const tabs = [ { id: 'basic', name: 'Basic Settings', icon: Settings }, diff --git a/src/components/ConfigVariablesEditor.tsx b/src/components/ConfigVariablesEditor.tsx index ffbfe4d..36057cf 100644 --- a/src/components/ConfigVariablesEditor.tsx +++ b/src/components/ConfigVariablesEditor.tsx @@ -1,4 +1,3 @@ -import React from 'react'; import { Plus, Trash2 } from 'lucide-react'; import type { NPCConfiguration, MoLangConfigVariable } from '../types/npc'; @@ -7,7 +6,7 @@ interface ConfigVariablesEditorProps { onChange: (config: NPCConfiguration) => void; } -export const ConfigVariablesEditor: React.FC = ({ config, onChange }) => { +export function ConfigVariablesEditor({ config, onChange }: ConfigVariablesEditorProps) { const addVariable = () => { const newVariable: MoLangConfigVariable = { variableName: '', @@ -166,4 +165,4 @@ export const ConfigVariablesEditor: React.FC = ({ co )} ); -}; \ No newline at end of file +} \ No newline at end of file diff --git a/src/components/DialogueEditor.tsx b/src/components/DialogueEditor.tsx index 94e9df5..b9ecf4f 100644 --- a/src/components/DialogueEditor.tsx +++ b/src/components/DialogueEditor.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import { useState } from 'react'; import { Plus, Trash2, MessageCircle } from 'lucide-react'; import type { DialogueConfiguration, DialoguePage, DialogueSpeaker } from '../types/npc'; @@ -7,7 +7,7 @@ interface DialogueEditorProps { onChange: (dialogue: DialogueConfiguration) => void; } -export const DialogueEditor: React.FC = ({ dialogue, onChange }) => { +export function DialogueEditor({ dialogue, onChange }: DialogueEditorProps) { const [selectedPageId, setSelectedPageId] = useState(null); const [speakerEditMode, setSpeakerEditMode] = useState(false); @@ -268,9 +268,12 @@ export const DialogueEditor: React.FC = ({ dialogue, onChan
{page.id}
Speaker: {page.speaker}
- {Array.isArray(page.lines) - ? (typeof page.lines[0] === 'string' ? page.lines[0] : page.lines[0]?.text || 'Expression') - : (typeof page.lines === 'string' ? page.lines : page.lines?.text || 'Expression')} + {page.lines.length > 0 + ? (typeof page.lines[0] === 'string' + ? page.lines[0] + : (page.lines[0] as { text?: string }).text || 'Expression' + ) + : 'No lines'}