import { useRef } from 'react'; import { useCutsceneStore } from '../../store/cutsceneStore'; import { parseFile, triggerDownload } from '../../utils/fileIO'; import styles from './LeftPanel.module.css'; export default function LeftPanel() { const fileInputRef = useRef(null); const { file, selectedCutsceneId, loadFile, addCutscene, deleteCutscene, selectCutscene, getExportData } = useCutsceneStore(); function handleFileChange(e: React.ChangeEvent) { const f = e.target.files?.[0]; if (!f) return; const reader = new FileReader(); reader.onload = (ev) => { try { const json = JSON.parse(ev.target!.result as string); loadFile(parseFile(json)); } catch { alert('Invalid JSON file'); } }; reader.readAsText(f); e.target.value = ''; } function handleSave() { const data = getExportData(); if (data) triggerDownload(data); } function handleDelete(id: string) { if (confirm(`Delete cutscene "${id}"?`)) deleteCutscene(id); } return (
Cutscenes
{!file || file.cutscenes.length === 0 ? (
No cutscenes. Load a JSON or create new.
) : ( file.cutscenes.map(c => (
selectCutscene(c.id)} > {c.id}
)) )}
); }