import { useRouter } from "next/router"; import useCollectionStore from "@/store/collections"; import { Collection, Tag } from "@prisma/client"; import ClickAwayHandler from "./ClickAwayHandler"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faPlus, faFolder, faBox, faHashtag, faBookmark, faMagnifyingGlass, IconDefinition, } from "@fortawesome/free-solid-svg-icons"; import { useEffect, useState } from "react"; import AddLinkModal from "./AddLinkModal"; import useTagStore from "@/store/tags"; export default function () { const router = useRouter(); const [pageName, setPageName] = useState(""); const [pageIcon, setPageIcon] = useState(null); const { collections } = useCollectionStore(); const { tags } = useTagStore(); useEffect(() => { if (router.route === "/collections/[id]") { const collectionId = router.query.id; const activeCollection: Collection | undefined = collections.find( (e) => e.id.toString() == collectionId ); if (activeCollection) { setPageName(activeCollection?.name); } setPageIcon(faFolder); } else if (router.route === "/tags/[id]") { const tagId = router.query.id; const activeTag: Tag | undefined = tags.find( (e) => e.id.toString() == tagId ); if (activeTag) { setPageName(activeTag?.name); } setPageIcon(faHashtag); } else if (router.route === "/collections") { setPageName("All Collections"); setPageIcon(faBox); } else if (router.route === "/links") { setPageName("All Links"); setPageIcon(faBookmark); } }, [router, collections, tags]); const [linkModal, setLinkModal] = useState(false); const toggleLinkModal = () => { setLinkModal(!linkModal); }; return (
{pageIcon ? ( ) : null}

{pageName}

{linkModal ? (
) : null}
); }