({ collection, onSave, onClose, initialEditId })
| 20 | } |
| 21 | |
| 22 | const ModPanel: React.FC<ModPanelProps> = ({ collection, onSave, onClose, initialEditId }) => { |
| 23 | const [col, setCol] = useState<ModCollection>(() => ({ ...collection })); |
| 24 | const [editingId, setEditingId] = useState<string | null>(initialEditId ?? null); |
| 25 | |
| 26 | const mods = getModList(col); |
| 27 | const activeId = col.activeId; |
| 28 | const editingEntry = editingId ? col.items[editingId] : null; |
| 29 | |
| 30 | const handleSelect = (id: string) => { |
| 31 | setCol({ ...col, activeId: id }); |
| 32 | }; |
| 33 | |
| 34 | const handleDelete = (id: string) => { |
| 35 | if (mods.length <= 1) return; |
| 36 | const items = { ...col.items }; |
| 37 | delete items[id]; |
| 38 | const newActiveId = col.activeId === id ? Object.keys(items)[0] : col.activeId; |
| 39 | setCol({ activeId: newActiveId, items }); |
| 40 | if (editingId === id) setEditingId(null); |
| 41 | }; |
| 42 | |
| 43 | const handleAdd = () => { |
| 44 | const id = generateModId(); |
| 45 | const newMod: ModConfig = { |
| 46 | id, |
| 47 | mod_name: 'New Mod', |
| 48 | mod_name_en: 'New Mod', |
| 49 | mod_description: '', |
| 50 | stage_count: 1, |
| 51 | stages: { |
| 52 | 0: { |
| 53 | stage_index: 0, |
| 54 | stage_name: 'Stage 1', |
| 55 | stage_description: '', |
| 56 | stage_targets: { 1: 'First target' }, |
| 57 | }, |
| 58 | }, |
| 59 | }; |
| 60 | const newState: ModState = { |
| 61 | current_stage_index: 0, |
| 62 | total_stage_count: 1, |
| 63 | is_finished: false, |
| 64 | completed_targets: [], |
| 65 | }; |
| 66 | setCol({ ...col, items: { ...col.items, [id]: { config: newMod, state: newState } } }); |
| 67 | setEditingId(id); |
| 68 | }; |
| 69 | |
| 70 | const handleSave = () => { |
| 71 | onSave(col); |
| 72 | }; |
| 73 | |
| 74 | if (editingEntry) { |
| 75 | return ( |
| 76 | <ModEditor |
| 77 | entry={editingEntry} |
| 78 | onSave={(updatedEntry) => { |
| 79 | setCol({ ...col, items: { ...col.items, [updatedEntry.config.id]: updatedEntry } }); |
nothing calls this directly
no test coverage detected