From e217dde4c5f33a527d45b6c3ac1ff78698f59cce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?nicole=20miko=C5=82ajczyk?= Date: Wed, 7 Jan 2026 17:05:13 +0100 Subject: [PATCH] pl-fe: another supposed modals fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: nicole mikołajczyk --- packages/pl-fe/src/components/modal-root.tsx | 6 ++--- .../src/features/ui/components/modal-root.tsx | 5 ++-- packages/pl-fe/src/stores/modals.ts | 23 +++++++++++-------- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/packages/pl-fe/src/components/modal-root.tsx b/packages/pl-fe/src/components/modal-root.tsx index 23aefbb22..4798455f4 100644 --- a/packages/pl-fe/src/components/modal-root.tsx +++ b/packages/pl-fe/src/components/modal-root.tsx @@ -29,7 +29,7 @@ const checkComposeContent = (compose?: Compose) => interface IModalRoot { onCancel?: () => void; - onClose: (type?: ModalType) => void; + onClose: (type?: ModalType, all?: boolean) => void; type: ModalType; children: React.ReactNode; modalIndex: number; @@ -124,8 +124,8 @@ const ModalRoot: React.FC = ({ children, onCancel, onClose, type, mo const handleModalOpen = () => { unlistenHistory.current = router.history.subscribe(({ action, location }) => { - if (action.type === 'PUSH' && location.state.modalIndex === undefined) { - onClose(); + if ((action.type === 'REPLACE' || action.type === 'PUSH') && location.state.modalIndex === undefined) { + onClose(undefined, true); } if (action.type === 'BACK') { handleOnClose(); diff --git a/packages/pl-fe/src/features/ui/components/modal-root.tsx b/packages/pl-fe/src/features/ui/components/modal-root.tsx index e24076497..bc92d1502 100644 --- a/packages/pl-fe/src/features/ui/components/modal-root.tsx +++ b/packages/pl-fe/src/features/ui/components/modal-root.tsx @@ -66,7 +66,8 @@ const ModalRoot: React.FC = () => { const { modalType: type, modalProps: props } = modals.at(-1) || { modalProps: {}, modalType: null }; const index = modals.length - 1; - const onClickClose = (type?: ModalType) => { + const onClickClose = (type?: ModalType, all?: boolean) => { + console.log('Closing modal:', type, all); switch (type) { case 'COMPOSE': dispatch(cancelReplyCompose()); @@ -75,7 +76,7 @@ const ModalRoot: React.FC = () => { break; } - closeModal(type); + closeModal(type, all); }; const Component = type !== null ? (MODAL_COMPONENTS as Record>)[type] : null; diff --git a/packages/pl-fe/src/stores/modals.ts b/packages/pl-fe/src/stores/modals.ts index fd5d51b16..822552841 100644 --- a/packages/pl-fe/src/stores/modals.ts +++ b/packages/pl-fe/src/stores/modals.ts @@ -89,7 +89,7 @@ type State = { /** Open a modal of the given type */ openModal: (...[modalType, modalProps]: OpenModalProps) => void; /** Close the modal */ - closeModal: (modalType?: ModalType) => void; + closeModal: (modalType?: ModalType, all?: boolean) => void; }; }; @@ -99,18 +99,23 @@ const useModalsStore = create()(mutative((set) => ({ openModal: (...[modalType, modalProps]) => set((state: State) => { state.modals.push({ modalType, modalProps }); }), - closeModal: (modalType) => set((state: State) => { + closeModal: (modalType, all) => set((state: State) => { if (state.modals.length === 0) { return; } let closedModal: Record | undefined; - if (modalType === undefined) { - closedModal = state.modals[state.modals.length - 1].modalProps; - state.modals = state.modals.slice(0, -1); - } else if (state.modals.some((modal) => modalType === modal.modalType)) { - const lastIndex = state.modals.findLastIndex((modal) => modalType === modal.modalType); - closedModal = state.modals[lastIndex].modalProps; - state.modals = state.modals.slice(0, lastIndex); + if (all) { + closedModal = state.modals[0].modalProps; + state.modals = []; + } else { + if (modalType === undefined) { + closedModal = state.modals[state.modals.length - 1].modalProps; + state.modals = state.modals.slice(0, -1); + } else if (state.modals.some((modal) => modalType === modal.modalType)) { + const lastIndex = state.modals.findLastIndex((modal) => modalType === modal.modalType); + closedModal = state.modals[lastIndex].modalProps; + state.modals = state.modals.slice(0, lastIndex); + } } if (closedModal?.element) { const element = closedModal.element;