import useCollectionStore from "@/store/collections"; import useLinkStore from "@/store/links"; import { CollectionIncludingMembersAndLinkCount, Sort, ViewMode, } from "@/types/global"; import { useRouter } from "next/router"; import React, { useEffect, useState } from "react"; import MainLayout from "@/layouts/MainLayout"; import ProfilePhoto from "@/components/ProfilePhoto"; import SortDropdown from "@/components/SortDropdown"; 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"; import EditCollectionModal from "@/components/ModalContent/EditCollectionModal"; import EditCollectionSharingModal from "@/components/ModalContent/EditCollectionSharingModal"; import DeleteCollectionModal from "@/components/ModalContent/DeleteCollectionModal"; import ViewDropdown from "@/components/ViewDropdown"; import CardView from "@/components/LinkViews/Layouts/CardView"; // import GridView from "@/components/LinkViews/Layouts/GridView"; import ListView from "@/components/LinkViews/Layouts/ListView"; export default function Index() { 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: "", archiveAsScreenshot: undefined as unknown as boolean, archiveAsPDF: undefined as unknown as boolean, }); 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, archiveAsScreenshot: account.archiveAsScreenshot as boolean, archiveAsPDF: account.archiveAsPDF as boolean, }); } }; fetchOwner(); }, [activeCollection]); const [editCollectionModal, setEditCollectionModal] = useState(false); const [editCollectionSharingModal, setEditCollectionSharingModal] = useState(false); const [deleteCollectionModal, setDeleteCollectionModal] = useState(false); const [viewMode, setViewMode] = useState( localStorage.getItem("viewMode") || ViewMode.Card ); const linkView = { [ViewMode.Card]: CardView, // [ViewMode.Grid]: GridView, [ViewMode.List]: ListView, }; // @ts-ignore const LinkComponent = linkView[viewMode]; return (
{activeCollection && (

{activeCollection?.name}

    {permissions === true ? (
  • { (document?.activeElement as HTMLElement)?.blur(); setEditCollectionModal(true); }} > Edit Collection Info
  • ) : undefined}
  • { (document?.activeElement as HTMLElement)?.blur(); setEditCollectionSharingModal(true); }} > {permissions === true ? "Share and Collaborate" : "View Team"}
  • { (document?.activeElement as HTMLElement)?.blur(); setDeleteCollectionModal(true); }} > {permissions === true ? "Delete Collection" : "Leave Collection"}
)} {activeCollection ? (
setEditCollectionSharingModal(true)} > {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}

By {collectionOwner.name} {activeCollection.members.length > 0 ? ` and ${activeCollection.members.length} others` : undefined} .

) : undefined} {activeCollection?.description ? (

{activeCollection?.description}

) : undefined}

Showing {activeCollection?._count?.links} results

{links.some((e) => e.collectionId === Number(router.query.id)) ? ( e.collection.id === activeCollection?.id )} /> ) : ( )}
{activeCollection ? ( <> {editCollectionModal ? ( setEditCollectionModal(false)} activeCollection={activeCollection} /> ) : undefined} {editCollectionSharingModal ? ( setEditCollectionSharingModal(false)} activeCollection={activeCollection} /> ) : undefined} {deleteCollectionModal ? ( setDeleteCollectionModal(false)} activeCollection={activeCollection} /> ) : undefined} ) : undefined}
); }