diff --git a/app/src/components/Videos.js b/app/src/components/Videos.js index 92c9d21b..10789f63 100644 --- a/app/src/components/Videos.js +++ b/app/src/components/Videos.js @@ -1,4 +1,4 @@ -import React, {useState} from 'react'; +import React, {useEffect, useState} from 'react'; import {Link, Route, Routes, useParams} from "react-router-dom"; import { defaultSearchOrder, @@ -22,7 +22,9 @@ import {deleteVideos} from "../api"; export function VideoWrapper() { const {videoId} = useParams(); const {videoFile, prevFile, nextFile, setFavorite} = useVideo(videoId); - scrollToTop(); + + // Scroll to the top when videoId changes. + useEffect(scrollToTop, [videoId]); return diff --git a/app/src/hooks/customHooks.js b/app/src/hooks/customHooks.js index 664e78dd..b50492e7 100644 --- a/app/src/hooks/customHooks.js +++ b/app/src/hooks/customHooks.js @@ -266,6 +266,12 @@ export const useVideo = (videoId) => { const [nextFile, setNextFile] = useState(null); const fetchVideo = async () => { + if (videoId && videoFile && videoFile.video.id !== videoId) { + // Video is changing. Clear the old video before fetching. + setVideoFile(null); + setPrevFile(null); + setNextFile(null); + } try { const [v, p, n] = await getVideo(videoId); setVideoFile(v);