Fix incorrect season showing when opening episode menu + fix selected season not resetting after reopen episode menu

This commit is contained in:
mrjvs 2023-10-24 20:52:39 +02:00
parent f5492c7e21
commit f30161fb1c

View File

@ -1,5 +1,5 @@
import classNames from "classnames"; 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 { useTranslation } from "react-i18next";
import { useAsync } from "react-use"; import { useAsync } from "react-use";
@ -196,9 +196,14 @@ function EpisodesOverlay({
}) { }) {
const router = useOverlayRouter(id); const router = useOverlayRouter(id);
const meta = usePlayerStore((s) => s.meta); const meta = usePlayerStore((s) => s.meta);
const [selectedSeason, setSelectedSeason] = useState( const [selectedSeason, setSelectedSeason] = useState("");
meta?.season?.tmdbId ?? ""
); 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( const setSeason = useCallback(
(seasonId: string) => { (seasonId: string) => {
@ -215,12 +220,14 @@ function EpisodesOverlay({
<SeasonsView setSeason={setSeason} selectedSeason={selectedSeason} /> <SeasonsView setSeason={setSeason} selectedSeason={selectedSeason} />
</OverlayPage> </OverlayPage>
<OverlayPage id={id} path="/episodes" width={343} height={431}> <OverlayPage id={id} path="/episodes" width={343} height={431}>
{selectedSeason.length > 0 ? (
<EpisodesView <EpisodesView
selectedSeason={selectedSeason} selectedSeason={selectedSeason}
id={id} id={id}
goBack={() => router.navigate("/")} goBack={() => router.navigate("/")}
onChange={onChange} onChange={onChange}
/> />
) : null}
</OverlayPage> </OverlayPage>
</OverlayRouter> </OverlayRouter>
</Overlay> </Overlay>