import { useCallback, useRef } from "react"; import { FiFilm } from "react-icons/fi"; import { useDemo } from "./DemoProvider"; import { parseDemoFile } from "../demo/parse"; export function LoadDemoButton() { const { setRecording, recording } = useDemo(); const inputRef = useRef(null); const handleClick = useCallback(() => { if (recording) { // Unload the current recording. setRecording(null); return; } inputRef.current?.click(); }, [recording, setRecording]); const handleFileChange = useCallback( async (e: React.ChangeEvent) => { const file = e.target.files?.[0]; if (!file) return; // Reset the input so the same file can be re-selected. e.target.value = ""; try { const buffer = await file.arrayBuffer(); const demo = parseDemoFile(buffer); setRecording(demo); } catch (err) { console.error("Failed to load demo:", err); } }, [setRecording], ); return ( <> ); }