import { useState } from "react"; import { chooseFolder } from "../tauri"; import { Icon } from "./Icon"; // A single "Give access to a folder" affordance. Collapsed it's one button; expanded it's a path // field (Browse on desktop, paste anywhere) + an "Allow writing" checkbox that's OFF by default — // so access is read-only unless explicitly granted. Used by the composer chip and the start panel. export function AddFolderForm({ onAdd, busy, compact, startOpen, onDismiss, }: { onAdd: (path: string, writable: boolean) => Promise | boolean | void; busy?: boolean; compact?: boolean; // Render the form expanded immediately (the caller owns the trigger); Cancel/success then // notify via onDismiss so the caller can collapse it. startOpen?: boolean; onDismiss?: () => void; }) { const [open, setOpen] = useState(!!startOpen); const [path, setPath] = useState(""); const [writable, setWritable] = useState(false); const reset = () => { setOpen(false); setPath(""); setWritable(false); onDismiss?.(); }; const browse = async () => { const p = await chooseFolder(); if (p) setPath(p); }; const submit = async () => { if (!path.trim()) return; const ok = await onAdd(path.trim(), writable); if (ok !== false) reset(); }; if (!open) { return ( ); } return (
setPath(e.target.value)} onKeyDown={(e) => { if (e.key === "Enter") submit(); else if (e.key === "Escape") reset(); }} />
); }