fix: list of streams glitching to top

This was due to real-time changes to items leading to scrolling to top.

Closes #123
This commit is contained in:
talksik
2026-04-08 08:56:12 -07:00
parent 7e11d66dc2
commit 8cbc04fff7
2 changed files with 18 additions and 6 deletions
+7 -2
View File
@@ -13,9 +13,14 @@ export function useStreamKeyboardNav({
}: UseStreamKeyboardNavOptions) {
const [selectedIndex, setSelectedIndex] = useState<number | null>(null);
// Reset selection to first item when streams change or view mode switches
// Initialize selection when streams first load; clear if streams become empty.
// Do NOT reset on every Firestore update — that would scroll the list to the top.
useEffect(() => {
setSelectedIndex(streams.length > 0 ? 0 : null);
setSelectedIndex((prev) => {
if (streams.length === 0) return null;
if (prev === null) return 0;
return prev;
});
}, [streams.length]);
useEffect(() => {