Disable episodes in list when episode hasn't aired yet

This commit is contained in:
Jip Fr 2024-01-01 21:55:04 +01:00
parent fa396e0183
commit de74eac008
6 changed files with 42 additions and 6 deletions

View File

@ -189,7 +189,8 @@
"loadingList": "Loading...", "loadingList": "Loading...",
"loadingError": "Error loading season", "loadingError": "Error loading season",
"emptyState": "There are no episodes in this season, check back later!", "emptyState": "There are no episodes in this season, check back later!",
"episodeBadge": "E{{episode}}" "episodeBadge": "E{{episode}}",
"unairedEpisodes": "One or more episodes in this season are disabled because they are not out yet."
}, },
"sources": { "sources": {
"title": "Sources", "title": "Sources",

View File

@ -71,7 +71,7 @@ export function formatTMDBMeta(
type, type,
seasons: seasons as any, seasons: seasons as any,
seasonData: season seasonData: season
? ({ ? {
id: season.id.toString(), id: season.id.toString(),
number: season.season_number, number: season.season_number,
title: season.title, title: season.title,
@ -81,8 +81,9 @@ export function formatTMDBMeta(
id: v.id.toString(), id: v.id.toString(),
number: v.episode_number, number: v.episode_number,
title: v.title, title: v.title,
air_date: v.air_date,
})), })),
} as any) }
: (undefined as any), : (undefined as any),
}; };
} }
@ -227,6 +228,7 @@ export async function getEpisodes(
id: e.id, id: e.id,
episode_number: e.episode_number, episode_number: e.episode_number,
title: e.name, title: e.name,
air_date: e.air_date,
})); }));
} }

View File

@ -18,6 +18,7 @@ export type MWSeasonWithEpisodeMeta = {
id: string; id: string;
number: number; number: number;
title: string; title: string;
air_date: string;
}[]; }[];
}; };

View File

@ -13,6 +13,7 @@ export type TMDBEpisodeShort = {
title: string; title: string;
id: number; id: number;
episode_number: number; episode_number: number;
air_date: string;
}; };
export type TMDBMediaResult = { export type TMDBMediaResult = {

View File

@ -19,6 +19,8 @@ import { PlayerMeta } from "@/stores/player/slices/source";
import { usePlayerStore } from "@/stores/player/store"; import { usePlayerStore } from "@/stores/player/store";
import { useProgressStore } from "@/stores/progress"; import { useProgressStore } from "@/stores/progress";
import { hasAired } from "../utils/aired";
function CenteredText(props: { children: React.ReactNode }) { function CenteredText(props: { children: React.ReactNode }) {
return ( return (
<div className="h-full w-full flex justify-center items-center p-8 text-center"> <div className="h-full w-full flex justify-center items-center p-8 text-center">
@ -135,6 +137,9 @@ function EpisodesView({
<CenteredText>{t("player.menus.episodes.loadingList")}</CenteredText> <CenteredText>{t("player.menus.episodes.loadingList")}</CenteredText>
); );
else if (loadingState.value) { else if (loadingState.value) {
const hasUnairedEpisodes = loadingState.value.season.episodes.some(
(ep) => !hasAired(ep.air_date),
);
content = ( content = (
<Menu.ScrollToActiveSection className="pb-6"> <Menu.ScrollToActiveSection className="pb-6">
{loadingState.value.season.episodes.length === 0 ? ( {loadingState.value.season.episodes.length === 0 ? (
@ -163,19 +168,31 @@ function EpisodesView({
return ( return (
<Menu.Link <Menu.Link
key={ep.id} key={ep.id}
onClick={() => playEpisode(ep.id)} onClick={() =>
hasAired(ep.air_date) ? playEpisode(ep.id) : null
}
active={ep.id === meta?.episode?.tmdbId} active={ep.id === meta?.episode?.tmdbId}
clickable clickable={hasAired(ep.air_date)}
rightSide={rightSide} rightSide={rightSide}
> >
<Menu.LinkTitle> <Menu.LinkTitle>
<div className="text-left flex items-center space-x-3"> <div
className={classNames(
"text-left flex items-center space-x-3 text-video-context-type-main",
hasAired(ep.air_date) || ep.id === meta?.episode?.tmdbId
? ""
: "text-opacity-25",
)}
>
<span <span
className={classNames( className={classNames(
"p-0.5 px-2 rounded inline bg-video-context-hoverColor", "p-0.5 px-2 rounded inline bg-video-context-hoverColor",
ep.id === meta?.episode?.tmdbId ep.id === meta?.episode?.tmdbId
? "text-white bg-opacity-100" ? "text-white bg-opacity-100"
: "bg-opacity-50", : "bg-opacity-50",
hasAired(ep.air_date) || ep.id === meta?.episode?.tmdbId
? ""
: "!bg-opacity-25",
)} )}
> >
{t("player.menus.episodes.episodeBadge", { {t("player.menus.episodes.episodeBadge", {
@ -188,6 +205,9 @@ function EpisodesView({
</Menu.Link> </Menu.Link>
); );
})} })}
{hasUnairedEpisodes ? (
<p>{t("player.menus.episodes.unairedEpisodes")}</p>
) : null}
</Menu.ScrollToActiveSection> </Menu.ScrollToActiveSection>
); );
} }

View File

@ -0,0 +1,11 @@
const hasAiredCache: { [key: string]: boolean } = {};
export function hasAired(date: string) {
if (hasAiredCache[date]) return hasAiredCache[date];
const now = new Date();
const airDate = new Date(date);
hasAiredCache[date] = airDate < now;
return hasAiredCache[date];
}