import { CollectionIncludingMembersAndLinkCount, LinkIncludingShortenedCollectionAndTags, } from "@/types/global"; import {faLink} from "@fortawesome/free-solid-svg-icons"; import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"; import {useEffect, useState} from "react"; import Image from "next/image"; import useLinkStore from "@/store/links"; import useCollectionStore from "@/store/collections"; import { faFileImage, faFilePdf, } from "@fortawesome/free-regular-svg-icons"; import isValidUrl from "@/lib/shared/isValidUrl"; import unescapeString from "@/lib/client/unescapeString"; import LinkActions from "@/components/LinkViews/LinkComponents/LinkActions"; import LinkDate from "@/components/LinkViews/LinkComponents/LinkDate"; import LinkCollection from "@/components/LinkViews/LinkComponents/LinkCollection"; type Props = { link: LinkIncludingShortenedCollectionAndTags; count: number; className?: string; }; export default function LinkCard({link, count, className}: Props) { const {links} = useLinkStore(); const {collections} = useCollectionStore(); const [collection, setCollection] = useState( collections.find( (e) => e.id === link.collection.id ) as CollectionIncludingMembersAndLinkCount ); useEffect(() => { setCollection( collections.find( (e) => e.id === link.collection.id ) as CollectionIncludingMembersAndLinkCount ); }, [collections, links]); let shortendURL; try { shortendURL = new URL(link.url || "").host.toLowerCase(); } catch (error) { console.log(error); } const url = isValidUrl(link.url || "") && link.url ? new URL(link.url) : undefined; return (
link.url && window.open(link.url || "", "_blank")} className="flex flex-col justify-between cursor-pointer h-full w-full gap-1 p-3" > {link.url && url ? ( { const target = e.target as HTMLElement; target.style.display = "none"; }} /> ) : link.type === "pdf" ? ( ) : link.type === "image" ? ( ) : undefined}

{count + 1}

{unescapeString(link.name || link.description) || link.url}

{link.url ? (

{shortendURL}

) : (
{link.type}
)} {/* {link.tags[0] ? (
{link.tags.map((e, i) => ( { e.stopPropagation(); }} className="btn btn-xs btn-ghost truncate max-w-[19rem]" > #{e.name} ))}
) : (

No Tags

)} */}
); }