import Link from "next/link"; import { CollectionIncludingMembersAndLinkCount } from "@/types/global"; import React, { useEffect, useState } from "react"; import ProfilePhoto from "./ProfilePhoto"; import usePermissions from "@/hooks/usePermissions"; import useLocalSettingsStore from "@/store/localSettings"; import getPublicUserData from "@/lib/client/getPublicUserData"; import useAccountStore from "@/store/account"; import EditCollectionModal from "./ModalContent/EditCollectionModal"; import EditCollectionSharingModal from "./ModalContent/EditCollectionSharingModal"; import DeleteCollectionModal from "./ModalContent/DeleteCollectionModal"; type Props = { collection: CollectionIncludingMembersAndLinkCount; className?: string; }; export default function CollectionCard({ collection, className }: Props) { const { settings } = useLocalSettingsStore(); const { account } = useAccountStore(); const formattedDate = new Date(collection.createdAt as string).toLocaleString( "en-US", { year: "numeric", month: "short", day: "numeric", } ); const permissions = usePermissions(collection.id as number); 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 (collection && collection.ownerId !== account.id) { const owner = await getPublicUserData(collection.ownerId as number); setCollectionOwner(owner); } else if (collection && collection.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(); }, [collection]); const [editCollectionModal, setEditCollectionModal] = useState(false); const [editCollectionSharingModal, setEditCollectionSharingModal] = useState(false); const [deleteCollectionModal, setDeleteCollectionModal] = useState(false); return (
setEditCollectionSharingModal(true)} > {collectionOwner.id ? ( ) : undefined} {collection.members .sort((a, b) => (a.userId as number) - (b.userId as number)) .map((e, i) => { return ( ); }) .slice(0, 3)} {collection.members.length - 3 > 0 ? (
+{collection.members.length - 3}
) : null}

{collection.name}

{collection.isPublic ? ( ) : undefined} {collection._count && collection._count.links}

{formattedDate}

{editCollectionModal ? ( setEditCollectionModal(false)} activeCollection={collection} /> ) : undefined} {editCollectionSharingModal ? ( setEditCollectionSharingModal(false)} activeCollection={collection} /> ) : undefined} {deleteCollectionModal ? ( setDeleteCollectionModal(false)} activeCollection={collection} /> ) : undefined}
); }