import { useEffect, useState } from "react"; import Button from "../components/ui/Button"; import { viewerChooseFile, viewerGetState } from "../lib/tauri-commands"; import type { ViewerState } from "../lib/types"; import EditorPane from "./EditorPane"; const errorText = (e: unknown) => (e instanceof Error ? e.message : String(e)); export default function ViewerApp() { const [state, setState] = useState(null); const [chooseError, setChooseError] = useState(null); useEffect(() => { viewerGetState().then(setState, (e) => setState({ error: errorText(e) })); }, []); if (state === null) return

Loading…

; if ("error" in state) return

{state.error}

; const choose = (index: number) => { setChooseError(null); viewerChooseFile(index).then(setState, (e) => setChooseError(errorText(e))); }; switch (state.state.kind) { case "resolved": return ; case "not_found": return (

Could not find {state.raw_path} in the container. Looked in:

    {state.state.tried.map((p) =>
  • {p}
  • )}
); case "choose": return (

Several files match {state.raw_path}. Open which?

    {state.state.candidates.map((p, i) => (
  • ))}
{chooseError &&

{chooseError}

}
); } }