Skip to content

Commit

Permalink
indicate when im behind in a series in admin/anime
Browse files Browse the repository at this point in the history
Signed-off-by: Vu Van Dung <[email protected]>
  • Loading branch information
joulev committed Oct 19, 2024
1 parent d20a93b commit c7d03d9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/app/admin/manage/anime/[[...status]]/card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ import {
import type { AnimeListItem, AnimeListItemStatus } from "~/lib/anime/get-lists";
import { constraintScore, convertSeason, getAccumulatedScore, getTitle } from "~/lib/anime/utils";
import { cn } from "~/lib/cn";
import { MediaFormat, MediaListStatus } from "~/lib/gql/graphql";
import { MediaFormat, MediaListStatus, MediaStatus } from "~/lib/gql/graphql";

function BottomPartTemplate({ text, children }: { text: string; children: React.ReactNode }) {
function BottomPartTemplate({
text,
children,
}: { text: React.ReactNode; children: React.ReactNode }) {
return (
<div className="flex flex-row flex-wrap items-end gap-x-3">
<div className="flex-grow text-sm text-text-secondary">{text}</div>
Expand Down Expand Up @@ -125,6 +128,15 @@ function UpdateItemScore({ item, status }: { item: AnimeListItem; status: AnimeL
);
}

function checkProgressBehind(item: AnimeListItem) {
if (item.media?.status !== MediaStatus.Releasing) return false;
const nextAiring = item.media?.nextAiringEpisode?.episode;
if (!nextAiring) return false;
const watchedEpisodes = item.progress ?? 0;
const behindBy = nextAiring - watchedEpisodes - 1;
return behindBy > 0;
}

function BottomPart({ item, status }: { item: AnimeListItem; status: AnimeListItemStatus }) {
const { optimisticListsAct } = useAnimeData();

Expand Down Expand Up @@ -185,7 +197,13 @@ function BottomPart({ item, status }: { item: AnimeListItem; status: AnimeListIt
switch (status) {
case "watching":
return (
<BottomPartTemplate text={`Progress: ${watchedEpisodes}/${totalEpisodes ?? "unknown"}`}>
<BottomPartTemplate
text={
<span className={cn(checkProgressBehind(item) && "text-yellow")}>
Progress: {watchedEpisodes}/{totalEpisodes ?? "unknown"}
</span>
}
>
<Button variants={{ size: "icon-sm" }} onClick={increment}>
<ChevronsRight />
</Button>
Expand Down
4 changes: 4 additions & 0 deletions src/lib/anime/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export const GET_ANIME = graphql(/* GraphQL */ `
season
seasonYear
format
status
nextAiringEpisode {
episode
}
}
}
}
Expand Down

0 comments on commit c7d03d9

Please sign in to comment.