handle setSeekToTimestamp reset in player

This commit is contained in:
Simon 2025-07-11 17:06:06 +07:00
parent 2e95412b5b
commit 7d5d64a48d
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
2 changed files with 5 additions and 3 deletions

View File

@ -112,6 +112,7 @@ type VideoPlayerProps = {
onWatchStateChanged?: (status: boolean) => void;
onVideoEnd?: () => void;
seekToTimestamp?: number;
setSeekToTimestamp?: (timestamp: number | undefined) => void;
};
const VideoPlayer = ({
@ -122,6 +123,7 @@ const VideoPlayer = ({
onWatchStateChanged,
onVideoEnd,
seekToTimestamp,
setSeekToTimestamp,
}: VideoPlayerProps) => {
const videoRef = useRef<HTMLVideoElement | null>(null);
@ -140,6 +142,8 @@ const VideoPlayer = ({
if (videoRef.current.paused) {
videoRef.current.play();
}
if (setSeekToTimestamp) setSeekToTimestamp(undefined);
window.scroll(0, 0);
}, [seekToTimestamp]);
const [searchParams] = useSearchParams();

View File

@ -138,9 +138,6 @@ const Video = () => {
const handleTimestampClick = (seconds: number) => {
setSeekToTimestamp(seconds);
// Reset timestamp to allow clicking again
setTimeout(() => setSeekToTimestamp(undefined), 500);
};
useEffect(() => {
@ -233,6 +230,7 @@ const Video = () => {
sponsorBlock={sponsorBlock}
autoplay={playlistAutoplay}
seekToTimestamp={seekToTimestamp}
setSeekToTimestamp={setSeekToTimestamp}
onWatchStateChanged={() => {
setRefreshVideoList(true);
}}