mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-22 07:56:18 -05:00
Only scrolling to top when changing videos. Clearing old video when changing videos.
This commit is contained in:
parent
6854fa3692
commit
b163b60837
2 changed files with 10 additions and 2 deletions
|
|
@ -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 <VideoPage videoFile={videoFile} prevFile={prevFile} nextFile={nextFile}
|
||||
setFavorite={setFavorite} autoplay={true}/>
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue