Browse Source

more fixes

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

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

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

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

@ -3,6 +3,8 @@ import { useTranslation } from 'react-i18next'
import { RefreshCw } from 'lucide-react' import { RefreshCw } from 'lucide-react'
import { useNostr } from '@/providers/NostrProvider' import { useNostr } from '@/providers/NostrProvider'
import { useFavoriteRelays } from '@/providers/FavoriteRelaysProvider' import { useFavoriteRelays } from '@/providers/FavoriteRelaysProvider'
import { useSmartNoteNavigation } from '@/PageManager'
import { toNote } from '@/lib/link'
import { NostrEvent, Event as NostrEventType } from 'nostr-tools' import { NostrEvent, Event as NostrEventType } from 'nostr-tools'
import { kinds } from 'nostr-tools' import { kinds } from 'nostr-tools'
import { normalizeUrl } from '@/lib/url' import { normalizeUrl } from '@/lib/url'
@ -42,20 +44,35 @@ function countVotesForThread(threadId: string, reactions: NostrEvent[], threadAu
return 'emoji' return 'emoji'
} }
console.log('[DiscussionsPage] Counting votes for thread', threadId.substring(0, 8), 'with', reactions.length, 'reactions')
// Process all reactions for this thread // Process all reactions for this thread
reactions.forEach(reaction => { reactions.forEach(reaction => {
const eTags = reaction.tags.filter(tag => tag[0] === 'e' && tag[1]) const eTags = reaction.tags.filter(tag => tag[0] === 'e' && tag[1])
eTags.forEach(tag => { eTags.forEach(tag => {
if (tag[1] === threadId) { 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 // Skip self-votes
if (reaction.pubkey === threadAuthor) return if (reaction.pubkey === threadAuthor) {
console.log('[DiscussionsPage] Skipping self-vote')
return
}
const normalizedReaction = normalizeReaction(reaction.content) const normalizedReaction = normalizeReaction(reaction.content)
console.log('[DiscussionsPage] Normalized reaction:', normalizedReaction)
if (normalizedReaction === '+' || normalizedReaction === '-') { if (normalizedReaction === '+' || normalizedReaction === '-') {
const existingVote = userVotes.get(reaction.pubkey) const existingVote = userVotes.get(reaction.pubkey)
// Only keep the newest vote from each user // Only keep the newest vote from each user
if (!existingVote || reaction.created_at > existingVote.created_at) { if (!existingVote || reaction.created_at > existingVote.created_at) {
userVotes.set(reaction.pubkey, { type: normalizedReaction, created_at: reaction.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(() => {
const { t } = useTranslation() const { t } = useTranslation()
const { favoriteRelays, blockedRelays } = useFavoriteRelays() const { favoriteRelays, blockedRelays } = useFavoriteRelays()
const { pubkey } = useNostr() const { pubkey } = useNostr()
const { navigateToNote } = useSmartNoteNavigation()
// State // State
const [allEventMap, setAllEventMap] = useState<Map<string, EventMapEntry>>(new Map()) const [allEventMap, setAllEventMap] = useState<Map<string, EventMapEntry>>(new Map())
@ -458,6 +476,11 @@ const DiscussionsPage = forwardRef(() => {
const handleCloseDialog = () => { const handleCloseDialog = () => {
setShowCreateDialog(false) setShowCreateDialog(false)
} }
// Handle thread click
const handleThreadClick = (threadId: string) => {
navigateToNote(toNote(threadId))
}
return ( return (
<div className="flex flex-col h-full"> <div className="flex flex-col h-full">
@ -497,14 +520,14 @@ const DiscussionsPage = forwardRef(() => {
<option value="all">All found ({timeSpanCounts.all})</option> <option value="all">All found ({timeSpanCounts.all})</option>
</select> </select>
<button <button
onClick={handleRefresh} onClick={handleRefresh}
disabled={loading} disabled={loading}
className="p-2 hover:bg-gray-100 dark:hover:bg-gray-700 rounded" className="p-2 hover:bg-gray-100 dark:hover:bg-gray-700 rounded"
> >
<RefreshCw className={`w-4 h-4 ${isRefreshing ? 'animate-spin' : ''}`} /> <RefreshCw className={`w-4 h-4 ${isRefreshing ? 'animate-spin' : ''}`} />
</button> </button>
</div> </div>
</div> </div>
{/* Content */} {/* Content */}
@ -528,7 +551,7 @@ const DiscussionsPage = forwardRef(() => {
lastVoteTime={entry.lastVoteTime} lastVoteTime={entry.lastVoteTime}
upVotes={entry.upVotes} upVotes={entry.upVotes}
downVotes={entry.downVotes} downVotes={entry.downVotes}
onThreadClick={() => console.log('Thread clicked:', entry.event.id)} onThreadClick={() => handleThreadClick(entry.event.id)}
/> />
))} ))}
</div> </div>

Loading…
Cancel
Save