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