From f30161fb1ccb69e932e323cf84882ae8998b2e76 Mon Sep 17 00:00:00 2001 From: mrjvs Date: Tue, 24 Oct 2023 20:52:39 +0200 Subject: [PATCH] Fix incorrect season showing when opening episode menu + fix selected season not resetting after reopen episode menu --- src/components/player/atoms/Episodes.tsx | 27 +++++++++++++++--------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/components/player/atoms/Episodes.tsx b/src/components/player/atoms/Episodes.tsx index eee474a1..f79e2081 100644 --- a/src/components/player/atoms/Episodes.tsx +++ b/src/components/player/atoms/Episodes.tsx @@ -1,5 +1,5 @@ import classNames from "classnames"; -import { ReactNode, useCallback, useEffect, useState } from "react"; +import { ReactNode, useCallback, useEffect, useRef, useState } from "react"; import { useTranslation } from "react-i18next"; import { useAsync } from "react-use"; @@ -196,9 +196,14 @@ function EpisodesOverlay({ }) { const router = useOverlayRouter(id); const meta = usePlayerStore((s) => s.meta); - const [selectedSeason, setSelectedSeason] = useState( - meta?.season?.tmdbId ?? "" - ); + const [selectedSeason, setSelectedSeason] = useState(""); + + const lastActiveState = useRef(false); + useEffect(() => { + if (lastActiveState.current === router.isRouterActive) return; + lastActiveState.current = router.isRouterActive; + setSelectedSeason(meta?.season?.tmdbId ?? ""); + }, [meta, selectedSeason, setSelectedSeason, router.isRouterActive]); const setSeason = useCallback( (seasonId: string) => { @@ -215,12 +220,14 @@ function EpisodesOverlay({ - router.navigate("/")} - onChange={onChange} - /> + {selectedSeason.length > 0 ? ( + router.navigate("/")} + onChange={onChange} + /> + ) : null}