From 64a5374ed7ab49190f8a3b3d2bd5b80ad92b30e4 Mon Sep 17 00:00:00 2001 From: mkrause Date: Wed, 15 Jan 2025 23:16:50 +0100 Subject: [PATCH] Cleanup. --- .../overlays/ToastProvider/ToastProvider.tsx | 2 +- .../util/overlays/modal/ModalDialogProvider.tsx | 17 +++++------------ 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/components/overlays/ToastProvider/ToastProvider.tsx b/src/components/overlays/ToastProvider/ToastProvider.tsx index e7d84b0..d0ad45e 100644 --- a/src/components/overlays/ToastProvider/ToastProvider.tsx +++ b/src/components/overlays/ToastProvider/ToastProvider.tsx @@ -239,7 +239,7 @@ export const ToastProvider = ({ global = false, children }: ToastProviderProps) {children} {createPortal(, activeModalDialog ?? window.document.body)} - ) + ); }; export const useNotify = () => { diff --git a/src/components/util/overlays/modal/ModalDialogProvider.tsx b/src/components/util/overlays/modal/ModalDialogProvider.tsx index c9a29af..7ca2347 100644 --- a/src/components/util/overlays/modal/ModalDialogProvider.tsx +++ b/src/components/util/overlays/modal/ModalDialogProvider.tsx @@ -66,16 +66,6 @@ export const ModalDialogProvider = (props: React.PropsWithChildren) => { const modalDialogStackRef = React.useRef(null); const modalDialogStack = modalDialogStackRef.current ?? new ModalDialogStackObservable(); // Lazy initialize - // const context = React.useMemo(() => ({ - // activeModal: instances.at(-1)?.dialogRef.current ?? null, - // activate: (ref: ModalDialogReference) => { - // //setInstances(instances => [...instances.filter(inst => inst.id !== ref.id), ref]); - // }, - // deactivate: (ref: ModalDialogReference) => { - // //setInstances(instances => instances.filter(inst => inst.id !== ref.id)); - // }, - // }), [instances]); - const context = React.useMemo(() => ({ modalDialogStack }), [modalDialogStack]); return ( @@ -116,9 +106,12 @@ export const useActiveModalDialog = (): null | HTMLDialogElement => { React.useEffect(() => { if (context === null) { throw new Error(`Cannot read ModalDialogContext: missing provider.`); } return context.modalDialogStack.subscribe(function() { - setActiveModalDialog(this.activeModalDialog()); + const newActiveModalDialog = this.activeModalDialog(); + if (newActiveModalDialog !== activeModalDialog) { + setActiveModalDialog(newActiveModalDialog); + } }); - }, [context]); + }, [context, activeModalDialog]); return activeModalDialog?.dialogRef?.current ?? null; };