2022-03-13 16:55:59 +01:00
|
|
|
import { getEpisodeFromMedia, MWMedia } from "providers";
|
2022-03-13 15:27:08 +01:00
|
|
|
import { useWatchedContext, getWatchedFromPortable } from "state/watched";
|
|
|
|
import { Episode } from "./EpisodeButton";
|
|
|
|
|
|
|
|
export interface WatchedEpisodeProps {
|
2022-03-13 16:55:59 +01:00
|
|
|
media: MWMedia;
|
2022-03-13 15:27:08 +01:00
|
|
|
onClick?: () => void;
|
|
|
|
active?: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function WatchedEpisode(props: WatchedEpisodeProps) {
|
|
|
|
const { watched } = useWatchedContext();
|
|
|
|
const foundWatched = getWatchedFromPortable(watched.items, props.media);
|
2022-03-13 16:55:59 +01:00
|
|
|
const episode = getEpisodeFromMedia(props.media);
|
2022-03-13 15:27:08 +01:00
|
|
|
const watchedPercentage = (foundWatched && foundWatched.percentage) || 0;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Episode
|
|
|
|
progress={watchedPercentage}
|
2022-03-13 16:55:59 +01:00
|
|
|
episodeNumber={episode?.episode?.sort ?? 1}
|
2022-03-13 15:27:08 +01:00
|
|
|
active={props.active}
|
|
|
|
onClick={props.onClick}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|