diff --git a/apps/client/src/widgets/dialogs/prompt.tsx b/apps/client/src/widgets/dialogs/prompt.tsx index 60ec94b88..0edb89774 100644 --- a/apps/client/src/widgets/dialogs/prompt.tsx +++ b/apps/client/src/widgets/dialogs/prompt.tsx @@ -32,25 +32,26 @@ function PromptDialogComponent() { const formRef = useRef(null); const labelRef = useRef(null); const answerRef = useRef(null); - const [ opts, setOpts ] = useState(); + const opts = useRef(); const [ value, setValue ] = useState(""); const [ shown, setShown ] = useState(false); + const submitValue = useRef(null); - useTriliumEvent("showPromptDialog", (opts) => { - setOpts(opts); + useTriliumEvent("showPromptDialog", (newOpts) => { + opts.current = newOpts; + setValue(newOpts.defaultValue ?? ""); setShown(true); - setValue(opts.defaultValue ?? ""); }) return ( { - opts?.shown?.({ + opts.current?.shown?.({ $dialog: refToJQuerySelector(modalRef), $question: refToJQuerySelector(labelRef), $answer: refToJQuerySelector(answerRef), @@ -59,20 +60,20 @@ function PromptDialogComponent() { answerRef.current?.focus(); }} onSubmit={() => { - const modal = BootstrapModal.getOrCreateInstance(modalRef.current!); - modal.hide(); - - opts?.callback?.(value); + submitValue.current = value; + setShown(false); }} onHidden={() => { - opts?.callback?.(null); setShown(false); + opts.current?.callback?.(submitValue.current); + submitValue.current = null; + opts.current = undefined; }} footer={