Skip to content

Build your personal knowledge base with Trilium Notes

fix(react/dialogs): unable to chain prompts

Elian Doran1dbcb5a02775
diff --git a/apps/client/src/widgets/dialogs/prompt.tsx b/apps/client/src/widgets/dialogs/prompt.tsx
index 60ec94b889..0edb897741 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<HTMLFormElement>(null);
const labelRef = useRef<HTMLLabelElement>(null);
const answerRef = useRef<HTMLInputElement>(null);
- const [ opts, setOpts ] = useState<PromptDialogOptions>();
+ const opts = useRef<PromptDialogOptions>();
const [ value, setValue ] = useState("");
const [ shown, setShown ] = useState(false);
+ const submitValue = useRef<string>(null);
- useTriliumEvent("showPromptDialog", (opts) => {
- setOpts(opts);
+ useTriliumEvent("showPromptDialog", (newOpts) => {
+ opts.current = newOpts;
+ setValue(newOpts.defaultValue ?? "");
setShown(true);
- setValue(opts.defaultValue ?? "");
})
return (
<Modal
className="prompt-dialog"
- title={opts?.title ?? t("prompt.title")}
+ title={opts.current?.title ?? t("prompt.title")}
size="lg"
zIndex={2000}
modalRef={modalRef} formRef={formRef}
onShown={() => {
- 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={<Button text={t("prompt.ok")} keyboardShortcut="Enter" primary />}
show={shown}
stackable
>
- <FormGroup label={opts?.message} labelRef={labelRef}>
+ <FormGroup label={opts.current?.message} labelRef={labelRef}>
<FormTextBox
name="prompt-dialog-answer"
inputRef={answerRef}