From 0fc86407be8cf3c7ed5bd7ec56da57bf4a993f31 Mon Sep 17 00:00:00 2001 From: MerlinScheurer Date: Thu, 6 Mar 2025 23:54:12 +0100 Subject: [PATCH] Refac refresh video list when videoId changing --- frontend/src/pages/ChannelVideo.tsx | 2 ++ frontend/src/pages/Home.tsx | 2 ++ frontend/src/pages/Playlist.tsx | 10 +++++++++- frontend/src/pages/Search.tsx | 3 ++- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/frontend/src/pages/ChannelVideo.tsx b/frontend/src/pages/ChannelVideo.tsx index 3a22aee2..aa8db33f 100644 --- a/frontend/src/pages/ChannelVideo.tsx +++ b/frontend/src/pages/ChannelVideo.tsx @@ -45,6 +45,7 @@ const ChannelVideo = ({ videoType }: ChannelVideoProps) => { const channel = channelResponse; const videoList = videoResponse?.data; const pagination = videoResponse?.paginate; + const refreshWhenVideoIdChanges = videoId !== null; const hasVideos = videoResponse?.data?.length !== 0; @@ -80,6 +81,7 @@ const ChannelVideo = ({ videoType }: ChannelVideoProps) => { channelId, pagination?.current_page, videoType, + refreshWhenVideoIdChanges, ]); if (!channel) { diff --git a/frontend/src/pages/Home.tsx b/frontend/src/pages/Home.tsx index 70a6fb70..0d58f410 100644 --- a/frontend/src/pages/Home.tsx +++ b/frontend/src/pages/Home.tsx @@ -117,6 +117,7 @@ const Home = () => { const videoList = videoResponse?.data; const pagination = videoResponse?.paginate; const continueVideos = continueVideoResponse?.data; + const refreshWhenVideoIdChanges = videoId !== null; const hasVideos = videoResponse?.data?.length !== 0; @@ -152,6 +153,7 @@ const Home = () => { userConfig.hide_watched, currentPage, pagination?.current_page, + refreshWhenVideoIdChanges, ]); return ( diff --git a/frontend/src/pages/Playlist.tsx b/frontend/src/pages/Playlist.tsx index 31719d9c..bd4ad549 100644 --- a/frontend/src/pages/Playlist.tsx +++ b/frontend/src/pages/Playlist.tsx @@ -56,6 +56,7 @@ const Playlist = () => { const palylistEntries = playlistResponse?.playlist_entries; const videoArchivedCount = Number(palylistEntries?.filter(video => video.downloaded).length); const videoInPlaylistCount = pagination?.total_hits; + const refreshWhenVideoIdChanges = videoId !== null; const view = userConfig.view_style_home; const gridItems = userConfig.grid_items; @@ -86,7 +87,14 @@ const Playlist = () => { setRefresh(false); })(); // eslint-disable-next-line react-hooks/exhaustive-deps - }, [playlistId, userConfig.hide_watched, refresh, currentPage, pagination?.current_page]); + }, [ + playlistId, + userConfig.hide_watched, + refresh, + currentPage, + pagination?.current_page, + refreshWhenVideoIdChanges, + ]); if (!playlistId || !playlist) { return `Playlist ${playlistId} not found!`; diff --git a/frontend/src/pages/Search.tsx b/frontend/src/pages/Search.tsx index eb1d13b5..2db6c4f3 100644 --- a/frontend/src/pages/Search.tsx +++ b/frontend/src/pages/Search.tsx @@ -56,6 +56,7 @@ const Search = () => { const playlistList = searchResults?.results.playlist_results; const fulltextList = searchResults?.results.fulltext_results; const queryType = searchResults?.queryType; + const refreshWhenVideoIdChanges = videoId !== null; const hasSearchQuery = searchTerm.length > 0; const hasVideos = Number(videoList?.length) > 0; @@ -89,7 +90,7 @@ const Search = () => { } else { setSearchResults(EmptySearchResponse); } - }, [debouncedSearchTerm, refresh]); + }, [debouncedSearchTerm, refresh, refreshWhenVideoIdChanges]); const fetchResults = async (searchQuery: string) => { const searchResults = await loadSearch(searchQuery);