import { Card, CardContent, CardHeader } from '@/components/ui/card' import { Badge } from '@/components/ui/badge' import { Clock, Hash, Server } from 'lucide-react' import { NostrEvent } from 'nostr-tools' import { formatDistanceToNow } from 'date-fns' import { useTranslation } from 'react-i18next' import { cn } from '@/lib/utils' import { DISCUSSION_TOPICS } from './CreateThreadDialog' import Username from '@/components/Username' import UserAvatar from '@/components/UserAvatar' import VoteButtons from '@/components/NoteStats/VoteButtons' import { useScreenSize } from '@/providers/ScreenSizeProvider' interface ThreadWithRelaySource extends NostrEvent { _relaySource?: string } interface ThreadCardProps { thread: ThreadWithRelaySource onThreadClick: () => void className?: string } export default function ThreadCard({ thread, onThreadClick, className }: ThreadCardProps) { const { t } = useTranslation() const { isSmallScreen } = useScreenSize() // Extract title from tags const titleTag = thread.tags.find(tag => tag[0] === 'title' && tag[1]) const title = titleTag?.[1] || t('Untitled') // Extract topic from tags const topicTag = thread.tags.find(tag => tag[0] === 't' && tag[1]) const topic = topicTag?.[1] || 'general' // Extract author and subject for readings threads const authorTag = thread.tags.find(tag => tag[0] === 'author' && tag[1]) const subjectTag = thread.tags.find(tag => tag[0] === 'subject' && tag[1]) const isReadingGroup = thread.tags.find(tag => tag[0] === 't' && tag[1] === 'readings') // Get first 250 characters of content const contentPreview = thread.content.length > 250 ? thread.content.substring(0, 250) + '...' : thread.content // Format creation time const createdAt = new Date(thread.created_at * 1000) const timeAgo = formatDistanceToNow(createdAt, { addSuffix: true }) // Get topic display info from centralized DISCUSSION_TOPICS const getTopicInfo = (topicId: string) => { const topic = DISCUSSION_TOPICS.find(t => t.id === topicId) return topic || { id: topicId, label: topicId, icon: Hash } } const topicInfo = getTopicInfo(topic) // Format relay name for display const formatRelayName = (relaySource: string) => { if (relaySource === 'multiple') { return t('Multiple Relays') } return relaySource.replace('wss://', '').replace('ws://', '') } return ( {isSmallScreen ? (

{title}

{topicInfo.id}
{thread._relaySource && ( {formatRelayName(thread._relaySource)} )}
{timeAgo}
{isReadingGroup && (authorTag || subjectTag) && (
{authorTag && ( Author: {authorTag[1]} )} {subjectTag && ( Book: {subjectTag[1]} )}
)}
) : (

{title}

{thread._relaySource && ( {formatRelayName(thread._relaySource)} )}
{topicInfo.label}
{timeAgo}
{isReadingGroup && (authorTag || subjectTag) && (
{authorTag && ( Author: {authorTag[1]} )} {subjectTag && ( Book: {subjectTag[1]} )}
)}
)}
{contentPreview}
) }