From 1dbcb5a027758b272e752eec1e2511cf6fdd2283 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 15 Aug 2025 12:33:23 +0300 Subject: [PATCH] fix(react/dialogs): unable to chain prompts --- apps/client/src/widgets/dialogs/prompt.tsx | 25 +++++++++++----------- 1 file changed, 13 insertions(+), 12 deletions(-) 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={