import useCollectionStore from "@/store/collections"; import useLinkStore from "@/store/links"; 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 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 CardView from "@/components/LinkViews/Layouts/CardView"; import ListView from "@/components/LinkViews/Layouts/ListView"; import { dropdownTriggerer } from "@/lib/client/utils"; import NewCollectionModal from "@/components/ModalContent/NewCollectionModal"; import MasonryView from "@/components/LinkViews/Layouts/MasonryView"; import getServerSideProps from "@/lib/client/getServerSideProps"; import { useTranslation } from "next-i18next"; import LinkListOptions from "@/components/LinkListOptions"; export default function Index() { const { t } = useTranslation(); 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>({}); 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, archiveAsMonolith: account.archiveAsScreenshot as boolean, archiveAsPDF: account.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") || ViewMode.Card ); const linkView = { [ViewMode.Card]: CardView, [ViewMode.List]: ListView, [ViewMode.Masonry]: MasonryView, }; // @ts-ignore const LinkComponent = linkView[viewMode]; return (
{activeCollection && (

{activeCollection?.name}

    {permissions === true && (
  • { (document?.activeElement as HTMLElement)?.blur(); setEditCollectionModal(true); }} > {t("edit_collection_info")}
  • )}
  • { (document?.activeElement as HTMLElement)?.blur(); setEditCollectionSharingModal(true); }} > {permissions === true ? t("share_and_collaborate") : t("view_team")}
  • {permissions === true && (
  • { (document?.activeElement as HTMLElement)?.blur(); setNewCollectionModal(true); }} > {t("create_subcollection")}
  • )}
  • { (document?.activeElement as HTMLElement)?.blur(); setDeleteCollectionModal(true); }} > {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, })}

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