Skip to content

Commit

Permalink
Cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrause committed Jan 15, 2025
1 parent c6702c2 commit 64a5374
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/components/overlays/ToastProvider/ToastProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ export const ToastProvider = ({ global = false, children }: ToastProviderProps)
{children}
{createPortal(<Toaster/>, activeModalDialog ?? window.document.body)}
</ToastContext>
)
);
};

export const useNotify = () => {
Expand Down
17 changes: 5 additions & 12 deletions src/components/util/overlays/modal/ModalDialogProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,6 @@ export const ModalDialogProvider = (props: React.PropsWithChildren) => {
const modalDialogStackRef = React.useRef<null | ModalDialogStackObservable>(null);
const modalDialogStack = modalDialogStackRef.current ?? new ModalDialogStackObservable(); // Lazy initialize

// const context = React.useMemo<ModalDialogContext>(() => ({
// 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<ModalDialogContext>(() => ({ modalDialogStack }), [modalDialogStack]);

return (
Expand Down Expand Up @@ -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;
};
Expand Down

0 comments on commit 64a5374

Please sign in to comment.