Refactor ShowDetail component to display loaded seasons: update season counting logic to return an array of loaded seasons, enhance UI to show the number of loaded seasons and their details, and update translations for new season information.

This commit is contained in:
Leonid Pershin
2026-07-25 00:54:00 +03:00
parent 17fdf32a3c
commit 5ad2746ddb
2 changed files with 23 additions and 14 deletions
@@ -73,15 +73,15 @@ export function ShowDetail({ showId }: { showId: string }) {
const selected = candidates.filter((c) => !deselected.has(c.asset.id)) const selected = candidates.filter((c) => !deselected.has(c.asset.id))
// Сколько разных сезонов загружено — по распознанным SxxExx в именах серий. // Какие сезоны загружены — по распознанным SxxExx в именах серий (отсортированы по возрастанию).
const seasonCount = useMemo(() => { const seasons = useMemo(() => {
if (!show) return 0 if (!show) return [] as number[]
const seasons = new Set<number>() const set = new Set<number>()
for (const e of show.episodes) { for (const e of show.episodes) {
const se = parseEpisode(e.assetName ?? '') const se = parseEpisode(e.assetName ?? '')
if (se) seasons.add(se.season) if (se) set.add(se.season)
} }
return seasons.size return [...set].sort((a, b) => a - b)
}, [show]) }, [show])
if (isLoading || !show) return <p className="text-muted-foreground">{t('common.loading')}</p> if (isLoading || !show) return <p className="text-muted-foreground">{t('common.loading')}</p>
@@ -126,17 +126,24 @@ export function ShowDetail({ showId }: { showId: string }) {
</Button> </Button>
</div> </div>
<div className="flex flex-wrap items-center gap-3"> <div className="flex flex-col gap-1">
<h2 className="crt-glow text-xl font-semibold">{show.name}</h2> <div className="flex flex-wrap items-center gap-3">
<Badge variant="muted">{t(`admin.shows.kinds.${show.kind}`)}</Badge> <h2 className="crt-glow text-xl font-semibold">{show.name}</h2>
{show.kind === 'Series' && ( <Badge variant="muted">{t(`admin.shows.kinds.${show.kind}`)}</Badge>
{show.kind === 'Series' && (
<Badge variant="muted">
{t('admin.shows.seasons')}: {seasons.length}
</Badge>
)}
<Badge variant="muted"> <Badge variant="muted">
{t('admin.shows.seasons')}: {seasonCount} {t('admin.shows.episodes')}: {show.episodes.length}
</Badge> </Badge>
</div>
{show.kind === 'Series' && seasons.length > 0 && (
<p className="text-sm text-muted-foreground">
{t('admin.shows.loadedSeasons')}: {seasons.join(', ')}
</p>
)} )}
<Badge variant="muted">
{t('admin.shows.episodes')}: {show.episodes.length}
</Badge>
</div> </div>
{canAdd && ( {canAdd && (
+2
View File
@@ -130,6 +130,7 @@ const resources = {
kind: 'Тип', kind: 'Тип',
kinds: { Series: 'Сериал', Single: 'Полнометражка' }, kinds: { Series: 'Сериал', Single: 'Полнометражка' },
seasons: 'Сезоны', seasons: 'Сезоны',
loadedSeasons: 'Загружены сезоны',
episodes: 'Серии', episodes: 'Серии',
episode: 'Серия', episode: 'Серия',
addEpisode: 'Добавить серию', addEpisode: 'Добавить серию',
@@ -358,6 +359,7 @@ const resources = {
kind: 'Kind', kind: 'Kind',
kinds: { Series: 'Series', Single: 'Movie' }, kinds: { Series: 'Series', Single: 'Movie' },
seasons: 'Seasons', seasons: 'Seasons',
loadedSeasons: 'Loaded seasons',
episodes: 'Episodes', episodes: 'Episodes',
episode: 'Episode', episode: 'Episode',
addEpisode: 'Add episode', addEpisode: 'Add episode',