pl-fe: another supposed modals fix
Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
This commit is contained in:
@ -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<IModalRoot> = ({ 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();
|
||||
|
||||
@ -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<keyof typeof MODAL_COMPONENTS, React.ExoticComponent<any>>)[type] : null;
|
||||
|
||||
@ -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<State>()(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<string, any> | 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;
|
||||
|
||||
Reference in New Issue
Block a user