diff --git a/src/components/EpisodeList.tsx b/src/components/EpisodeList.tsx new file mode 100644 index 0000000..5a35ea6 --- /dev/null +++ b/src/components/EpisodeList.tsx @@ -0,0 +1,143 @@ +import { Check, Loader2 } from 'lucide-react' +import { useEffect, useLayoutEffect, useRef, useState } from 'react' +import { locale, t } from '../i18n' +import { getTmdbSeasonEpisodes, type EpisodeInfo } from '../lib/catalogApi' +import { episodeCap, episodesBeforeSeason, seasonPosition } from '../lib/franchise' +import { cx, todayISO } from '../lib/utils' +import { useMedia } from '../store' +import type { MediaInput } from '../types' + +interface Props { + form: Pick + /** Nouveau nombre d'épisodes vus (et saison choisie) */ + onChange: (episodesWatched: number, season?: number) => void +} + +const MAX_GENERIC = 500 + +/** + * Liste des épisodes, saison par saison (façon plateforme de streaming). + * Toucher un épisode le marque comme vu, ainsi que tous ceux d'avant ; retoucher le dernier vu l'annule. + */ +export default function EpisodeList({ form, onChange }: Props) { + const { settings } = useMedia() + const seasons = form.seasons + const pos = seasonPosition(form) + const [viewSeason, setViewSeason] = useState(pos?.season ?? 1) + const [episodes, setEpisodes] = useState() + const [loading, setLoading] = useState(false) + const listRef = useRef(null) + const today = todayISO() + const key = settings.tmdbKey?.trim() + const isTmdb = !!form.externalId?.startsWith('tmdb:tv:') && !!key + + // Taille de la saison affichée (ou de toute la série si on ne connaît pas le découpage) + const before = seasons ? episodesBeforeSeason(seasons, viewSeason) : 0 + const size = seasons ? seasons[viewSeason - 1] : Math.min(episodeCap(form) ?? 0, MAX_GENERIC) + + useEffect(() => { + if (!isTmdb || !navigator.onLine) return setEpisodes(undefined) + let alive = true + setLoading(true) + getTmdbSeasonEpisodes(form.externalId!, seasons ? viewSeason : 1, key!) + .then((list) => alive && setEpisodes(list.length ? list : undefined)) + .catch(() => alive && setEpisodes(undefined)) + .finally(() => alive && setLoading(false)) + return () => { + alive = false + } + }, [isTmdb, form.externalId, viewSeason, seasons, key]) + + // Les infos TMDB complètent la liste ; sans elles (AniList, hors-ligne), on numérote simplement + const count = Math.max(size, seasons ? 0 : (episodes?.length ?? 0)) + const rows: EpisodeInfo[] = Array.from({ length: count }, (_, k) => episodes?.find((e) => e.number === k + 1) ?? { number: k + 1 }) + const watchedHere = Math.max(0, Math.min(count, form.episodesWatched - before)) + + // Ouvre la liste au niveau du prochain épisode à voir + useLayoutEffect(() => { + const el = listRef.current?.querySelector(`[data-ep="${Math.min(count, watchedHere + 1)}"]`) + if (el && listRef.current) listRef.current.scrollTop = Math.max(0, el.offsetTop - listRef.current.offsetTop - 8) + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [viewSeason, count, episodes]) + + const toggle = (n: number) => { + const target = before + n + // Retoucher le dernier épisode vu = l'annuler + const next = form.episodesWatched === target ? target - 1 : target + onChange(Math.max(0, next), seasons ? viewSeason : undefined) + } + + const fmtDate = (d: string) => new Date(`${d}T12:00:00`).toLocaleDateString(locale(), { day: 'numeric', month: 'short', year: d.slice(0, 4) === today.slice(0, 4) ? undefined : 'numeric' }) + + if (!count) return null + + return ( +
+
+ {seasons ? ( + + ) : ( + {t('form.episodes')} + )} + + {loading && } + {t('episodes.seen', { done: watchedHere, total: count })} + +
+ +
+ {rows.map((e) => { + const seen = e.number <= watchedHere + const upcoming = !!e.date && e.date > today + return ( + + ) + })} +
+
+ ) +} diff --git a/src/components/HomeHero.tsx b/src/components/HomeHero.tsx new file mode 100644 index 0000000..db1f42a --- /dev/null +++ b/src/components/HomeHero.tsx @@ -0,0 +1,94 @@ +import { Check, Info, Plus } from 'lucide-react' +import { t } from '../i18n' +import { TYPE_BY_VALUE } from '../lib/constants' +import { episodeCap, seasonPosition } from '../lib/franchise' +import { genreLabel } from '../lib/genres' +import { useMedia } from '../store' +import type { MediaItem } from '../types' + +/** Où j'en suis : « S2 · É3 » (épisode suivant à voir) */ +export function nextEpisodeLabel(item: MediaItem): string | undefined { + if (!TYPE_BY_VALUE[item.type].episodic) return undefined + const cap = episodeCap(item) + if (cap && item.episodesWatched >= cap) return undefined + const pos = seasonPosition({ ...item, episodesWatched: item.episodesWatched + 1, season: undefined }) + const ep = t('episodes.short', { n: pos ? pos.episode : item.episodesWatched + 1 }) + return pos ? `S${pos.season} · ${ep}` : ep +} + +/** Grande bannière de l'accueil : le titre que je regarde en ce moment (ou le prochain à voir). */ +export default function HomeHero({ item, onOpen }: { item: MediaItem; onOpen: (item: MediaItem) => void }) { + const { incrementEpisode } = useMedia() + const image = item.backdrop ?? item.poster + const next = nextEpisodeLabel(item) + const episodic = TYPE_BY_VALUE[item.type].episodic + const meta = [TYPE_BY_VALUE[item.type].label, item.year, ...item.genres.slice(0, 2).map(genreLabel)].filter(Boolean).join(' · ') + + return ( +
+ +
+

{item.status === 'en_cours' ? t('homeHero.continue') : t('homeHero.next')}

+

{item.title}

+ {meta &&

{meta}

} +
+ {episodic && next ? ( + + ) : episodic ? ( + + {t('hero.allSeen')} + + ) : null} + +
+
+
+ ) +} + +/** Carte horizontale « Reprendre » : image, barre de progression, prochain épisode. */ +export function ContinueCard({ item, onOpen }: { item: MediaItem; onOpen: (item: MediaItem) => void }) { + const { incrementEpisode } = useMedia() + const image = item.backdrop ?? item.poster + const pos = seasonPosition(item) + const cap = episodeCap(item) + const done = pos ? pos.episode : item.episodesWatched + const size = pos ? pos.size : cap + const pct = size ? Math.min(100, (done / size) * 100) : 0 + const next = nextEpisodeLabel(item) + + return ( +
+
+ + {next && ( + + )} +
+ +
+ ) +} diff --git a/src/components/ItemHero.tsx b/src/components/ItemHero.tsx new file mode 100644 index 0000000..f7b6311 --- /dev/null +++ b/src/components/ItemHero.tsx @@ -0,0 +1,91 @@ +import { Check, Pencil, Star } from 'lucide-react' +import { useState } from 'react' +import { t } from '../i18n' +import { genreLabel } from '../lib/genres' +import { formatRating } from '../lib/utils' +import { useMedia } from '../store' +import type { MediaInput } from '../types' +import Poster from './Poster' + +export interface HeroAction { + label: string + onClick?: () => void + /** Déjà fait (tout vu) : bouton affiché comme validé */ + done?: boolean +} + +interface Props { + form: MediaInput + typeLabel: string + editing: boolean + onEdit: () => void + primary: HeroAction +} + +/** En-tête d'une fiche, façon plateforme de streaming : grande image, titre, infos et action principale. */ +export default function ItemHero({ form, typeLabel, editing, onEdit, primary }: Props) { + const { settings } = useMedia() + const [moreText, setMoreText] = useState(false) + const image = form.backdrop ?? form.poster + const meta = [typeLabel, form.year, ...form.genres.slice(0, 3).map(genreLabel)].filter(Boolean).join(' · ') + + return ( +
+
+ {image && } +
+
+ +
+
+ +
+
+

{form.title}

+ {form.originalTitle &&

{form.originalTitle}

} +
+
+ +
+
+ {meta && {meta}} + {form.publicRating != null && ( + + + {formatRating(form.publicRating, settings.ratingScale)} + + )} +
+ +
+ + +
+ + {form.overview && ( + + )} +
+
+ ) +} diff --git a/src/components/MediaCard.tsx b/src/components/MediaCard.tsx index cc01140..782b701 100644 --- a/src/components/MediaCard.tsx +++ b/src/components/MediaCard.tsx @@ -1,7 +1,7 @@ import { t } from '../i18n' import { Heart, Plus } from 'lucide-react' import { TYPE_BY_VALUE } from '../lib/constants' -import { seasonPosition } from '../lib/franchise' +import { episodeCap, seasonPosition } from '../lib/franchise' import { useMedia } from '../store' import type { MediaItem } from '../types' import { StatusPill, TypeBadge } from './Badges' @@ -39,7 +39,7 @@ export function MediaCard({ item, onOpen }: { item: MediaItem; onOpen: (item: Me const canIncrement = TYPE_BY_VALUE[item.type].episodic && item.status === 'en_cours' && - (!item.episodesTotal || item.episodesWatched < item.episodesTotal) + (!episodeCap(item) || item.episodesWatched < episodeCap(item)!) return (
@@ -77,7 +77,7 @@ export function MediaCard({ item, onOpen }: { item: MediaItem; onOpen: (item: Me export function MediaRow({ item, onOpen }: { item: MediaItem; onOpen: (item: MediaItem) => void }) { const { settings, incrementEpisode } = useMedia() const episodic = TYPE_BY_VALUE[item.type].episodic - const done = !!item.episodesTotal && item.episodesWatched >= item.episodesTotal + const done = !!episodeCap(item) && item.episodesWatched >= episodeCap(item)! return (
diff --git a/src/components/MediaForm.tsx b/src/components/MediaForm.tsx index a315053..26a13b2 100644 --- a/src/components/MediaForm.tsx +++ b/src/components/MediaForm.tsx @@ -1,11 +1,11 @@ import { locale, t } from '../i18n' -import { Check, ChevronDown, Heart, ImagePlus, Loader2, Minus, Plus, Share2, Trash2, X } from 'lucide-react' +import { Check, Heart, ImagePlus, Loader2, Minus, Plus, Share2, Trash2, X } from 'lucide-react' import { useEffect, useMemo, useRef, useState, type ReactNode } from 'react' -import { CRITERIA, DEFAULT_FILM_MINUTES, MEDIA_TYPES, platformSuggestions as defaultPlatforms, STATUSES, TYPE_BY_VALUE } from '../lib/constants' +import { CRITERIA, DEFAULT_FILM_MINUTES, MEDIA_TYPES, STATUSES, TYPE_BY_VALUE } from '../lib/constants' import { canonicalGenre, canonicalSubtype, genreLabel, genreSuggestions as defaultGenres, subtypeLabel, subtypeSuggestions } from '../lib/genres' import { fileToPosterDataURL } from '../lib/image' -import { getTmdbCredits, getTmdbSeasons } from '../lib/catalogApi' -import { episodesBeforeSeason, seasonPosition } from '../lib/franchise' +import { getTmdbCredits, getTmdbExtras } from '../lib/catalogApi' +import { episodeCap, seasonPosition } from '../lib/franchise' import { renderItemCard, slug } from '../lib/shareCard' import { useScrollLock } from '../lib/scrollLock' import { cx, formatRating, todayISO } from '../lib/utils' @@ -15,6 +15,8 @@ import { StatusDot } from './Badges' import ConfirmDialog from './ConfirmDialog' import SharePreview from './SharePreview' import DatabaseSearch from './DatabaseSearch' +import EpisodeList from './EpisodeList' +import ItemHero, { type HeroAction } from './ItemHero' import { NewListForm } from './ListsView' import Poster from './Poster' import { RatingInput } from './Rating' @@ -42,6 +44,7 @@ const METADATA_KEYS = [ 'seasons', 'episodeDuration', 'poster', + 'backdrop', 'externalId', 'countries', 'publicRating', @@ -76,37 +79,6 @@ interface Props { onOpenItem?: (item: MediaItem) => void } -/** Choix de la saison : « S2 » = la saison 1 est vue, on commence la 2. */ -function SeasonPicker({ seasons, watched, season, onChange }: { seasons: number[]; watched: number; season?: number; onChange: (episodesWatched: number, season: number) => void }) { - const current = seasonPosition({ episodesWatched: watched, seasons, season })! - return ( -
- {t('form.season')} -
- {seasons.map((size, k) => { - const n = k + 1 - const start = episodesBeforeSeason(seasons, n) - const done = watched >= start + size - const on = n === current.season - return ( - - ) - })} -
-
- ) -} - /** « Moi vs le public » : ma note comparée à la moyenne TMDB / AniList. */ function PublicCompare({ mine, pub, scale, source }: { mine?: number; pub: number; scale: RatingScale; source: string }) { const gap = mine != null ? mine - pub : undefined @@ -163,7 +135,7 @@ function Rewatches({ dates, onChange }: { dates: string[]; onChange: (d: string[ } export default function MediaForm({ item, onClose, onGoToSettings, onOpenItem }: Props) { - const { add, update, remove, items, settings, lists } = useMedia() + const { add, update, remove, items, settings, lists, patchMany } = useMedia() const [form, setForm] = useState(() => { if (!item) return EMPTY const { id: _id, createdAt: _c, updatedAt: _u, ...rest } = item @@ -175,23 +147,30 @@ export default function MediaForm({ item, onClose, onGoToSettings, onOpenItem }: const [filledFrom, setFilledFrom] = useState() const [posterError, setPosterError] = useState() const fileRef = useRef(null) - const [showInfo, setShowInfo] = useState(false) const typeInfo = TYPE_BY_VALUE[form.type] - const pos = typeInfo.episodic ? seasonPosition(form) : undefined // Bloque le défilement de la page derrière la feuille useScrollLock() - // Série TMDB ajoutée avant le suivi par saison : on récupère le découpage en arrière-plan + // Fiche TMDB ajoutée avant ces nouveautés : grande image et saisons récupérées en arrière-plan (et gardées) const extId = form.externalId useEffect(() => { const key = settings.tmdbKey?.trim() - if (!extId?.startsWith('tmdb:tv:') || form.seasons || !key || !navigator.onLine) return + const isTv = extId?.startsWith('tmdb:tv:') + if (!extId?.startsWith('tmdb:') || !key || !navigator.onLine || (form.backdrop && (!isTv || form.seasons))) return let alive = true - getTmdbSeasons(extId, key) - .then(({ seasons, total }) => { - if (!alive || !seasons) return - setForm((f) => (f.externalId === extId && !f.seasons ? { ...f, seasons, episodesTotal: Math.max(f.episodesTotal ?? 0, total ?? 0) || f.episodesTotal } : f)) + getTmdbExtras(extId, key) + .then(({ seasons, total, backdrop }) => { + if (!alive) return + const patch: Partial = {} + if (backdrop && !form.backdrop) patch.backdrop = backdrop + if (seasons && !form.seasons) { + patch.seasons = seasons + if ((total ?? 0) > (form.episodesTotal ?? 0)) patch.episodesTotal = total + } + if (!Object.keys(patch).length) return + setForm((f) => (f.externalId === extId ? { ...f, ...patch } : f)) + if (item && item.externalId === extId) void patchMany([{ id: item.id, patch }]) }) .catch(() => {}) return () => { @@ -200,14 +179,47 @@ export default function MediaForm({ item, onClose, onGoToSettings, onOpenItem }: // eslint-disable-next-line react-hooks/exhaustive-deps }, [extId]) + const [editInfo, setEditInfo] = useState(false) + /** En-tête façon plateforme : dès qu'un titre est lié à TMDB / AniList, ou pour une fiche existante */ + const hasHero = !!form.title.trim() && (!!form.externalId || !!item) + + /** Nouveaux épisodes vus : le statut et les dates suivent. */ + const withEpisodes = (f: MediaInput, n: number, season?: number): MediaInput => { + const cap = episodeCap(f) + const watched = Math.max(0, cap ? Math.min(n, cap) : n) + const next: MediaInput = { ...f, episodesWatched: watched, season: f.seasons ? season ?? seasonPosition({ ...f, episodesWatched: watched, season: undefined })?.season : f.season } + if (watched > 0 && (f.status === 'a_voir' || f.status === 'pause')) { + next.status = 'en_cours' + next.startDate = f.startDate ?? todayISO() + } + if (cap && watched >= cap) { + next.status = 'termine' + next.endDate = f.endDate ?? todayISO() + } else if (f.status === 'termine' && watched < (f.episodesWatched ?? 0)) { + next.status = 'en_cours' + next.endDate = undefined + } + return next + } + + /** Bouton principal de l'en-tête : épisode suivant (séries) ou « vu » (films). */ + const primary: HeroAction = (() => { + if (typeInfo.episodic) { + const cap = episodeCap(form) + if (cap && form.episodesWatched >= cap) return { label: t('hero.allSeen'), done: true } + const nextPos = seasonPosition({ ...form, episodesWatched: form.episodesWatched + 1, season: undefined }) + const ep = t('episodes.short', { n: nextPos ? nextPos.episode : form.episodesWatched + 1 }) + const label = t('hero.seenEp', { ep: nextPos ? `S${nextPos.season} · ${ep}` : ep }) + return { label, onClick: () => setForm((f) => withEpisodes(f, f.episodesWatched + 1)) } + } + if (form.status === 'termine') return { label: t('hero.seen'), done: true } + return { label: t('hero.markSeen'), onClick: () => setStatus('termine') } + })() + const set = (key: K, value: MediaInput[K]) => setForm((f) => ({ ...f, [key]: value })) // Suggestions = listes par défaut + ce que j'ai déjà utilisé const genreSuggestions = useMemo(() => [...new Set([...items.flatMap((i) => i.genres.map(genreLabel)), ...defaultGenres()])], [items]) - const platformSuggestions = useMemo( - () => [...new Set([...items.map((i) => i.platform).filter(Boolean), ...defaultPlatforms()])] as string[], - [items], - ) /** Applique les infos trouvées en ligne sans écraser mon suivi (statut, note, épisodes vus, avis…). */ const applyMetadata = (data: Partial) => { @@ -218,10 +230,12 @@ export default function MediaForm({ item, onClose, onGoToSettings, onOpenItem }: } // Découpage par saison : celui de la nouvelle source (ou aucun) next.seasons = data.seasons + next.backdrop = data.backdrop if (data.type && data.type !== 'autre') next.subtype = undefined if (data.genres?.length) next.genres = [...new Set([...f.genres, ...data.genres])] if (data.platform && !f.platform) next.platform = data.platform - if (next.episodesTotal && next.episodesWatched > next.episodesTotal) next.episodesWatched = next.episodesTotal + const cap = episodeCap(next) + if (cap && next.episodesWatched > cap) next.episodesWatched = cap return next }) setFilledFrom(data.externalId?.startsWith('anilist') ? 'AniList' : 'TMDB') @@ -239,7 +253,8 @@ export default function MediaForm({ item, onClose, onGoToSettings, onOpenItem }: if (status === 'en_cours' && !f.startDate) next.startDate = todayISO() if (status === 'termine') { if (!f.endDate) next.endDate = todayISO() - if (f.episodesTotal && TYPE_BY_VALUE[f.type].episodic) next.episodesWatched = f.episodesTotal + const cap = episodeCap(f) + if (cap && TYPE_BY_VALUE[f.type].episodic) next.episodesWatched = cap } return next }) @@ -247,7 +262,8 @@ export default function MediaForm({ item, onClose, onGoToSettings, onOpenItem }: const changeEpisodes = (delta: number) => setForm((f) => { let n = Math.max(0, f.episodesWatched + delta) - if (f.episodesTotal) n = Math.min(n, f.episodesTotal) + const cap = episodeCap(f) + if (cap) n = Math.min(n, cap) return { ...f, episodesWatched: n } }) @@ -335,9 +351,18 @@ export default function MediaForm({ item, onClose, onGoToSettings, onOpenItem }: void submit() }} > + {hasHero && ( + setEditInfo((v) => !v)} + primary={primary} + /> + )}
{/* Recherche en ligne */} - {showSearch ? ( + {(!hasHero || editInfo || showSearch) && (showSearch ? ( → - )} + ))} - {/* Affiche + titres */} + {/* Affiche + titres (modifiables) */} + {(!hasHero || editInfo) && ( + <>
- {form.overview && ( + {form.overview && !hasHero && (
{t('form.synopsis')}

{form.overview}

)} + + )} - {/* Type */} -
-
- {MEDIA_TYPES.map((mt) => ( - - ))} -
- {form.type === 'autre' && ( - - set('subtype', e.target.value)} placeholder={t('form.subtypePh')} /> - - {subtypeSuggestions().map((s) => ( - + {/* Année, dates de visionnage, genres */} +
+
+ + set('startDate', e.target.value || undefined)} /> - )} -
+ + set('endDate', e.target.value || undefined)} /> + +
+
+ + set('year', toNum(e.target.value))} placeholder="2024" /> + +
+ {t('form.genres')} + set('genres', g)} + suggestions={genreSuggestions} + placeholder={t('form.genresPh')} + display={genreLabel} + normalize={canonicalGenre} + /> +
+
+ {/* Statut */}
@@ -429,6 +465,44 @@ export default function MediaForm({ item, onClose, onGoToSettings, onOpenItem }:
+ {/* Épisodes / durée */} + {typeInfo.episodic ? ( +
+ {form.seasons || form.episodesTotal ? ( + setForm((f) => withEpisodes(f, n, season))} /> + ) : ( +
+
+ {t('home.episodesSeen')} +
+ + {form.episodesWatched} + +
+
+
+ + set('episodesTotal', toNum(e.target.value))} placeholder="?" /> + + + set('season', toNum(e.target.value))} placeholder="1" /> + +
+
+ )} +
+ ) : ( +
+ + set('duration', toNum(e.target.value))} placeholder={String(DEFAULT_FILM_MINUTES)} /> + +
+ )} + {/* Note */}
@@ -465,114 +539,33 @@ export default function MediaForm({ item, onClose, onGoToSettings, onOpenItem }:
- {/* Épisodes / durée */} - {typeInfo.episodic ? ( -
-
- {pos && form.seasons ? ( - setForm((f) => ({ ...f, episodesWatched: n, season }))} /> - ) : null} -
- {pos ? t('form.episodesOfSeason', { season: pos.season }) : t('home.episodesSeen')} -
- - - {pos ? pos.episode : form.episodesWatched} - {pos ? /{pos.size} : form.episodesTotal ? /{form.episodesTotal} : null} - - -
-
- {pos ? ( -
-

{t('form.seasonsTotal', { seasons: form.seasons!.length, count: form.episodesTotal ?? 0 })}

-
- - set('episodeDuration', toNum(e.target.value))} placeholder={String(typeInfo.episodeMinutes)} /> - -
-
- ) : ( -
- - set('episodesTotal', toNum(e.target.value))} placeholder="?" /> - - - set('season', toNum(e.target.value))} placeholder="1" /> - - - set('episodeDuration', toNum(e.target.value))} placeholder={String(typeInfo.episodeMinutes)} /> - -
- )} -
-
- ) : ( -
- - set('duration', toNum(e.target.value))} placeholder={String(DEFAULT_FILM_MINUTES)} /> - -
- )} - - {/* Infos : repliées par défaut (dates remplies selon le statut, année et genres par la recherche) */} - - {showInfo && ( -
-
- - set('startDate', e.target.value || undefined)} /> - - - set('endDate', e.target.value || undefined)} /> - - - set('year', toNum(e.target.value))} placeholder="2024" /> - - - set('platform', e.target.value)} placeholder="Netflix…" /> - - {platformSuggestions.map((p) => ( - - -
-
- {t('form.genres')} - set('genres', g)} - suggestions={genreSuggestions} - placeholder={t('form.genresPh')} - display={genreLabel} - normalize={canonicalGenre} - /> -
-
- )} - {(form.status === 'termine' || (form.rewatchDates?.length ?? 0) > 0) && (
set('rewatchDates', d.length ? d : undefined)} />
)} + {/* Type */} +
+
+ {MEDIA_TYPES.map((mt) => ( + + ))} +
+ {form.type === 'autre' && ( + + set('subtype', e.target.value)} placeholder={t('form.subtypePh')} /> + + {subtypeSuggestions().map((s) => ( + + + )} +
+
{lists.length > 0 && (
diff --git a/src/i18n/locales/de.ts b/src/i18n/locales/de.ts index 1b2724b..58b5e52 100644 --- a/src/i18n/locales/de.ts +++ b/src/i18n/locales/de.ts @@ -769,6 +769,26 @@ const dict: Translations = { 'form.seasonsTotal_other': "{seasons} Staffeln · insgesamt {count} Folgen", 'form.seasonEpisodes_one': "{count} Folge", 'form.seasonEpisodes_other': "{count} Folgen", + 'form.startShort': "Begonnen", + 'form.endShort': "Beendet", + 'hero.allSeen': "Alles gesehen", + 'hero.seenEp': "{ep} gesehen", + 'hero.seen': "Gesehen", + 'hero.markSeen': "Als gesehen markieren", + 'hero.edit': "Angaben bearbeiten", + 'hero.more': "Mehr lesen", + 'hero.less': "Weniger", + 'episodes.seasonOption_one': "Staffel {season} · {count} Folge", + 'episodes.seasonOption_other': "Staffel {season} · {count} Folgen", + 'episodes.seen': "{done}/{total} gesehen", + 'episodes.short': "F{n}", + 'episodes.upcoming': "am {date}", + 'episodes.nameless': "Folge {n}", + 'homeHero.continue': "Schaue ich gerade", + 'homeHero.next': "Als Nächstes", + 'homeHero.details': "Details", + 'homeHero.continueRow': "Weiterschauen", + 'homeHero.nextUp': "Als Nächstes: {ep}", } export default dict diff --git a/src/i18n/locales/en.ts b/src/i18n/locales/en.ts index d8559c9..58659bf 100644 --- a/src/i18n/locales/en.ts +++ b/src/i18n/locales/en.ts @@ -769,6 +769,26 @@ const dict: Translations = { 'form.seasonsTotal_other': "{seasons} seasons · {count} episodes in total", 'form.seasonEpisodes_one': "{count} episode", 'form.seasonEpisodes_other': "{count} episodes", + 'form.startShort': "Started", + 'form.endShort': "Finished", + 'hero.allSeen': "All watched", + 'hero.seenEp': "Watched {ep}", + 'hero.seen': "Watched", + 'hero.markSeen': "Mark as watched", + 'hero.edit': "Edit details", + 'hero.more': "Read more", + 'hero.less': "Show less", + 'episodes.seasonOption_one': "Season {season} · {count} episode", + 'episodes.seasonOption_other': "Season {season} · {count} episodes", + 'episodes.seen': "{done}/{total} watched", + 'episodes.short': "E{n}", + 'episodes.upcoming': "on {date}", + 'episodes.nameless': "Episode {n}", + 'homeHero.continue': "Currently watching", + 'homeHero.next': "Up next", + 'homeHero.details': "Details", + 'homeHero.continueRow': "Continue watching", + 'homeHero.nextUp': "Next: {ep}", } export default dict diff --git a/src/i18n/locales/es.ts b/src/i18n/locales/es.ts index fcdf385..9e570e7 100644 --- a/src/i18n/locales/es.ts +++ b/src/i18n/locales/es.ts @@ -769,6 +769,26 @@ const dict: Translations = { 'form.seasonsTotal_other': "{seasons} temporadas · {count} episodios en total", 'form.seasonEpisodes_one': "{count} episodio", 'form.seasonEpisodes_other': "{count} episodios", + 'form.startShort': "Empezado", + 'form.endShort': "Terminado", + 'hero.allSeen': "Todo visto", + 'hero.seenEp': "He visto {ep}", + 'hero.seen': "Visto", + 'hero.markSeen': "Marcar como visto", + 'hero.edit': "Editar datos", + 'hero.more': "Leer más", + 'hero.less': "Ver menos", + 'episodes.seasonOption_one': "Temporada {season} · {count} episodio", + 'episodes.seasonOption_other': "Temporada {season} · {count} episodios", + 'episodes.seen': "{done}/{total} vistos", + 'episodes.short': "E{n}", + 'episodes.upcoming': "el {date}", + 'episodes.nameless': "Episodio {n}", + 'homeHero.continue': "Estoy viendo", + 'homeHero.next': "Para ver después", + 'homeHero.details': "Ficha", + 'homeHero.continueRow': "Seguir viendo", + 'homeHero.nextUp': "Siguiente: {ep}", } export default dict diff --git a/src/i18n/locales/fr.ts b/src/i18n/locales/fr.ts index 1e5fa2f..03dbca8 100644 --- a/src/i18n/locales/fr.ts +++ b/src/i18n/locales/fr.ts @@ -771,6 +771,26 @@ const dict = { 'form.seasonsTotal_other': "{seasons} saisons · {count} épisodes au total", 'form.seasonEpisodes_one': "{count} épisode", 'form.seasonEpisodes_other': "{count} épisodes", + 'form.startShort': "Commencé le", + 'form.endShort': "Fini le", + 'hero.allSeen': "Tout vu", + 'hero.seenEp': "J'ai vu {ep}", + 'hero.seen': "Vu", + 'hero.markSeen': "Marquer comme vu", + 'hero.edit': "Modifier les infos", + 'hero.more': "Lire la suite", + 'hero.less': "Réduire", + 'episodes.seasonOption_one': "Saison {season} · {count} épisode", + 'episodes.seasonOption_other': "Saison {season} · {count} épisodes", + 'episodes.seen': "{done}/{total} vus", + 'episodes.short': "É{n}", + 'episodes.upcoming': "le {date}", + 'episodes.nameless': "Épisode {n}", + 'homeHero.continue': "Je regarde", + 'homeHero.next': "À voir ensuite", + 'homeHero.details': "Fiche", + 'homeHero.continueRow': "Reprendre", + 'homeHero.nextUp': "Prochain : {ep}", } export default dict diff --git a/src/i18n/locales/it.ts b/src/i18n/locales/it.ts index df3c547..a0fe721 100644 --- a/src/i18n/locales/it.ts +++ b/src/i18n/locales/it.ts @@ -769,6 +769,26 @@ const dict: Translations = { 'form.seasonsTotal_other': "{seasons} stagioni · {count} episodi in totale", 'form.seasonEpisodes_one': "{count} episodio", 'form.seasonEpisodes_other': "{count} episodi", + 'form.startShort': "Iniziato", + 'form.endShort': "Finito", + 'hero.allSeen': "Tutto visto", + 'hero.seenEp': "Ho visto {ep}", + 'hero.seen': "Visto", + 'hero.markSeen': "Segna come visto", + 'hero.edit': "Modifica i dati", + 'hero.more': "Leggi tutto", + 'hero.less': "Riduci", + 'episodes.seasonOption_one': "Stagione {season} · {count} episodio", + 'episodes.seasonOption_other': "Stagione {season} · {count} episodi", + 'episodes.seen': "{done}/{total} visti", + 'episodes.short': "E{n}", + 'episodes.upcoming': "il {date}", + 'episodes.nameless': "Episodio {n}", + 'homeHero.continue': "Sto guardando", + 'homeHero.next': "Da vedere", + 'homeHero.details': "Scheda", + 'homeHero.continueRow': "Riprendi", + 'homeHero.nextUp': "Prossimo: {ep}", } export default dict diff --git a/src/i18n/locales/ja.ts b/src/i18n/locales/ja.ts index b719afd..22d1f92 100644 --- a/src/i18n/locales/ja.ts +++ b/src/i18n/locales/ja.ts @@ -769,6 +769,26 @@ const dict: Translations = { 'form.seasonsTotal_other': "{seasons}シーズン・全{count}話", 'form.seasonEpisodes_one': "{count}話", 'form.seasonEpisodes_other': "{count}話", + 'form.startShort': "開始日", + 'form.endShort': "完了日", + 'hero.allSeen': "すべて視聴済み", + 'hero.seenEp': "{ep}を見た", + 'hero.seen': "視聴済み", + 'hero.markSeen': "視聴済みにする", + 'hero.edit': "情報を編集", + 'hero.more': "続きを読む", + 'hero.less': "閉じる", + 'episodes.seasonOption_one': "シーズン{season}・全{count}話", + 'episodes.seasonOption_other': "シーズン{season}・全{count}話", + 'episodes.seen': "{done}/{total}話視聴", + 'episodes.short': "第{n}話", + 'episodes.upcoming': "{date}", + 'episodes.nameless': "第{n}話", + 'homeHero.continue': "視聴中", + 'homeHero.next': "次に見る", + 'homeHero.details': "詳細", + 'homeHero.continueRow': "続きを見る", + 'homeHero.nextUp': "次:{ep}", } export default dict diff --git a/src/i18n/locales/ko.ts b/src/i18n/locales/ko.ts index e25e151..b95c005 100644 --- a/src/i18n/locales/ko.ts +++ b/src/i18n/locales/ko.ts @@ -769,6 +769,26 @@ const dict: Translations = { 'form.seasonsTotal_other': "{seasons}개 시즌 · 총 {count}화", 'form.seasonEpisodes_one': "{count}화", 'form.seasonEpisodes_other': "{count}화", + 'form.startShort': "시작일", + 'form.endShort': "완료일", + 'hero.allSeen': "모두 시청함", + 'hero.seenEp': "{ep} 봤어요", + 'hero.seen': "봤어요", + 'hero.markSeen': "본 것으로 표시", + 'hero.edit': "정보 수정", + 'hero.more': "더 보기", + 'hero.less': "접기", + 'episodes.seasonOption_one': "시즌 {season} · {count}화", + 'episodes.seasonOption_other': "시즌 {season} · {count}화", + 'episodes.seen': "{done}/{total}화 시청", + 'episodes.short': "{n}화", + 'episodes.upcoming': "{date}", + 'episodes.nameless': "{n}화", + 'homeHero.continue': "보는 중", + 'homeHero.next': "다음에 볼 작품", + 'homeHero.details': "상세", + 'homeHero.continueRow': "이어 보기", + 'homeHero.nextUp': "다음: {ep}", } export default dict diff --git a/src/i18n/locales/pt.ts b/src/i18n/locales/pt.ts index 5f1dd94..ba45c47 100644 --- a/src/i18n/locales/pt.ts +++ b/src/i18n/locales/pt.ts @@ -769,6 +769,26 @@ const dict: Translations = { 'form.seasonsTotal_other': "{seasons} temporadas · {count} episódios no total", 'form.seasonEpisodes_one': "{count} episódio", 'form.seasonEpisodes_other': "{count} episódios", + 'form.startShort': "Começou", + 'form.endShort': "Terminou", + 'hero.allSeen': "Tudo visto", + 'hero.seenEp': "Vi {ep}", + 'hero.seen': "Visto", + 'hero.markSeen': "Marcar como visto", + 'hero.edit': "Editar dados", + 'hero.more': "Ler mais", + 'hero.less': "Ver menos", + 'episodes.seasonOption_one': "Temporada {season} · {count} episódio", + 'episodes.seasonOption_other': "Temporada {season} · {count} episódios", + 'episodes.seen': "{done}/{total} vistos", + 'episodes.short': "E{n}", + 'episodes.upcoming': "em {date}", + 'episodes.nameless': "Episódio {n}", + 'homeHero.continue': "Assistindo agora", + 'homeHero.next': "Para ver depois", + 'homeHero.details': "Detalhes", + 'homeHero.continueRow': "Continuar assistindo", + 'homeHero.nextUp': "Próximo: {ep}", } export default dict diff --git a/src/i18n/locales/zh.ts b/src/i18n/locales/zh.ts index 633d238..f84a661 100644 --- a/src/i18n/locales/zh.ts +++ b/src/i18n/locales/zh.ts @@ -769,6 +769,26 @@ const dict: Translations = { 'form.seasonsTotal_other': "{seasons} 季 · 共 {count} 集", 'form.seasonEpisodes_one': "{count} 集", 'form.seasonEpisodes_other': "{count} 集", + 'form.startShort': "开始于", + 'form.endShort': "看完于", + 'hero.allSeen': "全部看完", + 'hero.seenEp': "已看 {ep}", + 'hero.seen': "已看", + 'hero.markSeen': "标记为已看", + 'hero.edit': "编辑信息", + 'hero.more': "展开", + 'hero.less': "收起", + 'episodes.seasonOption_one': "第 {season} 季 · {count} 集", + 'episodes.seasonOption_other': "第 {season} 季 · {count} 集", + 'episodes.seen': "已看 {done}/{total}", + 'episodes.short': "第{n}集", + 'episodes.upcoming': "{date}", + 'episodes.nameless': "第 {n} 集", + 'homeHero.continue': "正在看", + 'homeHero.next': "接下来看", + 'homeHero.details': "详情", + 'homeHero.continueRow': "继续观看", + 'homeHero.nextUp': "下一集:{ep}", } export default dict diff --git a/src/lib/airing.ts b/src/lib/airing.ts index 8a1521a..afae03a 100644 --- a/src/lib/airing.ts +++ b/src/lib/airing.ts @@ -3,7 +3,7 @@ import type { MediaItem } from '../types' import { CLOUD_TMDB, isPlausibleTmdbKey } from './catalogApi' import { tmdbViaCloud } from './cloud/api' import { TYPE_BY_VALUE } from './constants' -import { isPlainObject, isSafeExternalId, isSafeId, readStorage, safeDay, safeIso, safeSeasons } from './security' +import { isPlainObject, isSafeExternalId, isSafeId, isSafeTmdbPath, readStorage, remoteImage, safeDay, safeIso, safeSeasons } from './security' /** * Suivi des nouveaux épisodes. @@ -21,6 +21,8 @@ export interface AiringInfo { seasons?: number /** Épisodes de chaque saison (TMDB) */ seasonSizes?: number[] + /** Grande image (TMDB) */ + backdrop?: string checkedAt: string } @@ -30,7 +32,7 @@ const KEY = 'azuucine:airing' const RECHECK_MS = 12 * 3600 * 1000 const RECHECK_ENDED_MS = 30 * 24 * 3600 * 1000 /** Date d'arrivée du suivi par saison (les vérifications plus anciennes n'ont pas le découpage) */ -const SEASONS_SINCE = '2026-10-04T00:00:00.000Z' +const SEASONS_SINCE = '2026-10-04T10:00:00.000Z' const n0 = (v: unknown, max = 100000) => (typeof v === 'number' && Number.isFinite(v) && v >= 0 ? Math.min(max, Math.round(v)) : 0) @@ -44,7 +46,7 @@ export function loadAiring(): AiringCache { const checkedAt = safeIso(v.checkedAt) if (!checkedAt) continue const next = isPlainObject(v.next) && safeDay(v.next.date) ? { episode: n0(v.next.episode), season: n0(v.next.season) || undefined, date: v.next.date as string } : undefined - out[id] = { aired: n0(v.aired), ended: v.ended === true, seasons: n0(v.seasons) || undefined, seasonSizes: safeSeasons(v.seasonSizes), next, checkedAt } + out[id] = { aired: n0(v.aired), ended: v.ended === true, seasons: n0(v.seasons) || undefined, seasonSizes: safeSeasons(v.seasonSizes), backdrop: remoteImage(v.backdrop), next, checkedAt } } return out } @@ -76,7 +78,7 @@ export function needsCheck(item: MediaItem, cache: AiringCache, force = false): const info = cache[item.id] if (!info || force) return true // Fiche TMDB vérifiée avant le suivi par saison : on récupère le découpage une fois - if (item.externalId?.startsWith('tmdb:tv:') && !info.seasonSizes && (info.seasons ?? 0) > 1 && info.checkedAt < SEASONS_SINCE) return true + if (item.externalId?.startsWith('tmdb:tv:') && (!info.backdrop || (!info.seasonSizes && (info.seasons ?? 0) > 1)) && info.checkedAt < SEASONS_SINCE) return true const age = Date.now() - new Date(info.checkedAt).getTime() return age > (info.ended ? RECHECK_ENDED_MS : RECHECK_MS) } @@ -90,6 +92,7 @@ interface TmdbTv { last_episode_to_air?: { season_number: number; episode_number: number } | null next_episode_to_air?: { season_number: number; episode_number: number; air_date?: string } | null seasons?: { season_number: number; episode_count: number }[] + backdrop_path?: string | null } async function checkTmdb(tvId: string, key: string): Promise> { @@ -128,6 +131,7 @@ async function checkTmdb(tvId: string, key: string): Promise a.season_number - b.season_number) .map((s) => n0(s.episode_count)), ), + backdrop: isSafeTmdbPath(d.backdrop_path) ? `https://image.tmdb.org/t/p/w780${d.backdrop_path}` : undefined, ended: d.status === 'Ended' || d.status === 'Canceled', next: nx && nextDate ? { episode: n0(nx.episode_number), season: n0(nx.season_number) || undefined, date: nextDate } : undefined, } diff --git a/src/lib/backup.ts b/src/lib/backup.ts index cf56c89..cc0495b 100644 --- a/src/lib/backup.ts +++ b/src/lib/backup.ts @@ -12,6 +12,7 @@ import { safeCountries, safeDay, safeIso, + remoteImage, safePosterUrl, safeSeasons, safeStringList, @@ -104,6 +105,7 @@ export function normalizeItem(raw: unknown): MediaItem | null { notes: cleanText(r.notes, LIMITS.notes), notesPublic: r.notesPublic === true || undefined, poster: safePosterUrl(r.poster), + backdrop: remoteImage(r.backdrop), overview: cleanText(r.overview, LIMITS.overview), externalId: isSafeExternalId(r.externalId) ? r.externalId : undefined, top: normalizeTop(r.top), diff --git a/src/lib/catalogApi.ts b/src/lib/catalogApi.ts index ade69df..8ec4af7 100644 --- a/src/lib/catalogApi.ts +++ b/src/lib/catalogApi.ts @@ -4,7 +4,7 @@ import { tmdbViaCloud } from './cloud/api' import { TYPE_BY_VALUE } from './constants' import { subtypeLabel, tmdbGenres } from './genres' import { franchiseKey } from './franchise' -import { cleanText, isSafeExternalId, isSafeTmdbPath, LIMITS, safeCountries, safePosterUrl, safeSeasons, safeStringList } from './security' +import { cleanText, isSafeExternalId, isSafeTmdbPath, LIMITS, remoteImage, safeCountries, safeDay, safePosterUrl, safeSeasons, safeStringList } from './security' /** * Recherche dans les bases publiques : @@ -58,6 +58,7 @@ export function sanitizeMeta(d: Partial): Partial { externalId: isSafeExternalId(d.externalId) ? d.externalId : undefined, countries: safeCountries(d.countries), poster: safePosterUrl(d.poster), + backdrop: remoteImage(d.backdrop), publicRating: typeof d.publicRating === 'number' && d.publicRating > 0 && d.publicRating <= 10 ? Math.round(d.publicRating * 10) / 10 : undefined, } @@ -212,6 +213,7 @@ interface TmdbDetails { release_date?: string first_air_date?: string poster_path?: string | null + backdrop_path?: string | null last_episode_to_air?: { runtime?: number } | null seasons?: { season_number?: number; episode_count?: number }[] vote_average?: number @@ -287,6 +289,7 @@ export async function getTmdbDetails(result: SearchResult, key: string): Promise duration: kind === 'movie' ? d.runtime || undefined : undefined, episodesTotal: kind === 'tv' ? Math.max(d.number_of_episodes || 0, sumSeasons(tmdbSeasons(d))) || undefined : undefined, seasons: kind === 'tv' ? tmdbSeasons(d) : undefined, + backdrop: tmdbBackdrop(d.backdrop_path), episodeDuration: kind === 'tv' ? epRuntime : undefined, externalId: result.externalId, countries: d.origin_country?.length ? d.origin_country : d.production_countries?.map((c) => c.iso_3166_1).slice(0, 3), @@ -304,12 +307,53 @@ function tmdbSeasons(d: TmdbDetails): number[] | undefined { } const sumSeasons = (s?: number[]) => (s ?? []).reduce((a, b) => a + b, 0) -/** Saisons d'une série déjà dans la bibliothèque (pour les fiches ajoutées avant le suivi par saison). */ -export async function getTmdbSeasons(externalId: string, key: string): Promise<{ seasons?: number[]; total?: number }> { - if (!isSafeExternalId(externalId) || !externalId.startsWith('tmdb:tv:')) return {} - const d = await tmdbFetch(`/tv/${externalId.split(':')[2]}`, key) - const seasons = tmdbSeasons(d) - return { seasons, total: Math.max(d.number_of_episodes || 0, sumSeasons(seasons)) || undefined } +const tmdbBackdrop = (path?: string | null) => (isSafeTmdbPath(path) ? `${TMDB_IMG}/w780${path}` : undefined) + +/** Grande image et saisons d'un titre déjà dans la bibliothèque (fiches ajoutées avant ces nouveautés). */ +export async function getTmdbExtras(externalId: string, key: string): Promise<{ seasons?: number[]; total?: number; backdrop?: string }> { + if (!isSafeExternalId(externalId) || !externalId.startsWith('tmdb:')) return {} + const [, kind, id] = externalId.split(':') as ['tmdb', 'movie' | 'tv', string] + const d = await tmdbFetch(`/${kind}/${id}`, key) + const seasons = kind === 'tv' ? tmdbSeasons(d) : undefined + return { + seasons, + total: kind === 'tv' ? Math.max(d.number_of_episodes || 0, sumSeasons(seasons)) || undefined : undefined, + backdrop: tmdbBackdrop(d.backdrop_path), + } +} + +export interface EpisodeInfo { + number: number + name?: string + still?: string + date?: string + runtime?: number +} + +const seasonCache = new Map() + +/** Épisodes d'une saison (titre, image, date de diffusion). Gardés en mémoire le temps de la session. */ +export async function getTmdbSeasonEpisodes(externalId: string, season: number, key: string): Promise { + if (!isSafeExternalId(externalId) || !externalId.startsWith('tmdb:tv:') || !Number.isInteger(season) || season < 1 || season > 999) return [] + const cacheKey = `${externalId}:${season}:${tmdbLanguage()}` + const cached = seasonCache.get(cacheKey) + if (cached) return cached + const d = await tmdbFetch<{ episodes?: { episode_number?: number; name?: string; still_path?: string | null; air_date?: string; runtime?: number }[] }>( + `/tv/${externalId.split(':')[2]}/season/${season}`, + key, + ) + const list = (Array.isArray(d.episodes) ? d.episodes : []) + .filter((e) => Number.isInteger(e.episode_number) && e.episode_number! > 0) + .slice(0, 1000) + .map((e) => ({ + number: e.episode_number!, + name: cleanText(e.name, LIMITS.title), + still: isSafeTmdbPath(e.still_path) ? `${TMDB_IMG}/w300${e.still_path}` : undefined, + date: safeDay(e.air_date), + runtime: typeof e.runtime === 'number' && e.runtime > 0 && e.runtime < 1000 ? Math.round(e.runtime) : undefined, + })) + seasonCache.set(cacheKey, list) + return list } /** Vérifie qu'une clé TMDB fonctionne. */ diff --git a/src/lib/franchise.ts b/src/lib/franchise.ts index 524c59e..79f1d36 100644 --- a/src/lib/franchise.ts +++ b/src/lib/franchise.ts @@ -76,3 +76,9 @@ export function seasonPosition(item: Pick seasons.slice(0, Math.max(0, n - 1)).reduce((a, b) => a + b, 0) + +/** Nombre maximum d'épisodes : toutes les saisons connues, sinon le total enregistré. */ +export function episodeCap(item: Pick): number | undefined { + const sum = item.seasons?.reduce((a, b) => a + b, 0) ?? 0 + return Math.max(sum, item.episodesTotal ?? 0) || undefined +} diff --git a/src/lib/security.ts b/src/lib/security.ts index 03c8eb5..c8aff0a 100644 --- a/src/lib/security.ts +++ b/src/lib/security.ts @@ -132,3 +132,9 @@ export function safeSeasons(v: unknown): number[] | undefined { const out = v.slice(0, 100).map((n) => (typeof n === 'number' && Number.isInteger(n) && n > 0 && n <= 5000 ? n : 0)) return out.length > 1 && out.every((n) => n > 0) ? out : undefined } + +/** Image distante autorisée (jamais d'image intégrée : la grande image n'est qu'un décor). */ +export function remoteImage(value: unknown): string | undefined { + const url = safePosterUrl(value) + return url && !url.startsWith('data:') && url.length <= 300 ? url : undefined +} diff --git a/src/pages/HomePage.tsx b/src/pages/HomePage.tsx index 603beed..b2f7f85 100644 --- a/src/pages/HomePage.tsx +++ b/src/pages/HomePage.tsx @@ -2,12 +2,13 @@ import { useSocial } from '../components/social/SocialProvider' import { t } from '../i18n' import { CalendarDays, Dices, Plus } from 'lucide-react' import { useEffect, useMemo, useRef, useState } from 'react' -import { MediaRow } from '../components/MediaCard' +import { TYPE_BY_VALUE } from '../lib/constants' import Avatar from '../components/social/Avatar' import FriendsFeed from '../components/social/FriendsFeed' import Poster from '../components/Poster' import TopFive from '../components/TopFive' import Recommendations from '../components/Recommendations' +import HomeHero, { ContinueCard } from '../components/HomeHero' import type { Tab } from '../components/BottomNav' import { EmptyState, LinkArrow, PageHeader, SectionTitle, StatTile } from '../components/ui' import { CACHE_EVENT, loadAiring, needsCheck, refreshAiring, saveAiring, trackable } from '../lib/airing' @@ -29,9 +30,10 @@ function PosterStrip({ items, onOpen }: { items: MediaItem[]; onOpen: (item: Med return (
{items.map((item) => ( - ))}
@@ -60,6 +62,7 @@ export default function HomePage({ onOpen, onAdd, onNavigate, onRoulette, onCale if (i.status !== 'termine' && info.aired > (i.episodesTotal ?? 0)) patch.episodesTotal = info.aired // Découpage par saison (nouvelle saison annoncée, ou fiche ajoutée avant le suivi par saison) if (info.seasonSizes && info.seasonSizes.join() !== (i.seasons ?? []).join()) patch.seasons = info.seasonSizes + if (info.backdrop && !i.backdrop) patch.backdrop = info.backdrop return Object.keys(patch).length ? [{ id: i.id, patch }] : [] }) if (patches.length) return patchMany(patches) @@ -82,6 +85,8 @@ export default function HomePage({ onOpen, onAdd, onNavigate, onRoulette, onCale }, [items, cacheVersion]) const inProgress = items.filter((i) => i.status === 'en_cours') + // Bannière : ce que je regarde en ce moment (le plus récemment touché), sinon le prochain « à voir » + const featured = [...inProgress].sort((a, b) => b.updatedAt.localeCompare(a.updatedAt))[0] ?? items.find((i) => i.status === 'a_voir') const toWatch = items.filter((i) => i.status === 'a_voir').slice(0, 12) const recent = items .filter((i) => i.status === 'termine') @@ -135,15 +140,32 @@ export default function HomePage({ onOpen, onAdd, onNavigate, onRoulette, onCale ) : ( <> -
- - - - -
+ {featured && } + + {inProgress.length > 0 && ( + <> + {t('homeHero.continueRow')} +
+ {[...inProgress] + .sort((x, y) => y.updatedAt.localeCompare(x.updatedAt)) + .map((item) => ( + + ))} +
+ + )} + + {toWatch.length > 0 && ( + <> + {t('status.a_voir')} + + + )} + + {/* Roulette : pour les soirs sans idée */} - - - - {inProgress.length > 0 && ( - <> - {t('status.en_cours')} -
- {inProgress.map((item) => ( - - ))} -
- - )} - {toWatch.length > 0 && ( - <> - {t('status.a_voir')} - - - )} - {recent.length > 0 && ( <> {t('home.recentlyFinished')} )} + + {t('nav.stats')} +
+ + + + +
+ )} diff --git a/src/store.tsx b/src/store.tsx index 9f11973..f5da8c8 100644 --- a/src/store.tsx +++ b/src/store.tsx @@ -13,7 +13,7 @@ import { dbNameFor, scopedKey } from './lib/scope' import { isPlainObject, LIMITS, readStorage } from './lib/security' import { mediaDB, requestPersistentStorage } from './lib/db' import { todayISO, uid } from './lib/utils' -import { seasonPosition } from './lib/franchise' +import { episodeCap, seasonPosition } from './lib/franchise' // Clés propres à l'espace actif (compte connecté, ou appareil sans compte) const settingsKey = () => scopedKey('settings') @@ -247,7 +247,8 @@ export function MediaProvider({ children, cloudUser }: { children: ReactNode; cl const item = items.find((i) => i.id === id) if (!item) return let next = Math.max(0, item.episodesWatched + delta) - if (item.episodesTotal) next = Math.min(next, item.episodesTotal) + const cap = episodeCap(item) + if (cap) next = Math.min(next, cap) if (next === item.episodesWatched) return const patch: Partial = { episodesWatched: next } // Série en plusieurs saisons : la saison suit les épisodes vus @@ -257,7 +258,7 @@ export function MediaProvider({ children, cloudUser }: { children: ReactNode; cl patch.status = 'en_cours' if (!item.startDate) patch.startDate = todayISO() } - if (item.episodesTotal && next === item.episodesTotal && delta > 0) { + if (cap && next === cap && delta > 0) { patch.status = 'termine' if (!item.endDate) patch.endDate = todayISO() } diff --git a/src/types.ts b/src/types.ts index d944ac7..41acf66 100644 --- a/src/types.ts +++ b/src/types.ts @@ -40,6 +40,8 @@ export interface MediaItem { notesPublic?: boolean /** URL d'image ou image compressée en data URL (reste locale). */ poster?: string + /** Grande image horizontale (TMDB), pour l'en-tête de la fiche et l'accueil. */ + backdrop?: string /** Synopsis (rempli depuis TMDB / AniList). */ overview?: string /** Référence dans une base externe, ex. « tmdb:tv:1396 » ou « anilist:154587 ». */