"use client" import { formatDistanceToNow, format } from "date-fns" import { classNames } from "@/lib/utilities" import { useUserInterfaceStore } from "@/lib/stores/user-interface-store" import type { TimelineEntry } from "@/lib/types/timeline" import type { VirtualItem } from "@tanstack/react-virtual" function getEntryFaviconUrl(entryUrl: string): string | null { try { const hostname = new URL(entryUrl).hostname return `https://www.google.com/s2/favicons?domain=${hostname}&sz=16` } catch { return null } } interface EntryListItemProperties { entry: TimelineEntry isSelected: boolean isFocused: boolean viewMode: "compact" | "comfortable" | "expanded" onSelect: () => void measureReference: (element: HTMLElement | null) => void virtualItem: VirtualItem } function stripHtmlTags(html: string): string { return html .replace(/<[^>]*>/g, "") .replace(/&#(\d+);/g, (_, code) => String.fromCharCode(Number(code))) .replace(/&#x([0-9a-fA-F]+);/g, (_, code) => String.fromCharCode(parseInt(code, 16))) .replace(/&/g, "&") .replace(/</g, "<") .replace(/>/g, ">") .replace(/"/g, '"') .replace(/'/g, "'") .replace(/ /g, " ") .trim() } export function EntryListItem({ entry, isSelected, isFocused, viewMode, onSelect, measureReference, virtualItem, }: EntryListItemProperties) { const timeDisplayFormat = useUserInterfaceStore( (state) => state.timeDisplayFormat ) const showEntryImages = useUserInterfaceStore( (state) => state.showEntryImages ) const showEntryFavicons = useUserInterfaceStore( (state) => state.showEntryFavicons ) const faviconUrl = showEntryFavicons ? getEntryFaviconUrl(entry.entryUrl) : null const formattedTimestamp = entry.publishedAt ? timeDisplayFormat === "absolute" ? format(new Date(entry.publishedAt), "MMM d, h:mm a") : formatDistanceToNow(new Date(entry.publishedAt), { addSuffix: true }) : "" const displayTitle = entry.customTitle ?? entry.feedTitle return ( ) }