import { useState } from "preact/hooks"; import { t } from "../../services/i18n"; import tree from "../../services/tree"; import Button from "../react/Button"; import FormRadioGroup from "../react/FormRadioGroup"; import Modal from "../react/Modal"; import "./export.css"; import ws from "../../services/ws"; import toastService, { ToastOptions } from "../../services/toast"; import utils from "../../services/utils"; import open from "../../services/open"; import froca from "../../services/froca"; import { useTriliumEvent } from "../react/hooks"; interface ExportDialogProps { branchId?: string | null; noteTitle?: string; defaultType?: "subtree" | "single"; } export default function ExportDialog() { const [ opts, setOpts ] = useState(); const [ exportType, setExportType ] = useState(opts?.defaultType ?? "subtree"); const [ subtreeFormat, setSubtreeFormat ] = useState("html"); const [ singleFormat, setSingleFormat ] = useState("html"); const [ opmlVersion, setOpmlVersion ] = useState("2.0"); const [ shown, setShown ] = useState(false); useTriliumEvent("showExportDialog", async ({ notePath, defaultType }) => { const { noteId, parentNoteId } = tree.getNoteIdAndParentIdFromUrl(notePath); if (!parentNoteId) { return; } const branchId = await froca.getBranchId(parentNoteId, noteId); setOpts({ noteTitle: noteId && await tree.getNoteTitle(noteId), defaultType, branchId }); setShown(true); }); return ( { if (!opts || !opts.branchId) { return; } const format = (exportType === "subtree" ? subtreeFormat : singleFormat); const version = (format === "opml" ? opmlVersion : "1.0"); exportBranch(opts.branchId, exportType, format, version); setShown(false); }} onHidden={() => setShown(false)} footer={