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:
@@ -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(() => {
|
||||
|
||||
Reference in New Issue
Block a user