feat: auto-show new notes at top

This commit is contained in:
codytseng 2026-01-05 13:13:17 +08:00
parent 53a67d8233
commit d1b3a8c4c7
10 changed files with 32 additions and 82 deletions

View file

@ -338,9 +338,21 @@ const NoteList = forwardRef<
oldEvents.some((e) => e.id === event.id) ? oldEvents : [event, ...oldEvents]
)
} else {
setNewEvents((oldEvents) =>
[event, ...oldEvents].sort((a, b) => b.created_at - a.created_at)
)
const isAtTop = (() => {
if (!topRef.current) return true
const rect = topRef.current.getBoundingClientRect()
return rect.top >= 50
})()
if (isAtTop) {
setEvents((oldEvents) =>
oldEvents.some((e) => e.id === event.id) ? oldEvents : [event, ...oldEvents]
)
} else {
setNewEvents((oldEvents) =>
[event, ...oldEvents].sort((a, b) => b.created_at - a.created_at)
)
}
}
threadService.addRepliesToThread([event])
},