improve initial scroll to active item in detail stream

This commit is contained in:
Josh Hawkins 2025-12-30 15:01:40 -06:00
parent 865ca80608
commit 774e567317

View File

@ -100,7 +100,25 @@ export default function DetailStream({
} }
}, [reviewItems, activeReviewId, effectiveTime]); }, [reviewItems, activeReviewId, effectiveTime]);
// Auto-scroll to current time // Initial scroll to active review (runs immediately when user selects, not during playback)
useEffect(() => {
if (!scrollRef.current || !activeReviewId || userInteracting || isPlaying)
return;
const element = scrollRef.current.querySelector(
`[data-review-id="${activeReviewId}"]`,
) as HTMLElement;
if (element) {
setProgrammaticScroll();
scrollIntoView(element, {
scrollMode: "if-needed",
behavior: "smooth",
});
}
}, [activeReviewId, setProgrammaticScroll, userInteracting, isPlaying]);
// Auto-scroll to current time during playback
useEffect(() => { useEffect(() => {
if (!scrollRef.current || userInteracting || !isPlaying) return; if (!scrollRef.current || userInteracting || !isPlaying) return;
// Prefer the review whose range contains the effectiveTime. If none // Prefer the review whose range contains the effectiveTime. If none