2023-01-24 02:39:56 +01:00
|
|
|
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 };
|
|
|
|
|
2023-01-24 14:38:37 +01:00
|
|
|
const humanizedEpisodeId = `S${currentSeasonInfo?.number} E${currentEpisodeInfo?.number}`;
|
2023-01-24 02:39:56 +01:00
|
|
|
|
|
|
|
return {
|
|
|
|
isSeries: true,
|
2023-01-24 14:38:37 +01:00
|
|
|
humanizedEpisodeId,
|
2023-01-24 02:39:56 +01:00
|
|
|
currentSeasonInfo,
|
|
|
|
currentEpisodeInfo,
|
|
|
|
};
|
|
|
|
}
|