2023-06-12 23:46:32 -05:00
|
|
|
import useModalStore from "@/store/modals";
|
|
|
|
import Modal from "./Modal";
|
2023-06-20 09:39:03 -05:00
|
|
|
import LinkModal from "./Modal/Link";
|
2023-06-12 23:46:32 -05:00
|
|
|
import {
|
2023-06-16 07:55:21 -05:00
|
|
|
CollectionIncludingMembersAndLinkCount,
|
2023-06-14 17:34:54 -05:00
|
|
|
LinkIncludingShortenedCollectionAndTags,
|
2023-06-12 23:46:32 -05:00
|
|
|
} from "@/types/global";
|
|
|
|
import CollectionModal from "./Modal/Collection";
|
2023-06-20 09:39:03 -05:00
|
|
|
import { useEffect } from "react";
|
|
|
|
import { useRouter } from "next/router";
|
2023-06-12 23:46:32 -05:00
|
|
|
|
|
|
|
export default function ModalManagement() {
|
|
|
|
const { modal, setModal } = useModalStore();
|
|
|
|
|
|
|
|
const toggleModal = () => {
|
|
|
|
setModal(null);
|
|
|
|
};
|
|
|
|
|
2023-06-20 09:39:03 -05:00
|
|
|
const router = useRouter();
|
|
|
|
useEffect(() => {
|
|
|
|
toggleModal();
|
|
|
|
}, [router]);
|
|
|
|
|
2023-06-12 23:46:32 -05:00
|
|
|
if (modal && modal.modal === "LINK")
|
|
|
|
return (
|
|
|
|
<Modal toggleModal={toggleModal}>
|
|
|
|
<LinkModal
|
|
|
|
toggleLinkModal={toggleModal}
|
|
|
|
method={modal.method}
|
2023-06-14 17:34:54 -05:00
|
|
|
activeLink={modal.active as LinkIncludingShortenedCollectionAndTags}
|
2023-06-12 23:46:32 -05:00
|
|
|
/>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
else if (modal && modal.modal === "COLLECTION")
|
|
|
|
return (
|
|
|
|
<Modal toggleModal={toggleModal}>
|
|
|
|
<CollectionModal
|
|
|
|
toggleCollectionModal={toggleModal}
|
|
|
|
method={modal.method}
|
2023-06-26 17:33:40 -05:00
|
|
|
isOwner={modal.isOwner as boolean}
|
2023-06-12 23:46:32 -05:00
|
|
|
defaultIndex={modal.defaultIndex}
|
2023-06-16 07:55:21 -05:00
|
|
|
activeCollection={
|
|
|
|
modal.active as CollectionIncludingMembersAndLinkCount
|
|
|
|
}
|
2023-06-12 23:46:32 -05:00
|
|
|
/>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
else return <></>;
|
|
|
|
}
|