import { useContext } from "react"; import type { RichContent } from "../model.ts"; import { PlayerContext } from "../contexts/PlayerContext.ts"; import Thumbnail from "./Thumbnail.tsx"; interface RichContentCardProps { richContent: RichContent; compact?: boolean; /** Overrides richContent.thumbnailUrl with a custom dump thumbnail, if set. */ thumbnailOverrideUrl?: string; /** Link back to the owning dump, surfaced as the global player's title. */ dumpHref?: string; } export default function RichContentCard( { richContent, compact = false, thumbnailOverrideUrl, dumpHref }: RichContentCardProps, ) { const { play, current, playing } = useContext(PlayerContext); const thumbnailSrc = thumbnailOverrideUrl ?? richContent.thumbnailUrl; const placeholder = { url: richContent.url, accentColor: richContent.accentColor, faviconUrl: richContent.faviconUrl, siteName: richContent.siteName, }; if (compact) { const thumbnail = ( ); if (richContent.embedUrl) { const isActive = current?.kind === "embed" && current.embedUrl === richContent.embedUrl; const isPlaying = isActive && playing; return ( ); } return ( e.stopPropagation()} > {thumbnail} ); } const canPlay = !!richContent.embedUrl; const thumbnailImg = ( ); const thumbnail = canPlay ? ( ) : thumbnailImg; return (
{thumbnail} {richContent.siteName && ( {richContent.siteName} )} {richContent.title && (

{richContent.title}

)} {richContent.description && (

{richContent.description}

)} {richContent.url}
); }