import { AccountSettings, 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 usePermissions from "@/hooks/usePermissions"; import NoLinksFound from "@/components/NoLinksFound"; import useLocalSettingsStore from "@/store/localSettings"; 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 { dropdownTriggerer } from "@/lib/client/utils"; import NewCollectionModal from "@/components/ModalContent/NewCollectionModal"; import getServerSideProps from "@/lib/client/getServerSideProps"; import { useTranslation } from "next-i18next"; import LinkListOptions from "@/components/LinkListOptions"; import { useCollections } from "@/hooks/store/collections"; import { useUser } from "@/hooks/store/user"; import { useLinks } from "@/hooks/store/links"; import Links from "@/components/LinkViews/Links"; import Icon from "@/components/Icon"; import { IconWeight } from "@phosphor-icons/react"; export default function Index() { const { t } = useTranslation(); const { settings } = useLocalSettingsStore(); const router = useRouter(); const { data: collections = [] } = useCollections(); const [sortBy, setSortBy] = useState( Number(localStorage.getItem("sortBy")) ?? Sort.DateNewestFirst ); const { links, data } = useLinks({ sort: sortBy, collectionId: Number(router.query.id), }); const [activeCollection, setActiveCollection] = useState(); const permissions = usePermissions(activeCollection?.id as number); useEffect(() => { setActiveCollection( collections.find((e) => e.id === Number(router.query.id)) ); }, [router, collections]); const { data: user = {} } = useUser(); const [collectionOwner, setCollectionOwner] = useState< Partial >({}); useEffect(() => { const fetchOwner = async () => { if (activeCollection && activeCollection.ownerId !== user.id) { const owner = await getPublicUserData( activeCollection.ownerId as number ); setCollectionOwner(owner); } else if (activeCollection && activeCollection.ownerId === user.id) { setCollectionOwner({ id: user.id as number, name: user.name, username: user.username as string, image: user.image as string, archiveAsScreenshot: user.archiveAsScreenshot as boolean, archiveAsMonolith: user.archiveAsScreenshot as boolean, archiveAsPDF: user.archiveAsPDF as boolean, }); } }; fetchOwner(); }, [activeCollection]); const [editCollectionModal, setEditCollectionModal] = useState(false); const [newCollectionModal, setNewCollectionModal] = useState(false); const [editCollectionSharingModal, setEditCollectionSharingModal] = useState(false); const [deleteCollectionModal, setDeleteCollectionModal] = useState(false); const [editMode, setEditMode] = useState(false); useEffect(() => { if (editMode) return setEditMode(false); }, [router]); const [viewMode, setViewMode] = useState( (localStorage.getItem("viewMode") as ViewMode) || ViewMode.Card ); return (
{activeCollection && (
{activeCollection.icon ? ( ) : ( )}

{activeCollection?.name}

    {permissions === true && (
  • { (document?.activeElement as HTMLElement)?.blur(); setEditCollectionModal(true); }} className="whitespace-nowrap" > {t("edit_collection_info")}
  • )}
  • { (document?.activeElement as HTMLElement)?.blur(); setEditCollectionSharingModal(true); }} className="whitespace-nowrap" > {permissions === true ? t("share_and_collaborate") : t("view_team")}
  • {permissions === true && (
  • { (document?.activeElement as HTMLElement)?.blur(); setNewCollectionModal(true); }} className="whitespace-nowrap" > {t("create_subcollection")}
  • )}
  • { (document?.activeElement as HTMLElement)?.blur(); setDeleteCollectionModal(true); }} className="whitespace-nowrap" > {permissions === true ? t("delete_collection") : t("leave_collection")}
)} {activeCollection && (
setEditCollectionSharingModal(true)} > {collectionOwner.id && ( )} {activeCollection.members .sort((a, b) => a.userId - b.userId) .map((e, i) => { return ( ); }) .slice(0, 3)} {activeCollection.members.length - 3 > 0 && (
+{activeCollection.members.length - 3}
)}

{activeCollection.members.length > 0 && activeCollection.members.length === 1 ? t("by_author_and_other", { author: collectionOwner.name, count: activeCollection.members.length, }) : activeCollection.members.length > 0 && activeCollection.members.length !== 1 ? t("by_author_and_others", { author: collectionOwner.name, count: activeCollection.members.length, }) : t("by_author", { author: collectionOwner.name, })}

)} {activeCollection?.description && (

{activeCollection?.description}

)} {/* {collections.some((e) => e.parentId === activeCollection.id) ? (
Sub-Collections
{collections .filter((e) => e.parentId === activeCollection?.id) .map((e, i) => { return (

{e.name}

); })}
) : undefined} */}

{activeCollection?._count?.links === 1 ? t("showing_count_result", { count: activeCollection?._count?.links, }) : t("showing_count_results", { count: activeCollection?._count?.links, })}

{!data.isLoading && links && !links[0] && }
{activeCollection && ( <> {editCollectionModal && ( setEditCollectionModal(false)} activeCollection={activeCollection} /> )} {editCollectionSharingModal && ( setEditCollectionSharingModal(false)} activeCollection={activeCollection} /> )} {newCollectionModal && ( setNewCollectionModal(false)} parent={activeCollection} /> )} {deleteCollectionModal && ( setDeleteCollectionModal(false)} activeCollection={activeCollection} /> )} )}
); } export { getServerSideProps };