import { Dropdown, type DropdownItem, IconButton } from "@yaakapp-internal/ui"; import { useAtomValue, useSetAtom } from "jotai"; import { useState } from "react"; import { clearFlowsAtom, flowTotalAtom } from "../lib/store"; /** * Clears every flow, once confirmed in its menu, which its hotkey opens too. The list empties at * once; the flows are deleted in the background. */ export function ClearFlowsButton() { const total = useAtomValue(flowTotalAtom); const clear = useSetAtom(clearFlowsAtom); const [error, setError] = useState(null); const items: DropdownItem[] = [ { type: "content", label: (
{total === 1 ? "Clear 1 flow?" : `Clear all ${total.toLocaleString()} flows?`}
{error != null ? ( {error} ) : ( "They are deleted from disk with their bodies, for good." )}
), }, { type: "separator" }, { label: "Clear", icon: "trash", color: "danger", onSelect: () => { setError(null); clear().catch((err: unknown) => { const message = (err as { message?: unknown } | null)?.message; setError(typeof message === "string" ? message : String(err)); }); }, }, ]; return ( ); }