1 parent
080279e456
commit
b15207aa88
22 files changed
+800
-222
No files matched your search
@@ -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<MediaInput, 'externalId' | 'episodesWatched' | 'episodesTotal' | 'seasons' | 'season'>
|
||||
/** 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<EpisodeInfo[]>()
|
||||
const [loading, setLoading] = useState(false)
|
||||
const listRef = useRef<HTMLDivElement>(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<HTMLElement>(`[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 (
|
||||
<div>
|
||||
<div className="mb-3 flex items-center justify-between gap-3">
|
||||
{seasons ? (
|
||||
<select
|
||||
value={viewSeason}
|
||||
onChange={(e) => setViewSeason(Number(e.target.value))}
|
||||
className="field w-auto py-2 pr-9 text-sm font-semibold"
|
||||
aria-label={t('form.season')}
|
||||
>
|
||||
{seasons.map((n, k) => (
|
||||
<option key={k} value={k + 1}>
|
||||
{t('episodes.seasonOption', { season: k + 1, count: n })}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
) : (
|
||||
<span className="eyebrow">{t('form.episodes')}</span>
|
||||
)}
|
||||
<span className="flex items-center gap-2 text-xs text-ink-3">
|
||||
{loading && <Loader2 size={13} className="animate-spin" />}
|
||||
{t('episodes.seen', { done: watchedHere, total: count })}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div ref={listRef} className="max-h-[26rem] space-y-1 overflow-y-auto overscroll-contain pr-1">
|
||||
{rows.map((e) => {
|
||||
const seen = e.number <= watchedHere
|
||||
const upcoming = !!e.date && e.date > today
|
||||
return (
|
||||
<button
|
||||
key={e.number}
|
||||
type="button"
|
||||
data-ep={e.number}
|
||||
onClick={() => toggle(e.number)}
|
||||
aria-pressed={seen}
|
||||
className={cx('flex w-full items-center gap-3 rounded-xl p-1.5 text-left transition-colors active:bg-surface-2', upcoming && 'opacity-50')}
|
||||
>
|
||||
<span className="relative aspect-video w-28 shrink-0 overflow-hidden rounded-lg border border-line bg-surface-2">
|
||||
{e.still ? (
|
||||
<img src={e.still} alt="" loading="lazy" className="size-full object-cover" />
|
||||
) : (
|
||||
<span className="grid size-full place-items-center text-sm font-semibold text-ink-3">{e.number}</span>
|
||||
)}
|
||||
{seen && <span className="absolute inset-x-0 bottom-0 h-[3px] bg-accent" />}
|
||||
</span>
|
||||
<span className="min-w-0 flex-1">
|
||||
<span className="block text-[11px] font-medium uppercase tracking-wide text-ink-3">
|
||||
{t('episodes.short', { n: e.number })}
|
||||
{e.date && ` · ${upcoming ? t('episodes.upcoming', { date: fmtDate(e.date) }) : fmtDate(e.date)}`}
|
||||
</span>
|
||||
<span className={cx('mt-0.5 line-clamp-2 text-sm leading-snug', seen ? 'text-ink-3' : 'text-ink')}>
|
||||
{e.name && !/^(episode|épisode|episodio|folge|第)\s*\d+/i.test(e.name) ? e.name : t('episodes.nameless', { n: e.number })}
|
||||
</span>
|
||||
</span>
|
||||
<span
|
||||
className={cx(
|
||||
'grid size-7 shrink-0 place-items-center rounded-full border transition-colors',
|
||||
seen ? 'border-accent bg-accent-fill text-on-accent' : 'border-line-strong text-transparent',
|
||||
)}
|
||||
>
|
||||
<Check size={14} strokeWidth={3} />
|
||||
</span>
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -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 (
|
||||
<section className="relative -mx-4 overflow-hidden sm:mx-0 sm:rounded-3xl">
|
||||
<button onClick={() => onOpen(item)} className="relative block aspect-[4/3] w-full bg-surface-2 sm:aspect-video" aria-label={t('card.open', { title: item.title })}>
|
||||
{image && <img src={image} alt="" className={item.backdrop ? 'size-full object-cover' : 'size-full scale-110 object-cover blur-md'} />}
|
||||
<span className="absolute inset-0 bg-bg/50" />
|
||||
</button>
|
||||
<div className="pointer-events-none absolute inset-x-0 bottom-0 p-5">
|
||||
<p className="eyebrow text-ink-2">{item.status === 'en_cours' ? t('homeHero.continue') : t('homeHero.next')}</p>
|
||||
<h2 className="mt-1.5 line-clamp-2 text-[1.9rem] font-bold leading-[1.1]">{item.title}</h2>
|
||||
{meta && <p className="mt-1.5 text-xs text-ink-2">{meta}</p>}
|
||||
<div className="pointer-events-auto mt-4 flex gap-2">
|
||||
{episodic && next ? (
|
||||
<button onClick={() => incrementEpisode(item.id)} className="btn btn-primary px-5">
|
||||
<Plus size={17} strokeWidth={2.5} /> {t('hero.seenEp', { ep: next })}
|
||||
</button>
|
||||
) : episodic ? (
|
||||
<span className="btn btn-ghost px-5">
|
||||
<Check size={17} /> {t('hero.allSeen')}
|
||||
</span>
|
||||
) : null}
|
||||
<button onClick={() => onOpen(item)} className="btn btn-ghost bg-bg/60 px-4">
|
||||
<Info size={17} /> {t('homeHero.details')}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
/** 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 (
|
||||
<article className="w-60 shrink-0">
|
||||
<div className="relative">
|
||||
<button onClick={() => onOpen(item)} className="relative block aspect-video w-full overflow-hidden rounded-xl border border-line bg-surface-2" aria-label={t('card.open', { title: item.title })}>
|
||||
{image && <img src={image} alt="" loading="lazy" className="size-full object-cover" />}
|
||||
{size ? (
|
||||
<span className="absolute inset-x-0 bottom-0 h-1 bg-bg/70">
|
||||
<span className="block h-full bg-accent" style={{ width: `${pct}%` }} />
|
||||
</span>
|
||||
) : null}
|
||||
</button>
|
||||
{next && (
|
||||
<button
|
||||
onClick={() => incrementEpisode(item.id)}
|
||||
className="absolute bottom-3 right-2 flex h-8 items-center gap-0.5 rounded-full bg-accent-fill px-3 text-xs font-semibold text-on-accent transition active:scale-90"
|
||||
aria-label={t('card.plusOne', { title: item.title })}
|
||||
>
|
||||
<Plus size={13} strokeWidth={2.5} />1
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
<button onClick={() => onOpen(item)} className="mt-2 block w-full text-left">
|
||||
<span className="block truncate text-sm font-semibold">{item.title}</span>
|
||||
<span className="block text-xs text-ink-3">{next ? t('homeHero.nextUp', { ep: next }) : t('hero.allSeen')}</span>
|
||||
</button>
|
||||
</article>
|
||||
)
|
||||
}
|
||||
@@ -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 (
|
||||
<section>
|
||||
<div className="relative h-56 overflow-hidden bg-surface-2 sm:h-72">
|
||||
{image && <img src={image} alt="" className={form.backdrop ? 'size-full object-cover' : 'size-full scale-110 object-cover blur-md'} />}
|
||||
<div className="absolute inset-0 bg-bg/55" />
|
||||
</div>
|
||||
|
||||
<div className="relative mx-auto -mt-24 flex max-w-2xl items-end gap-4 px-4">
|
||||
<div className="w-24 shrink-0 sm:w-28">
|
||||
<Poster src={form.poster} title={form.title} />
|
||||
</div>
|
||||
<div className="min-w-0 flex-1 pb-1">
|
||||
<h1 className="line-clamp-3 text-2xl font-bold leading-tight">{form.title}</h1>
|
||||
{form.originalTitle && <p className="mt-0.5 truncate text-sm text-ink-3">{form.originalTitle}</p>}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="mx-auto mt-4 max-w-2xl px-4">
|
||||
<div className="flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-ink-2">
|
||||
{meta && <span>{meta}</span>}
|
||||
{form.publicRating != null && (
|
||||
<span className="flex items-center gap-1 font-semibold text-ink">
|
||||
<Star size={12} className="fill-accent text-accent" />
|
||||
{formatRating(form.publicRating, settings.ratingScale)}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="mt-4 flex gap-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={primary.onClick}
|
||||
disabled={!primary.onClick}
|
||||
className={primary.done ? 'btn btn-ghost flex-1 py-3' : 'btn btn-primary flex-1 py-3'}
|
||||
>
|
||||
{primary.done && <Check size={17} />}
|
||||
{primary.label}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onEdit}
|
||||
aria-pressed={editing}
|
||||
className={editing ? 'btn btn-light px-4' : 'btn btn-ghost px-4'}
|
||||
aria-label={t('hero.edit')}
|
||||
title={t('hero.edit')}
|
||||
>
|
||||
<Pencil size={17} />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{form.overview && (
|
||||
<button type="button" onClick={() => setMoreText((v) => !v)} className="mt-4 block text-left text-sm leading-relaxed text-ink-2">
|
||||
<span className={moreText ? 'whitespace-pre-line' : 'line-clamp-3'}>{form.overview}</span>
|
||||
{form.overview.length > 160 && <span className="mt-1 block text-xs font-medium text-ink">{moreText ? t('hero.less') : t('hero.more')}</span>}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
@@ -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 (
|
||||
<article>
|
||||
@@ -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 (
|
||||
<article className="card flex items-center gap-3.5 p-3">
|
||||
|
||||
+170
-177
@@ -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 (
|
||||
<div>
|
||||
<span className="label">{t('form.season')}</span>
|
||||
<div className="no-scrollbar -mx-1 flex gap-1.5 overflow-x-auto px-1 pb-1">
|
||||
{seasons.map((size, k) => {
|
||||
const n = k + 1
|
||||
const start = episodesBeforeSeason(seasons, n)
|
||||
const done = watched >= start + size
|
||||
const on = n === current.season
|
||||
return (
|
||||
<button
|
||||
key={n}
|
||||
type="button"
|
||||
onClick={() => !on && (n < current.season ? onChange(start + size, n) : onChange(start, n))}
|
||||
className={cx('chip shrink-0', on && 'chip-on')}
|
||||
aria-pressed={on}
|
||||
title={t('form.seasonEpisodes', { count: size })}
|
||||
>
|
||||
{done && !on && <Check size={13} />}
|
||||
S{n}
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/** « 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<MediaInput>(() => {
|
||||
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<string>()
|
||||
const [posterError, setPosterError] = useState<string>()
|
||||
const fileRef = useRef<HTMLInputElement>(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<MediaInput> = {}
|
||||
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 = <K extends keyof MediaInput>(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<MediaInput>) => {
|
||||
@@ -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 && (
|
||||
<ItemHero
|
||||
form={form}
|
||||
typeLabel={form.type === 'autre' && form.subtype ? subtypeLabel(form.subtype) : typeInfo.label}
|
||||
editing={editInfo}
|
||||
onEdit={() => setEditInfo((v) => !v)}
|
||||
primary={primary}
|
||||
/>
|
||||
)}
|
||||
<div className="safe-bottom mx-auto max-w-2xl space-y-9 px-4 py-6 pb-16">
|
||||
{/* Recherche en ligne */}
|
||||
{showSearch ? (
|
||||
{(!hasHero || editInfo || showSearch) && (showSearch ? (
|
||||
<DatabaseSearch
|
||||
onPick={applyMetadata}
|
||||
initialQuery={item ? form.title : ''}
|
||||
@@ -362,9 +387,11 @@ export default function MediaForm({ item, onClose, onGoToSettings, onOpenItem }:
|
||||
</span>
|
||||
<span className="text-accent">→</span>
|
||||
</button>
|
||||
)}
|
||||
))}
|
||||
|
||||
{/* Affiche + titres */}
|
||||
{/* Affiche + titres (modifiables) */}
|
||||
{(!hasHero || editInfo) && (
|
||||
<>
|
||||
<div className="flex gap-4">
|
||||
<div className="w-28 shrink-0">
|
||||
<button type="button" onClick={() => fileRef.current?.click()} className="relative block w-full" aria-label={t('form.pickPoster')}>
|
||||
@@ -389,33 +416,42 @@ export default function MediaForm({ item, onClose, onGoToSettings, onOpenItem }:
|
||||
</Field>
|
||||
</div>
|
||||
</div>
|
||||
{form.overview && (
|
||||
{form.overview && !hasHero && (
|
||||
<details className="-mt-3 text-sm text-ink-2">
|
||||
<summary className="eyebrow cursor-pointer select-none">{t('form.synopsis')}</summary>
|
||||
<p className="mt-2 whitespace-pre-line leading-relaxed">{form.overview}</p>
|
||||
</details>
|
||||
)}
|
||||
|
||||
{/* Type */}
|
||||
<Section title={t('form.type')}>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{MEDIA_TYPES.map((mt) => (
|
||||
<button key={mt.value} type="button" onClick={() => set('type', mt.value)} className={cx('chip', form.type === mt.value && 'chip-on')}>
|
||||
{mt.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
{form.type === 'autre' && (
|
||||
<Field label={t('form.subtype')}>
|
||||
<input className="field" list="subtypes" value={form.subtype ? subtypeLabel(form.subtype) : ''} onChange={(e) => set('subtype', e.target.value)} placeholder={t('form.subtypePh')} />
|
||||
<datalist id="subtypes">
|
||||
{subtypeSuggestions().map((s) => (
|
||||
<option key={s} value={s} />
|
||||
))}
|
||||
</datalist>
|
||||
</Field>
|
||||
</>
|
||||
)}
|
||||
</Section>
|
||||
|
||||
{/* Année, dates de visionnage, genres */}
|
||||
<div className="space-y-4">
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<Field label={t('form.startShort')}>
|
||||
<input className="field px-3" type="date" value={form.startDate ?? ''} onChange={(e) => set('startDate', e.target.value || undefined)} />
|
||||
</Field>
|
||||
<Field label={t('form.endShort')}>
|
||||
<input className="field px-3" type="date" value={form.endDate ?? ''} onChange={(e) => set('endDate', e.target.value || undefined)} />
|
||||
</Field>
|
||||
</div>
|
||||
<div className="grid grid-cols-[5rem_minmax(0,1fr)] items-start gap-3">
|
||||
<Field label={t('form.year')}>
|
||||
<input className="field px-3" type="number" inputMode="numeric" value={form.year ?? ''} onChange={(e) => set('year', toNum(e.target.value))} placeholder="2024" />
|
||||
</Field>
|
||||
<div>
|
||||
<span className="label">{t('form.genres')}</span>
|
||||
<TagInput
|
||||
value={form.genres}
|
||||
onChange={(g) => set('genres', g)}
|
||||
suggestions={genreSuggestions}
|
||||
placeholder={t('form.genresPh')}
|
||||
display={genreLabel}
|
||||
normalize={canonicalGenre}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Statut */}
|
||||
<Section title={t('form.status')}>
|
||||
@@ -429,6 +465,44 @@ export default function MediaForm({ item, onClose, onGoToSettings, onOpenItem }:
|
||||
</div>
|
||||
</Section>
|
||||
|
||||
{/* Épisodes / durée */}
|
||||
{typeInfo.episodic ? (
|
||||
<Section title={t('form.episodes')}>
|
||||
{form.seasons || form.episodesTotal ? (
|
||||
<EpisodeList form={form} onChange={(n, season) => setForm((f) => withEpisodes(f, n, season))} />
|
||||
) : (
|
||||
<div className="card space-y-5 p-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="text-sm text-ink-2">{t('home.episodesSeen')}</span>
|
||||
<div className="flex items-center gap-3">
|
||||
<button type="button" onClick={() => changeEpisodes(-1)} className="grid size-10 place-items-center rounded-full border border-line-strong text-ink-2" aria-label={t('form.minusEp')}>
|
||||
<Minus size={17} />
|
||||
</button>
|
||||
<span className="min-w-16 text-center text-2xl font-bold tabular-nums">{form.episodesWatched}</span>
|
||||
<button type="button" onClick={() => changeEpisodes(1)} className="grid size-10 place-items-center rounded-full bg-accent-fill text-on-accent" aria-label={t('form.plusEp')}>
|
||||
<Plus size={17} strokeWidth={2.5} />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<Field label={t('form.total')}>
|
||||
<input className="field" type="number" inputMode="numeric" min={0} value={form.episodesTotal ?? ''} onChange={(e) => set('episodesTotal', toNum(e.target.value))} placeholder="?" />
|
||||
</Field>
|
||||
<Field label={t('form.season')}>
|
||||
<input className="field" type="number" inputMode="numeric" min={0} value={form.season ?? ''} onChange={(e) => set('season', toNum(e.target.value))} placeholder="1" />
|
||||
</Field>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</Section>
|
||||
) : (
|
||||
<Section title={t('form.duration')}>
|
||||
<Field label={t('form.durationMin')}>
|
||||
<input className="field" type="number" inputMode="numeric" min={0} value={form.duration ?? ''} onChange={(e) => set('duration', toNum(e.target.value))} placeholder={String(DEFAULT_FILM_MINUTES)} />
|
||||
</Field>
|
||||
</Section>
|
||||
)}
|
||||
|
||||
{/* Note */}
|
||||
<Section title={t('form.myRating')}>
|
||||
<div className="card space-y-4 p-4">
|
||||
@@ -465,114 +539,33 @@ export default function MediaForm({ item, onClose, onGoToSettings, onOpenItem }:
|
||||
</div>
|
||||
</Section>
|
||||
|
||||
{/* Épisodes / durée */}
|
||||
{typeInfo.episodic ? (
|
||||
<Section title={t('form.episodes')}>
|
||||
<div className="card space-y-5 p-4">
|
||||
{pos && form.seasons ? (
|
||||
<SeasonPicker seasons={form.seasons} watched={form.episodesWatched} season={form.season} onChange={(n, season) => setForm((f) => ({ ...f, episodesWatched: n, season }))} />
|
||||
) : null}
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="text-sm text-ink-2">{pos ? t('form.episodesOfSeason', { season: pos.season }) : t('home.episodesSeen')}</span>
|
||||
<div className="flex items-center gap-3">
|
||||
<button type="button" onClick={() => changeEpisodes(-1)} className="grid size-10 place-items-center rounded-full border border-line-strong text-ink-2" aria-label={t('form.minusEp')}>
|
||||
<Minus size={17} />
|
||||
</button>
|
||||
<span className="min-w-16 text-center text-2xl font-bold tabular-nums">
|
||||
{pos ? pos.episode : form.episodesWatched}
|
||||
{pos ? <span className="text-base text-ink-3">/{pos.size}</span> : form.episodesTotal ? <span className="text-base text-ink-3">/{form.episodesTotal}</span> : null}
|
||||
</span>
|
||||
<button type="button" onClick={() => changeEpisodes(1)} className="grid size-10 place-items-center rounded-full bg-accent-fill text-on-accent" aria-label={t('form.plusEp')}>
|
||||
<Plus size={17} strokeWidth={2.5} />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{pos ? (
|
||||
<div className="flex items-end justify-between gap-3">
|
||||
<p className="pb-2 text-xs text-ink-3">{t('form.seasonsTotal', { seasons: form.seasons!.length, count: form.episodesTotal ?? 0 })}</p>
|
||||
<div className="w-28 shrink-0">
|
||||
<Field label={t('form.minPerEp')}>
|
||||
<input className="field" type="number" inputMode="numeric" min={0} value={form.episodeDuration ?? ''} onChange={(e) => set('episodeDuration', toNum(e.target.value))} placeholder={String(typeInfo.episodeMinutes)} />
|
||||
</Field>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="grid grid-cols-3 gap-3">
|
||||
<Field label={t('form.total')}>
|
||||
<input className="field" type="number" inputMode="numeric" min={0} value={form.episodesTotal ?? ''} onChange={(e) => set('episodesTotal', toNum(e.target.value))} placeholder="?" />
|
||||
</Field>
|
||||
<Field label={t('form.season')}>
|
||||
<input className="field" type="number" inputMode="numeric" min={0} value={form.season ?? ''} onChange={(e) => set('season', toNum(e.target.value))} placeholder="1" />
|
||||
</Field>
|
||||
<Field label={t('form.minPerEp')}>
|
||||
<input className="field" type="number" inputMode="numeric" min={0} value={form.episodeDuration ?? ''} onChange={(e) => set('episodeDuration', toNum(e.target.value))} placeholder={String(typeInfo.episodeMinutes)} />
|
||||
</Field>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</Section>
|
||||
) : (
|
||||
<Section title={t('form.duration')}>
|
||||
<Field label={t('form.durationMin')}>
|
||||
<input className="field" type="number" inputMode="numeric" min={0} value={form.duration ?? ''} onChange={(e) => set('duration', toNum(e.target.value))} placeholder={String(DEFAULT_FILM_MINUTES)} />
|
||||
</Field>
|
||||
</Section>
|
||||
)}
|
||||
|
||||
{/* Infos : repliées par défaut (dates remplies selon le statut, année et genres par la recherche) */}
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setShowInfo((v) => !v)}
|
||||
aria-expanded={showInfo}
|
||||
className="flex w-full items-center justify-between border-t border-line pt-5 text-left"
|
||||
>
|
||||
<span>
|
||||
<span className="eyebrow block text-ink-2">{t('form.info')}</span>
|
||||
<span className="mt-1 block text-xs text-ink-3">{t('form.infoHint')}</span>
|
||||
</span>
|
||||
<ChevronDown size={18} className={cx('shrink-0 text-ink-3 transition-transform', showInfo && 'rotate-180')} />
|
||||
</button>
|
||||
{showInfo && (
|
||||
<Section title="">
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<Field label={t('form.start')}>
|
||||
<input className="field" type="date" value={form.startDate ?? ''} onChange={(e) => set('startDate', e.target.value || undefined)} />
|
||||
</Field>
|
||||
<Field label={t('form.end')}>
|
||||
<input className="field" type="date" value={form.endDate ?? ''} onChange={(e) => set('endDate', e.target.value || undefined)} />
|
||||
</Field>
|
||||
<Field label={t('form.year')}>
|
||||
<input className="field" type="number" inputMode="numeric" value={form.year ?? ''} onChange={(e) => set('year', toNum(e.target.value))} placeholder="2024" />
|
||||
</Field>
|
||||
<Field label={t('form.platform')}>
|
||||
<input className="field" list="platforms" value={form.platform ?? ''} onChange={(e) => set('platform', e.target.value)} placeholder="Netflix…" />
|
||||
<datalist id="platforms">
|
||||
{platformSuggestions.map((p) => (
|
||||
<option key={p} value={p} />
|
||||
))}
|
||||
</datalist>
|
||||
</Field>
|
||||
</div>
|
||||
<div>
|
||||
<span className="label">{t('form.genres')}</span>
|
||||
<TagInput
|
||||
value={form.genres}
|
||||
onChange={(g) => set('genres', g)}
|
||||
suggestions={genreSuggestions}
|
||||
placeholder={t('form.genresPh')}
|
||||
display={genreLabel}
|
||||
normalize={canonicalGenre}
|
||||
/>
|
||||
</div>
|
||||
</Section>
|
||||
)}
|
||||
|
||||
{(form.status === 'termine' || (form.rewatchDates?.length ?? 0) > 0) && (
|
||||
<Section title={t('form.rewatches')}>
|
||||
<Rewatches dates={form.rewatchDates ?? []} onChange={(d) => set('rewatchDates', d.length ? d : undefined)} />
|
||||
</Section>
|
||||
)}
|
||||
|
||||
{/* Type */}
|
||||
<Section title={t('form.type')}>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{MEDIA_TYPES.map((mt) => (
|
||||
<button key={mt.value} type="button" onClick={() => set('type', mt.value)} className={cx('chip', form.type === mt.value && 'chip-on')}>
|
||||
{mt.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
{form.type === 'autre' && (
|
||||
<Field label={t('form.subtype')}>
|
||||
<input className="field" list="subtypes" value={form.subtype ? subtypeLabel(form.subtype) : ''} onChange={(e) => set('subtype', e.target.value)} placeholder={t('form.subtypePh')} />
|
||||
<datalist id="subtypes">
|
||||
{subtypeSuggestions().map((s) => (
|
||||
<option key={s} value={s} />
|
||||
))}
|
||||
</datalist>
|
||||
</Field>
|
||||
)}
|
||||
</Section>
|
||||
|
||||
<Section title={t('lists.myLists')}>
|
||||
{lists.length > 0 && (
|
||||
<div className="flex flex-wrap gap-2">
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
+8
-4
@@ -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<Omit<AiringInfo, 'checkedAt'>> {
|
||||
@@ -128,6 +131,7 @@ async function checkTmdb(tvId: string, key: string): Promise<Omit<AiringInfo, 'c
|
||||
.sort((a, b) => 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,
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
|
||||
+51
-7
@@ -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<MediaInput>): Partial<MediaInput> {
|
||||
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<TmdbDetails>(`/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<TmdbDetails>(`/${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<string, EpisodeInfo[]>()
|
||||
|
||||
/** É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<EpisodeInfo[]> {
|
||||
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. */
|
||||
|
||||
@@ -76,3 +76,9 @@ export function seasonPosition(item: Pick<MediaItem, 'episodesWatched' | 'season
|
||||
|
||||
/** Nombre d'épisodes vus au début de la saison n (1 = première). */
|
||||
export const episodesBeforeSeason = (seasons: number[], n: number) => 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<MediaItem, 'episodesTotal' | 'seasons'>): number | undefined {
|
||||
const sum = item.seasons?.reduce((a, b) => a + b, 0) ?? 0
|
||||
return Math.max(sum, item.episodesTotal ?? 0) || undefined
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
+40
-28
@@ -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 (
|
||||
<div className="no-scrollbar -mx-4 flex gap-3 overflow-x-auto px-4 pb-1">
|
||||
{items.map((item) => (
|
||||
<button key={item.id} onClick={() => onOpen(item)} className="w-24 shrink-0 text-left">
|
||||
<button key={item.id} onClick={() => onOpen(item)} className="w-32 shrink-0 text-left">
|
||||
<Poster src={item.poster} title={item.title} />
|
||||
<p className="mt-2 line-clamp-2 text-xs font-medium leading-snug text-ink-2">{item.title}</p>
|
||||
<p className="mt-2 truncate text-sm font-semibold leading-snug">{item.title}</p>
|
||||
<p className="truncate text-[11px] text-ink-3">{[TYPE_BY_VALUE[item.type].label, item.year].filter(Boolean).join(' · ')}</p>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
@@ -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
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<StatTile label={t('home.completed')} value={stats.completed} hint={t('home.thisYear', { count: stats.completedThisYear })} />
|
||||
<StatTile label={t('status.en_cours')} value={stats.inProgress} hint={t('home.toWatchN', { count: stats.toWatch })} />
|
||||
<StatTile label={t('home.screenTime')} value={formatDuration(stats.totalMinutes)} hint={t('home.estimate')} />
|
||||
<StatTile label={t('home.episodesSeen')} value={stats.episodesWatched} />
|
||||
{featured && <HomeHero item={featured} onOpen={onOpen} />}
|
||||
|
||||
{inProgress.length > 0 && (
|
||||
<>
|
||||
<SectionTitle>{t('homeHero.continueRow')}</SectionTitle>
|
||||
<div className="no-scrollbar -mx-4 flex gap-3 overflow-x-auto px-4 pb-1">
|
||||
{[...inProgress]
|
||||
.sort((x, y) => y.updatedAt.localeCompare(x.updatedAt))
|
||||
.map((item) => (
|
||||
<ContinueCard key={item.id} item={item} onOpen={onOpen} />
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
{toWatch.length > 0 && (
|
||||
<>
|
||||
<SectionTitle action={seeAll}>{t('status.a_voir')}</SectionTitle>
|
||||
<PosterStrip items={toWatch} onOpen={onOpen} />
|
||||
</>
|
||||
)}
|
||||
|
||||
<FriendsFeed />
|
||||
|
||||
{/* Roulette : pour les soirs sans idée */}
|
||||
<button onClick={onRoulette} className="card mt-3 flex w-full items-center gap-4 p-4 text-left transition-colors active:bg-surface-2">
|
||||
<button onClick={onRoulette} className="card mt-8 flex w-full items-center gap-4 p-4 text-left transition-colors active:bg-surface-2">
|
||||
<span className="grid size-12 shrink-0 place-items-center rounded-full bg-accent-fill text-on-accent">
|
||||
<Dices size={24} />
|
||||
</span>
|
||||
@@ -158,36 +180,26 @@ export default function HomePage({ onOpen, onAdd, onNavigate, onRoulette, onCale
|
||||
<span className="text-accent">→</span>
|
||||
</button>
|
||||
|
||||
<FriendsFeed />
|
||||
|
||||
{inProgress.length > 0 && (
|
||||
<>
|
||||
<SectionTitle>{t('status.en_cours')}</SectionTitle>
|
||||
<div className="space-y-2.5">
|
||||
{inProgress.map((item) => (
|
||||
<MediaRow key={item.id} item={item} onOpen={onOpen} />
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
<TopFive onOpen={onOpen} />
|
||||
|
||||
<Recommendations />
|
||||
|
||||
{toWatch.length > 0 && (
|
||||
<>
|
||||
<SectionTitle action={seeAll}>{t('status.a_voir')}</SectionTitle>
|
||||
<PosterStrip items={toWatch} onOpen={onOpen} />
|
||||
</>
|
||||
)}
|
||||
|
||||
{recent.length > 0 && (
|
||||
<>
|
||||
<SectionTitle action={seeAll}>{t('home.recentlyFinished')}</SectionTitle>
|
||||
<PosterStrip items={recent} onOpen={onOpen} />
|
||||
</>
|
||||
)}
|
||||
|
||||
<SectionTitle>{t('nav.stats')}</SectionTitle>
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<StatTile label={t('home.completed')} value={stats.completed} hint={t('home.thisYear', { count: stats.completedThisYear })} />
|
||||
<StatTile label={t('status.en_cours')} value={stats.inProgress} hint={t('home.toWatchN', { count: stats.toWatch })} />
|
||||
<StatTile label={t('home.screenTime')} value={formatDuration(stats.totalMinutes)} hint={t('home.estimate')} />
|
||||
<StatTile label={t('home.episodesSeen')} value={stats.episodesWatched} />
|
||||
</div>
|
||||
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
|
||||
+4
-3
@@ -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<MediaInput> = { 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()
|
||||
}
|
||||
|
||||
@@ -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 ». */
|
||||
|
||||
Reference in new issue
Block a user