fix(web): keep highlights card active index in range on refresh

The Daily Brief refreshes on its own every few hours, replacing the items
array, and the paging controls also let the user sit on a later index. When a
refresh returns fewer highlights than before, activeIndex was left pointing
past the end of the new list, so currentItem became undefined and the card
rendered the "Add some documents" empty state even though highlights existed,
with no pagination shown to recover from it.

Clamp activeIndex back into range whenever items changes, alongside the
existing reply/expansion reset. Also drops a now-unnecessary
useExhaustiveDependencies suppression, since the effect body now reads
items.length so items is a real dependency.
This commit is contained in:
abhay-codes07 2026-07-22 16:56:55 +05:30
parent 90f709bf8d
commit 34b0b3db59
No known key found for this signature in database

View file

@ -92,8 +92,12 @@ export function HighlightsCard({
if (isReplyOpen) replyInputRef.current?.focus()
}, [isReplyOpen])
// biome-ignore lint/correctness/useExhaustiveDependencies: intentionally re-run when items changes
useEffect(() => {
// The Daily Brief refreshes on its own every few hours, so items can be
// replaced with a shorter list while the user is on a later page. Pull the
// active index back into range, otherwise currentItem is undefined and the
// card falls through to the empty state even though highlights exist.
setActiveIndex((i) => Math.min(i, Math.max(items.length - 1, 0)))
setIsReplyOpen(false)
setReplyText("")
setIsExpanded(false)