mirror of
https://github.com/sussy-code/smov.git
synced 2025-01-04 16:47:40 +01:00
34 lines
920 B
TypeScript
34 lines
920 B
TypeScript
|
import { useMemo } from "react";
|
||
|
import { useVideoPlayerState } from "../VideoContext";
|
||
|
|
||
|
export function useCurrentSeriesEpisodeInfo() {
|
||
|
const { videoState } = useVideoPlayerState();
|
||
|
|
||
|
const { current, seasons } = videoState.seasonData;
|
||
|
|
||
|
const currentSeasonInfo = useMemo(() => {
|
||
|
return seasons?.find((season) => season.id === current?.seasonId);
|
||
|
}, [seasons, current]);
|
||
|
|
||
|
const currentEpisodeInfo = useMemo(() => {
|
||
|
return currentSeasonInfo?.episodes?.find(
|
||
|
(episode) => episode.id === current?.episodeId
|
||
|
);
|
||
|
}, [currentSeasonInfo, current]);
|
||
|
|
||
|
const isSeries = Boolean(
|
||
|
videoState.seasonData.isSeries && videoState.seasonData.current
|
||
|
);
|
||
|
|
||
|
if (!isSeries) return { isSeries: false };
|
||
|
|
||
|
const episodeIdentifier = `S${currentSeasonInfo?.number} E${currentEpisodeInfo?.number}`;
|
||
|
|
||
|
return {
|
||
|
isSeries: true,
|
||
|
episodeIdentifier,
|
||
|
currentSeasonInfo,
|
||
|
currentEpisodeInfo,
|
||
|
};
|
||
|
}
|