import LinkCard from "@/components/LinkCard"; import useCollectionStore from "@/store/collections"; import useLinkStore from "@/store/links"; import { CollectionIncludingMembersAndLinkCount, Sort } from "@/types/global"; import { faEllipsis, faFolder } 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 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"; import useLocalSettingsStore from "@/store/localSettings"; import useAccountStore from "@/store/account"; import getPublicUserData from "@/lib/client/getPublicUserData"; export default function Index() { const { setModal } = useModalStore(); const { settings } = useLocalSettingsStore(); const router = useRouter(); const { links } = useLinkStore(); const { collections } = useCollectionStore(); 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]); const { account } = useAccountStore(); const [collectionOwner, setCollectionOwner] = useState({ id: null as unknown as number, name: "", username: "", image: "", }); useEffect(() => { const fetchOwner = async () => { if (activeCollection && activeCollection.ownerId !== account.id) { const owner = await getPublicUserData( activeCollection.ownerId as number ); setCollectionOwner(owner); } else if (activeCollection && activeCollection.ownerId === account.id) { setCollectionOwner({ id: account.id as number, name: account.name, username: account.username as string, image: account.image as string, }); } }; fetchOwner(); }, [activeCollection]); return (
{activeCollection && (

{activeCollection?.name}

)} {activeCollection ? (
activeCollection && setModal({ modal: "COLLECTION", state: true, method: "UPDATE", isOwner: permissions === true, active: activeCollection, defaultIndex: permissions === true ? 1 : 0, }) } > {collectionOwner.id ? ( ) : undefined} {activeCollection.members .sort((a, b) => (a.userId as number) - (b.userId as number)) .map((e, i) => { return ( ); }) .slice(0, 3)} {activeCollection.members.length - 3 > 0 ? (
+{activeCollection.members.length - 3}
) : null}
) : undefined}

{activeCollection?.description}

    {permissions === true ? (
  • { (document?.activeElement as HTMLElement)?.blur(); activeCollection && setModal({ modal: "COLLECTION", state: true, method: "UPDATE", isOwner: permissions === true, active: activeCollection, }); }} > Edit Collection Info
  • ) : undefined}
  • { (document?.activeElement as HTMLElement)?.blur(); activeCollection && setModal({ modal: "COLLECTION", state: true, method: "UPDATE", isOwner: permissions === true, active: activeCollection, defaultIndex: permissions === true ? 1 : 0, }); }} > {permissions === true ? "Share and Collaborate" : "View Team"}
  • { (document?.activeElement as HTMLElement)?.blur(); activeCollection && setModal({ modal: "COLLECTION", state: true, method: "UPDATE", isOwner: permissions === true, active: activeCollection, defaultIndex: permissions === true ? 2 : 1, }); }} > {permissions === true ? "Delete Collection" : "Leave Collection"}
{links.some((e) => e.collectionId === Number(router.query.id)) ? (
{links .filter((e) => e.collection.id === activeCollection?.id) .map((e, i) => { return ; })}
) : ( )}
); }