import React, { useState } from 'react' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { faBookmark, faUserLock, faChevronDown, faChevronUp } from '@fortawesome/free-solid-svg-icons' import { IndividualBookmark } from '../../types/bookmarks' import { formatDate, renderParsedContent } from '../../utils/bookmarkUtils' import ContentWithResolvedProfiles from '../ContentWithResolvedProfiles' import IconButton from '../IconButton' import { classifyUrl } from '../../utils/helpers' import { IconGetter } from './shared' interface CardViewProps { bookmark: IndividualBookmark index: number hasUrls: boolean extractedUrls: string[] onSelectUrl?: (url: string) => void getIconForUrlType: IconGetter firstUrlClassification: { buttonText: string } | null authorNpub: string eventNevent?: string getAuthorDisplayName: () => string handleReadNow: (e: React.MouseEvent) => void } export const CardView: React.FC = ({ bookmark, index, hasUrls, extractedUrls, onSelectUrl, getIconForUrlType, firstUrlClassification, authorNpub, eventNevent, getAuthorDisplayName, handleReadNow }) => { const [expanded, setExpanded] = useState(false) const [urlsExpanded, setUrlsExpanded] = useState(false) const contentLength = (bookmark.content || '').length const shouldTruncate = !expanded && contentLength > 210 return (
{bookmark.isPrivate ? ( <> ) : ( )} {eventNevent ? ( {formatDate(bookmark.created_at)} ) : ( {formatDate(bookmark.created_at)} )}
{extractedUrls.length > 0 && (
{(urlsExpanded ? extractedUrls : extractedUrls.slice(0, 1)).map((url, urlIndex) => { const classification = classifyUrl(url) return (
{ e.preventDefault(); onSelectUrl?.(url) }} />
) })} {extractedUrls.length > 1 && ( )}
)} {bookmark.parsedContent ? (
{shouldTruncate && bookmark.content ? : renderParsedContent(bookmark.parsedContent)}
) : bookmark.content && (
)} {contentLength > 210 && ( )}
{getAuthorDisplayName()}
{hasUrls && firstUrlClassification && ( )}
) }