fix: replies
This commit is contained in:
parent
a6c2decfe3
commit
304bbe4f01
13 changed files with 178 additions and 120 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import { useNostr } from '@/providers/NostrProvider'
|
||||
import { useNoteStats } from '@/providers/NoteStatsProvider'
|
||||
import { useReply } from '@/providers/ReplyProvider'
|
||||
import { MessageCircle } from 'lucide-react'
|
||||
import { Event } from 'nostr-tools'
|
||||
import { useMemo, useState } from 'react'
|
||||
|
|
@ -7,19 +7,13 @@ import { useTranslation } from 'react-i18next'
|
|||
import PostEditor from '../PostEditor'
|
||||
import { formatCount } from './utils'
|
||||
|
||||
export default function ReplyButton({
|
||||
event,
|
||||
variant = 'note'
|
||||
}: {
|
||||
event: Event
|
||||
variant?: 'note' | 'reply'
|
||||
}) {
|
||||
export default function ReplyButton({ event }: { event: Event }) {
|
||||
const { t } = useTranslation()
|
||||
const { checkLogin } = useNostr()
|
||||
const { noteStatsMap } = useNoteStats()
|
||||
const { replyCount } = useMemo(
|
||||
() => (variant === 'reply' ? {} : (noteStatsMap.get(event.id) ?? {})),
|
||||
[noteStatsMap, event.id, variant]
|
||||
const { repliesMap } = useReply()
|
||||
const replyCount = useMemo(
|
||||
() => repliesMap.get(event.id)?.events.length || 0,
|
||||
[repliesMap, event.id]
|
||||
)
|
||||
const [open, setOpen] = useState(false)
|
||||
|
||||
|
|
@ -36,9 +30,7 @@ export default function ReplyButton({
|
|||
title={t('Reply')}
|
||||
>
|
||||
<MessageCircle />
|
||||
{variant !== 'reply' && !!replyCount && (
|
||||
<div className="text-sm">{formatCount(replyCount)}</div>
|
||||
)}
|
||||
{!!replyCount && <div className="text-sm">{formatCount(replyCount)}</div>}
|
||||
</button>
|
||||
<PostEditor parentEvent={event} open={open} setOpen={setOpen} />
|
||||
</>
|
||||
|
|
|
|||
|
|
@ -16,8 +16,7 @@ export default function NoteStats({
|
|||
event,
|
||||
className,
|
||||
classNames,
|
||||
fetchIfNotExisting = false,
|
||||
variant = 'note'
|
||||
fetchIfNotExisting = false
|
||||
}: {
|
||||
event: Event
|
||||
className?: string
|
||||
|
|
@ -25,7 +24,6 @@ export default function NoteStats({
|
|||
buttonBar?: string
|
||||
}
|
||||
fetchIfNotExisting?: boolean
|
||||
variant?: 'note' | 'reply'
|
||||
}) {
|
||||
const { isSmallScreen } = useScreenSize()
|
||||
const { fetchNoteStats } = useNoteStats()
|
||||
|
|
@ -50,7 +48,7 @@ export default function NoteStats({
|
|||
)}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<ReplyButton event={event} variant={variant} />
|
||||
<ReplyButton event={event} />
|
||||
<RepostButton event={event} />
|
||||
<LikeButton event={event} />
|
||||
<ZapButton event={event} />
|
||||
|
|
@ -70,7 +68,7 @@ export default function NoteStats({
|
|||
className={cn('flex items-center', loading ? 'animate-pulse' : '')}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<ReplyButton event={event} variant={variant} />
|
||||
<ReplyButton event={event} />
|
||||
<RepostButton event={event} />
|
||||
<LikeButton event={event} />
|
||||
<ZapButton event={event} />
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue