import Dropdown from "@/components/Dropdown"; import LinkCard from "@/components/LinkCard"; import useCollectionStore from "@/store/collections"; import useLinkStore from "@/store/links"; import { CollectionIncludingMembersAndLinkCount, Sort } from "@/types/global"; import { faEllipsis, faFolder, faSort, } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { useRouter } from "next/router"; import { useEffect, useState } from "react"; import MainLayout from "@/layouts/MainLayout"; import { useSession } from "next-auth/react"; import ProfilePhoto from "@/components/ProfilePhoto"; import SortDropdown from "@/components/SortDropdown"; import useModalStore from "@/store/modals"; import useLinks from "@/hooks/useLinks"; import usePermissions from "@/hooks/usePermissions"; import NoLinksFound from "@/components/NoLinksFound"; export default function Index() { const { setModal } = useModalStore(); const router = useRouter(); const { links } = useLinkStore(); const { collections } = useCollectionStore(); const { data } = useSession(); const [expandDropdown, setExpandDropdown] = useState(false); const [sortDropdown, setSortDropdown] = useState(false); const [sortBy, setSortBy] = useState(Sort.DateNewestFirst); const [activeCollection, setActiveCollection] = useState(); const permissions = usePermissions(activeCollection?.id as number); useLinks({ collectionId: Number(router.query.id), sort: sortBy }); useEffect(() => { setActiveCollection( collections.find((e) => e.id === Number(router.query.id)) ); }, [router, collections]); return (
{activeCollection && (

{activeCollection?.name}

)} {activeCollection ? (
setModal({ modal: "COLLECTION", state: true, method: "UPDATE", isOwner: permissions === true, active: activeCollection, defaultIndex: permissions === true ? 1 : 0, }) } className="flex justify-center sm:justify-end items-center w-fit mx-auto sm:mr-0 sm:ml-auto group cursor-pointer" >
{permissions === true ? "Manage" : "View"} Team
{activeCollection?.members .sort((a, b) => (a.userId as number) - (b.userId as number)) .map((e, i) => { return ( ); }) .slice(0, 4)} {activeCollection?.members.length && activeCollection.members.length - 4 > 0 ? (
+{activeCollection?.members?.length - 4}
) : null}
) : null}

{activeCollection?.description}

setSortDropdown(!sortDropdown)} id="sort-dropdown" className="inline-flex rounded-md cursor-pointer hover:bg-slate-200 duration-100 p-1" >
{sortDropdown ? ( setSortDropdown(!sortDropdown)} /> ) : null}
setExpandDropdown(!expandDropdown)} id="expand-dropdown" className="inline-flex rounded-md cursor-pointer hover:bg-slate-200 duration-100 p-1" >
{expandDropdown ? ( { setModal({ modal: "LINK", state: true, method: "CREATE", }); setExpandDropdown(false); }, } : undefined, permissions === true ? { name: "Edit Collection Info", onClick: () => { activeCollection && setModal({ modal: "COLLECTION", state: true, method: "UPDATE", isOwner: permissions === true, active: activeCollection, }); setExpandDropdown(false); }, } : undefined, { name: permissions === true ? "Share/Collaborate" : "View Team", onClick: () => { activeCollection && setModal({ modal: "COLLECTION", state: true, method: "UPDATE", isOwner: permissions === true, active: activeCollection, defaultIndex: permissions === true ? 1 : 0, }); setExpandDropdown(false); }, }, { name: permissions === true ? "Delete Collection" : "Leave Collection", onClick: () => { activeCollection && setModal({ modal: "COLLECTION", state: true, method: "UPDATE", isOwner: permissions === true, active: activeCollection, defaultIndex: permissions === true ? 2 : 1, }); setExpandDropdown(false); }, }, ]} onClickOutside={(e: Event) => { const target = e.target as HTMLInputElement; if (target.id !== "expand-dropdown") setExpandDropdown(false); }} className="absolute top-8 right-0 z-10 w-40" /> ) : null}
{links[0] ? (
{links .filter((e) => e.collectionId === Number(router.query.id)) .map((e, i) => { return ; })}
) : ( )}
); }