import { useRef, useState } from "preact/hooks"; import appContext from "../../components/app_context.js"; import { closeActiveDialog } from "../../services/dialog.js"; import { t } from "../../services/i18n.js"; import server from "../../services/server.js"; import toast from "../../services/toast.js"; import Modal from "../react/Modal.jsx"; import ReactBasicWidget from "../react/ReactBasicWidget.js"; import froca from "../../services/froca.js"; import tree from "../../services/tree.js"; import Button from "../react/Button.jsx"; import FormGroup from "../react/FormGroup.js"; import useTriliumEvent from "../react/hooks.jsx"; import FBranch from "../../entities/fbranch.js"; function BranchPrefixDialogComponent() { const [ shown, setShown ] = useState(false); const [ branch, setBranch ] = useState(); const [ prefix, setPrefix ] = useState(branch?.prefix ?? ""); const branchInput = useRef(null); useTriliumEvent("editBranchPrefix", async () => { const notePath = appContext.tabManager.getActiveContextNotePath(); if (!notePath) { return; } const { noteId, parentNoteId } = tree.getNoteIdAndParentIdFromUrl(notePath); if (!noteId || !parentNoteId) { return; } const newBranchId = await froca.getBranchId(parentNoteId, noteId); if (!newBranchId) { return; } const parentNote = await froca.getNote(parentNoteId); if (!parentNote || parentNote.type === "search") { return; } setBranch(froca.getBranch(newBranchId)); setShown(true); }); async function onSubmit() { if (!branch) { return; } savePrefix(branch.branchId, prefix); closeActiveDialog(); } return ( branchInput.current?.focus()} onHidden={() => setShown(false)} onSubmit={onSubmit} helpPageId="TBwsyfadTA18" footer={