This commit is contained in:
Arjun Patel
2026-06-11 10:45:11 -07:00
parent dd850d28d1
commit 1cf144bce3
2 changed files with 17 additions and 11 deletions
@@ -1,5 +1,4 @@
import { useEffect, type RefObject } from 'react';
import { useNavigate } from 'react-router-dom';
import type { MediaParticleHandle } from '@/features/particles/media-particle-view';
import { isTypingTarget } from '@/lib/keyboard';
@@ -11,6 +10,7 @@ interface UseStreamNavigationKeysOptions {
currentIndex: number;
childrenLength: number;
mediaRef: RefObject<MediaParticleHandle | null>;
onExit: () => void;
}
/**
@@ -23,9 +23,8 @@ export function useStreamNavigationKeys({
currentIndex,
childrenLength,
mediaRef,
onExit,
}: UseStreamNavigationKeysOptions) {
const navigate = useNavigate();
useEffect(() => {
const onKeyDown = (e: KeyboardEvent) => {
if (isTypingTarget(e)) return;
@@ -53,12 +52,12 @@ export function useStreamNavigationKeys({
break;
case 'Escape':
e.preventDefault();
navigate(-1);
onExit();
break;
}
};
window.addEventListener('keydown', onKeyDown);
return () => window.removeEventListener('keydown', onKeyDown);
}, [next, prev, currentIndex, childrenLength, mediaRef, navigate]);
}, [next, prev, currentIndex, childrenLength, mediaRef, onExit]);
}