Browse Source

more fixes

imwald
Silberengel 5 months ago
parent
commit
496e27ab4a
  1. 18
      src/pages/primary/DiscussionsPage/ThreadCard.tsx
  2. 27
      src/pages/primary/DiscussionsPage/index.tsx

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

@ -8,7 +8,6 @@ import { cn } from '@/lib/utils' @@ -8,7 +8,6 @@ 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'
import { extractAllTopics } from '@/lib/discussion-topics'
@ -88,8 +87,8 @@ export default function ThreadCard({ @@ -88,8 +87,8 @@ export default function ThreadCard({
<div className="space-y-3">
<div className="flex items-start gap-3">
<div className="flex flex-col items-center gap-1">
<div className="text-green-600 font-semibold text-sm">+{upVotes}</div>
<div className="text-red-600 font-semibold text-sm">-{downVotes}</div>
<div className="text-green-600 font-semibold text-sm">+{upVotes || 0}</div>
<div className="text-red-600 font-semibold text-sm">-{downVotes || 0}</div>
</div>
<div className="flex-1 min-w-0">
<h3 className="font-semibold text-lg leading-tight line-clamp-2 mb-2 break-words">
@ -122,22 +121,18 @@ export default function ThreadCard({ @@ -122,22 +121,18 @@ export default function ThreadCard({
<span>{timeAgo}</span>
</div>
{/* Vote counts */}
{totalVotes > 0 && (
{/* Vote counts - always show */}
<div className="text-xs text-muted-foreground">
<span className={netVotes > 0 ? 'text-green-600' : netVotes < 0 ? 'text-red-600' : ''}>
{netVotes > 0 ? '+' : ''}{netVotes}
</span>
{' '}{t('votes')} ({totalVotes} {t('total')})
</div>
)}
{/* Comment count */}
{commentCount > 0 && (
{/* Comment count - always show */}
<div className="text-xs text-muted-foreground">
{commentCount} {commentCount === 1 ? t('comment') : t('comments')}
</div>
)}
{/* Last activity */}
{lastCommentAgo && (
@ -156,7 +151,10 @@ export default function ThreadCard({ @@ -156,7 +151,10 @@ export default function ThreadCard({
) : (
<div className="flex items-start justify-between gap-3">
<div className="flex items-start gap-3 flex-1 min-w-0">
<VoteButtons event={thread} />
<div className="flex flex-col items-center gap-1">
<div className="text-green-600 font-semibold text-sm">+{upVotes || 0}</div>
<div className="text-red-600 font-semibold text-sm">-{downVotes || 0}</div>
</div>
<div className="flex-1 min-w-0">
<div className="flex items-center gap-2 mb-2">
<h3 className="font-semibold text-lg leading-tight line-clamp-2 break-words">

27
src/pages/primary/DiscussionsPage/index.tsx

@ -3,6 +3,8 @@ import { useTranslation } from 'react-i18next' @@ -3,6 +3,8 @@ import { useTranslation } from 'react-i18next'
import { RefreshCw } from 'lucide-react'
import { useNostr } from '@/providers/NostrProvider'
import { useFavoriteRelays } from '@/providers/FavoriteRelaysProvider'
import { useSmartNoteNavigation } from '@/PageManager'
import { toNote } from '@/lib/link'
import { NostrEvent, Event as NostrEventType } from 'nostr-tools'
import { kinds } from 'nostr-tools'
import { normalizeUrl } from '@/lib/url'
@ -42,20 +44,35 @@ function countVotesForThread(threadId: string, reactions: NostrEvent[], threadAu @@ -42,20 +44,35 @@ function countVotesForThread(threadId: string, reactions: NostrEvent[], threadAu
return 'emoji'
}
console.log('[DiscussionsPage] Counting votes for thread', threadId.substring(0, 8), 'with', reactions.length, 'reactions')
// Process all reactions for this thread
reactions.forEach(reaction => {
const eTags = reaction.tags.filter(tag => tag[0] === 'e' && tag[1])
eTags.forEach(tag => {
if (tag[1] === threadId) {
console.log('[DiscussionsPage] Found reaction for thread', threadId.substring(0, 8), ':', {
content: reaction.content,
pubkey: reaction.pubkey.substring(0, 8),
isSelf: reaction.pubkey === threadAuthor,
created_at: reaction.created_at
})
// Skip self-votes
if (reaction.pubkey === threadAuthor) return
if (reaction.pubkey === threadAuthor) {
console.log('[DiscussionsPage] Skipping self-vote')
return
}
const normalizedReaction = normalizeReaction(reaction.content)
console.log('[DiscussionsPage] Normalized reaction:', normalizedReaction)
if (normalizedReaction === '+' || normalizedReaction === '-') {
const existingVote = userVotes.get(reaction.pubkey)
// Only keep the newest vote from each user
if (!existingVote || reaction.created_at > existingVote.created_at) {
userVotes.set(reaction.pubkey, { type: normalizedReaction, created_at: reaction.created_at })
console.log('[DiscussionsPage] Added vote:', normalizedReaction, 'from', reaction.pubkey.substring(0, 8))
}
}
}
@ -116,6 +133,7 @@ const DiscussionsPage = forwardRef(() => { @@ -116,6 +133,7 @@ const DiscussionsPage = forwardRef(() => {
const { t } = useTranslation()
const { favoriteRelays, blockedRelays } = useFavoriteRelays()
const { pubkey } = useNostr()
const { navigateToNote } = useSmartNoteNavigation()
// State
const [allEventMap, setAllEventMap] = useState<Map<string, EventMapEntry>>(new Map())
@ -459,6 +477,11 @@ const DiscussionsPage = forwardRef(() => { @@ -459,6 +477,11 @@ const DiscussionsPage = forwardRef(() => {
setShowCreateDialog(false)
}
// Handle thread click
const handleThreadClick = (threadId: string) => {
navigateToNote(toNote(threadId))
}
return (
<div className="flex flex-col h-full">
{/* Header */}
@ -528,7 +551,7 @@ const DiscussionsPage = forwardRef(() => { @@ -528,7 +551,7 @@ const DiscussionsPage = forwardRef(() => {
lastVoteTime={entry.lastVoteTime}
upVotes={entry.upVotes}
downVotes={entry.downVotes}
onThreadClick={() => console.log('Thread clicked:', entry.event.id)}
onThreadClick={() => handleThreadClick(entry.event.id)}
/>
))}
</div>

Loading…
Cancel
Save