import { useRef, useState } from "preact/hooks"; import { t } from "../../services/i18n"; import FormGroup from "../react/FormGroup"; import FormRadioGroup from "../react/FormRadioGroup"; import Modal from "../react/Modal"; import NoteAutocomplete from "../react/NoteAutocomplete"; import Button from "../react/Button"; import { Suggestion, triggerRecentNotes } from "../../services/note_autocomplete"; import tree from "../../services/tree"; import froca from "../../services/froca"; import { useTriliumEvent } from "../react/hooks"; import { type BoxSize, CKEditorApi } from "../type_widgets/text/CKEditorWithWatchdog"; export interface IncludeNoteOpts { editorApi: CKEditorApi; } export default function IncludeNoteDialog() { const editorApiRef = useRef(null); const [suggestion, setSuggestion] = useState(null); const [boxSize, setBoxSize] = useState("medium"); const [shown, setShown] = useState(false); useTriliumEvent("showIncludeNoteDialog", ({ editorApi }) => { editorApiRef.current = editorApi; setShown(true); }); const autoCompleteRef = useRef(null); return ( triggerRecentNotes(autoCompleteRef.current)} onHidden={() => setShown(false)} onSubmit={() => { if (!suggestion?.notePath || !editorApiRef.current) return; setShown(false); includeNote(suggestion.notePath, editorApiRef.current, boxSize as BoxSize); }} footer={