Browse Source

fixed thread cards

imwald
Silberengel 5 months ago
parent
commit
515ea5d4d1
  1. 13
      src/pages/primary/DiscussionsPage/ThreadCard.tsx

13
src/pages/primary/DiscussionsPage/ThreadCard.tsx

@ -5,7 +5,6 @@ import { NostrEvent } from 'nostr-tools'
import { formatDistanceToNow } from 'date-fns' import { formatDistanceToNow } from 'date-fns'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { cn } from '@/lib/utils' import { cn } from '@/lib/utils'
import { truncateText } from '@/lib/utils'
import { DISCUSSION_TOPICS } from './CreateThreadDialog' import { DISCUSSION_TOPICS } from './CreateThreadDialog'
import Username from '@/components/Username' import Username from '@/components/Username'
import UserAvatar from '@/components/UserAvatar' import UserAvatar from '@/components/UserAvatar'
@ -34,8 +33,10 @@ export default function ThreadCard({ thread, onThreadClick, className }: ThreadC
const topicTag = thread.tags.find(tag => tag[0] === 't' && tag[1]) const topicTag = thread.tags.find(tag => tag[0] === 't' && tag[1])
const topic = topicTag?.[1] || 'general' const topic = topicTag?.[1] || 'general'
// Get first 250 words of content // Get first 250 characters of content
const contentPreview = truncateText(thread.content, 250) const contentPreview = thread.content.length > 250
? thread.content.substring(0, 250) + '...'
: thread.content
// Format creation time // Format creation time
const createdAt = new Date(thread.created_at * 1000) const createdAt = new Date(thread.created_at * 1000)
@ -75,7 +76,7 @@ export default function ThreadCard({ thread, onThreadClick, className }: ThreadC
<div className="flex items-start gap-3"> <div className="flex items-start gap-3">
<VoteButtons event={thread} /> <VoteButtons event={thread} />
<div className="flex-1 min-w-0"> <div className="flex-1 min-w-0">
<h3 className="font-semibold text-lg leading-tight line-clamp-2 mb-2"> <h3 className="font-semibold text-lg leading-tight line-clamp-2 mb-2 break-words">
{title} {title}
</h3> </h3>
<div className="flex items-center gap-2 text-sm text-muted-foreground"> <div className="flex items-center gap-2 text-sm text-muted-foreground">
@ -113,7 +114,7 @@ export default function ThreadCard({ thread, onThreadClick, className }: ThreadC
<VoteButtons event={thread} /> <VoteButtons event={thread} />
<div className="flex-1 min-w-0"> <div className="flex-1 min-w-0">
<div className="flex items-center gap-2 mb-2"> <div className="flex items-center gap-2 mb-2">
<h3 className="font-semibold text-lg leading-tight line-clamp-2"> <h3 className="font-semibold text-lg leading-tight line-clamp-2 break-words">
{title} {title}
</h3> </h3>
{thread._relaySource && ( {thread._relaySource && (
@ -148,7 +149,7 @@ export default function ThreadCard({ thread, onThreadClick, className }: ThreadC
</CardHeader> </CardHeader>
<CardContent className="pt-0"> <CardContent className="pt-0">
<div className="text-sm text-muted-foreground leading-relaxed"> <div className="text-sm text-muted-foreground leading-relaxed break-words overflow-hidden">
{contentPreview} {contentPreview}
</div> </div>
</CardContent> </CardContent>

Loading…
Cancel
Save