Deco
deploy / deploy (push) Successful in 32s

This commit is contained in:
Romain committed 2026-10-04 12:34:08 +02:00
1 parent 080279e456
commit b15207aa88
22 files changed
+800 -222

No files matched your search

+143
View File
@@ -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>
)
}
+94
View File
@@ -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>
)
}
+91
View File
@@ -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>
)
}
+3 -3
View File
@@ -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">
+169 -176
View File
@@ -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>
{/* 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>
)}
</Section>
<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">