import { CollectionIncludingMembers, LinkIncludingCollectionAndTags, } from "@/types/global"; import { faFolder, faArrowUpRightFromSquare, faEllipsis, faThumbTack, } from "@fortawesome/free-solid-svg-icons"; import { faFileImage, faFilePdf } from "@fortawesome/free-regular-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { useEffect, useState } from "react"; import Image from "next/image"; import Dropdown from "./Dropdown"; import useLinkStore from "@/store/links"; import Link from "next/link"; import useCollectionStore from "@/store/collections"; import useAccountStore from "@/store/account"; import useModalStore from "@/store/modals"; type Props = { link: LinkIncludingCollectionAndTags; count: number; className?: string; }; export default function LinkCard({ link, count, className }: Props) { const { setModal } = useModalStore(); const [expandDropdown, setExpandDropdown] = useState(false); const { collections } = useCollectionStore(); const { account } = useAccountStore(); const [collection, setCollection] = useState( collections.find( (e) => e.id === link.collection.id ) as CollectionIncludingMembers ); useEffect(() => { setCollection( collections.find( (e) => e.id === link.collection.id ) as CollectionIncludingMembers ); }, [collections]); const { removeLink, updateLink } = useLinkStore(); const url = new URL(link.url); const formattedDate = new Date(link.createdAt as string).toLocaleString( "en-US", { year: "numeric", month: "short", day: "numeric", } ); return (
{ const target = e.target as HTMLElement; target.style.opacity = "0"; }} /> {link?.pinnedBy && link.pinnedBy[0] && (
)} { const target = e.target as HTMLElement; target.style.opacity = "0"; }} />

{count + 1}.

{link.name}

{link.description}

{collection?.name}

{link.tags.map((e, i) => (

{e.name}

))}

{formattedDate}

{url.host}

setExpandDropdown(!expandDropdown)} id={"expand-dropdown" + link.id} className="text-gray-500 inline-flex rounded-md cursor-pointer hover:bg-slate-200 duration-100 p-1" >
{expandDropdown ? ( { updateLink({ ...link, pinnedBy: link?.pinnedBy && link.pinnedBy[0] ? undefined : [{ id: account.id }], }); setExpandDropdown(false); }, }, { name: "Edit", onClick: () => { setModal({ modal: "LINK", state: true, method: "UPDATE", active: link, }); setExpandDropdown(false); }, }, { name: "Delete", onClick: () => { removeLink(link); setExpandDropdown(false); }, }, ]} onClickOutside={(e: Event) => { const target = e.target as HTMLInputElement; if (target.id !== "expand-dropdown" + link.id) setExpandDropdown(false); }} className="absolute top-8 right-0 w-36" /> ) : null}
); }