feat: enhance reply experience

This commit is contained in:
codytseng
2024-12-24 21:42:32 +08:00
parent 6b58d1673b
commit 109c4ef6f0

View File

@@ -26,6 +26,7 @@ export default function ReplyNoteList({ event, className }: { event: NEvent; cla
const [highlightReplyId, setHighlightReplyId] = useState<string | undefined>(undefined)
const { updateNoteReplyCount } = useNoteStats()
const replyRefs = useRef<Record<string, HTMLDivElement | null>>({})
const bottomRef = useRef<HTMLDivElement | null>(null)
useEffect(() => {
const handleEventPublished = (data: Event) => {
@@ -145,15 +146,20 @@ export default function ReplyNoteList({ event, className }: { event: NEvent; cla
})
if (evt.pubkey === pubkey) {
setTimeout(() => {
highlightReply(evt.id)
if (bottomRef.current) {
bottomRef.current.scrollIntoView({ behavior: 'smooth', block: 'nearest' })
}
highlightReply(evt.id, false)
}, 100)
}
}
const highlightReply = (eventId: string) => {
const highlightReply = (eventId: string, scrollTo = true) => {
if (scrollTo) {
const ref = replyRefs.current[eventId]
if (ref) {
ref.scrollIntoView({ behavior: 'smooth', block: 'center' })
ref.scrollIntoView({ behavior: 'smooth', block: 'nearest' })
}
}
setHighlightReplyId(eventId)
setTimeout(() => {
@@ -188,6 +194,7 @@ export default function ReplyNoteList({ event, className }: { event: NEvent; cla
{replies.length === 0 && !loading && !until && (
<div className="text-sm text-center text-muted-foreground">{t('no replies')}</div>
)}
<div ref={bottomRef} />
</>
)
}