mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-11-23 04:46:08 -08:00
feat(stats): group library seasons, movies and OVAs into franchise cards (#336)
This commit is contained in:
1 parent
9d2057cc30
commit
71251b8d7b
41 files changed
+2335
-109
No files matched your search
@@ -0,0 +1,62 @@
|
||||
import type { AnimeLibraryGroup, AnimeLibraryItem } from '../types/stats';
|
||||
|
||||
/** What a library card shows; a single entry or a whole franchise. */
|
||||
export type AnimeCardData = Pick<
|
||||
AnimeLibraryItem,
|
||||
| 'animeId'
|
||||
| 'canonicalTitle'
|
||||
| 'anilistId'
|
||||
| 'tmdbId'
|
||||
| 'mediaKind'
|
||||
| 'episodeCount'
|
||||
| 'totalActiveMs'
|
||||
| 'totalCards'
|
||||
> & {
|
||||
/** Set for franchise cards with more than one part. */
|
||||
partCount?: number;
|
||||
};
|
||||
|
||||
/** A one-part card is exactly that entry; a franchise card shows the first part's cover. */
|
||||
export function groupCardData(group: AnimeLibraryGroup): AnimeCardData {
|
||||
const cover = group.parts.find((part) => part.animeId === group.coverAnimeId) ?? group.parts[0]!;
|
||||
if (group.parts.length === 1) return cover;
|
||||
return {
|
||||
animeId: cover.animeId,
|
||||
canonicalTitle: group.title,
|
||||
anilistId: cover.anilistId,
|
||||
tmdbId: cover.tmdbId,
|
||||
mediaKind: group.mediaKind,
|
||||
episodeCount: group.episodeCount,
|
||||
totalActiveMs: group.totalActiveMs,
|
||||
totalCards: group.totalCards,
|
||||
partCount: group.parts.length,
|
||||
};
|
||||
}
|
||||
|
||||
/** Matches the franchise name or any part's title, so "Undead King" finds Overlord. */
|
||||
export function groupMatchesSearch(group: AnimeLibraryGroup, search: string): boolean {
|
||||
const term = search.trim().toLowerCase();
|
||||
if (!term) return true;
|
||||
return (
|
||||
group.title.toLowerCase().includes(term) ||
|
||||
group.parts.some((part) => part.canonicalTitle.toLowerCase().includes(term))
|
||||
);
|
||||
}
|
||||
|
||||
const FORMAT_LABELS: Record<string, string> = {
|
||||
TV: 'TV',
|
||||
TV_SHORT: 'TV Short',
|
||||
MOVIE: 'Movie',
|
||||
SPECIAL: 'Special',
|
||||
OVA: 'OVA',
|
||||
ONA: 'ONA',
|
||||
MUSIC: 'Music',
|
||||
};
|
||||
|
||||
/** "Movie · 2017" from AniList's format and yyyymmdd start date; null when neither is known. */
|
||||
export function describeAnimePart(format: string | null, startDate: number | null): string | null {
|
||||
const label = format ? (FORMAT_LABELS[format] ?? format) : null;
|
||||
const year = startDate ? String(Math.floor(startDate / 10_000)) : null;
|
||||
const parts = [label, year].filter((value): value is string => value !== null);
|
||||
return parts.length > 0 ? parts.join(' · ') : null;
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import type {
|
||||
StatsExcludedWord,
|
||||
StatsCoverImagesData,
|
||||
StatsAnilistAssignment,
|
||||
StatsAnimeGroupOverrideRequest,
|
||||
StatsAnkiNotesInfoRequest,
|
||||
StatsCoverImagesRequest,
|
||||
StatsDeleteSessionsRequest,
|
||||
@@ -163,6 +164,7 @@ export const apiClient = {
|
||||
getMediaLibrary: () => fetchJson('mediaLibrary', '/api/stats/media'),
|
||||
getMediaDetail: (videoId: number) => fetchJson('mediaDetail', `/api/stats/media/${videoId}`),
|
||||
getAnimeLibrary: () => fetchJson('animeLibrary', '/api/stats/anime'),
|
||||
getAnimeLibraryGroups: () => fetchJson('animeLibraryGroups', '/api/stats/anime/groups'),
|
||||
getAnimeMergeRecommendations: () =>
|
||||
fetchJson('animeMergeRecommendations', '/api/stats/anime/merge-recommendations'),
|
||||
getAnimeDetail: (animeId: number) => fetchJson('animeDetail', `/api/stats/anime/${animeId}`),
|
||||
@@ -268,6 +270,16 @@ export const apiClient = {
|
||||
});
|
||||
return res.json() as Promise<StatsMoveVideoResponse>;
|
||||
},
|
||||
setAnimeGroupOverride: async (
|
||||
animeId: number,
|
||||
request: StatsAnimeGroupOverrideRequest,
|
||||
): Promise<void> => {
|
||||
await fetchResponse(`/api/stats/anime/${animeId}/group`, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(request satisfies StatsAnimeGroupOverrideRequest),
|
||||
});
|
||||
},
|
||||
dismissAnimeMergeRecommendation: async (recommendationId: number): Promise<void> => {
|
||||
await fetchResponse(`/api/stats/anime/merge-recommendations/${recommendationId}`, {
|
||||
method: 'DELETE',
|
||||
|
||||
Reference in new issue
Block a user