Note Trakt affichée tout de suite
deploy / deploy (push) Successful in 40s

- Gardée sur l'appareil : une fiche déjà ouverte affiche sa note et sa répartition immédiatement (et hors-ligne), rafraîchie en arrière-plan
- La fiche n'attend plus Trakt pour le casting et « Où regarder » ; pendant le premier chargement, place réservée sans chiffre provisoire (plus de bascule TMDB → Trakt)
- Préchargement dès qu'on touche une affiche (ou qu'on la survole à la souris) : la fiche s'ouvre avec ses infos
- Serveur : notes Trakt gardées 24 h pour tout le monde (table title_ratings), correspondance TMDB → Trakt gardée pour toujours ; une note plus ancienne est renvoyée tout de suite puis rafraîchie

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YVo1qxKoBQCaMd7Ue8PGbe
This commit is contained in:
Claude committed 2026-11-29 15:13:59 +00:00
1 parent e627e935c4
commit f3b7d0c025
16 files changed
+326 -75

No files matched your search

+1 -1
View File
@@ -71,7 +71,7 @@ function EntryRow({ e, onOpen, onAdd, busy, added }: { e: Entry; onOpen: (i: Med
)
if (mine) {
return (
<button onClick={() => onOpen(e.item!)} className="flex w-full items-center gap-3 py-2.5 text-start">
<button data-prefetch={e.item?.externalId} onClick={() => onOpen(e.item!)} className="flex w-full items-center gap-3 py-2.5 text-start">
{body}
<ChevronRight size={16} className="shrink-0 text-ink-3" />
</button>
+3 -3
View File
@@ -110,7 +110,7 @@ export default function HomeHero({ items, onOpen }: { items: MediaItem[]; onOpen
if (Math.abs(dx) > 45) go(current + (dx < 0 ? 1 : -1))
}}
>
<button onClick={() => onOpen(item)} className="relative block aspect-video w-full overflow-hidden bg-surface-2 lg:aspect-auto lg:h-full lg:min-h-[22rem]" aria-label={t('card.open', { title: item.title })}>
<button data-prefetch={item.externalId} onClick={() => onOpen(item)} className="relative block aspect-video w-full overflow-hidden bg-surface-2 lg:aspect-auto lg:h-full lg:min-h-[22rem]" aria-label={t('card.open', { title: item.title })}>
{items.map((it, k) => {
const image = it.backdrop ?? it.poster
return image ? (
@@ -164,7 +164,7 @@ export default function HomeHero({ items, onOpen }: { items: MediaItem[]; onOpen
<Check size={17} /> {waitingLabel(item)}
</span>
) : null}
<button onClick={() => onOpen(item)} className="btn btn-ghost px-4">
<button data-prefetch={item.externalId} onClick={() => onOpen(item)} className="btn btn-ghost px-4">
<Info size={17} /> {t('homeHero.details')}
</button>
</div>
@@ -196,7 +196,7 @@ export function ContinueCard({ item, onOpen }: { item: MediaItem; onOpen: (item:
return (
<article className="flex h-[5.5rem] w-72 shrink-0 overflow-hidden rounded-md border border-line bg-surface">
<button onClick={() => onOpen(item)} className="flex min-w-0 flex-1 items-stretch text-start" aria-label={t('card.open', { title: item.title })}>
<button data-prefetch={item.externalId} onClick={() => onOpen(item)} className="flex min-w-0 flex-1 items-stretch text-start" aria-label={t('card.open', { title: item.title })}>
<span className="block w-[3.6rem] shrink-0 bg-surface-2">{image && <img src={image} alt="" loading="lazy" className="size-full object-cover" />}</span>
<span className="flex min-w-0 flex-1 flex-col justify-center px-3">
<span className="block truncate font-bold text-base leading-tight">{item.title}</span>
+1 -1
View File
@@ -90,7 +90,7 @@ export default function JournalView({ onOpen }: { onOpen: (item: MediaItem) => v
const d = new Date(e.date + 'T12:00:00')
return (
<li key={e.item.id + e.date + e.kind}>
<button onClick={() => onOpen(e.item)} className="flex w-full items-center gap-3 py-2.5 text-start">
<button data-prefetch={e.item.externalId} onClick={() => onOpen(e.item)} className="flex w-full items-center gap-3 py-2.5 text-start">
<span className="w-9 shrink-0 text-center">
<span className="block text-xl font-bold leading-none tabular-nums">{d.getDate()}</span>
<span className="block text-[10px] text-ink-3">{d.toLocaleDateString(locale(), { weekday: 'short' }).replace('.', '')}</span>
+1 -1
View File
@@ -98,7 +98,7 @@ export default function LatestReleases({ onOpenSeed }: { onOpenSeed: (seed: Sear
return (
<div key={r.externalId} className="w-28 shrink-0">
<div className="relative">
<button onClick={() => void open(r)} className="block w-full" aria-label={t('card.open', { title: r.title })}>
<button data-prefetch={r.externalId} onClick={() => void open(r)} className="block w-full" aria-label={t('card.open', { title: r.title })}>
<Poster src={r.poster} title={r.title} />
</button>
<button
+2 -2
View File
@@ -52,7 +52,7 @@ export const MediaCard = memo(function MediaCard({ item, onOpen }: { item: Media
return (
<article>
<div className="relative">
<button onClick={() => onOpen(item)} className="block w-full" aria-label={t('card.open', { title: item.title })}>
<button data-prefetch={item.externalId} onClick={() => onOpen(item)} className="block w-full" aria-label={t('card.open', { title: item.title })}>
<Poster src={item.poster} title={item.title} />
</button>
<TypeBadge item={item} className="pointer-events-none absolute start-2 top-2 border-transparent bg-bg/85" />
@@ -69,7 +69,7 @@ export const MediaCard = memo(function MediaCard({ item, onOpen }: { item: Media
</button>
)}
</div>
<button onClick={() => onOpen(item)} className="block w-full text-start">
<button data-prefetch={item.externalId} onClick={() => onOpen(item)} className="block w-full text-start">
<h3 className="mt-2.5 line-clamp-2 font-sans text-sm font-semibold leading-snug tracking-normal">{item.title}</h3>
<div className="mt-1 flex items-center justify-between gap-2">
<StatusPill status={item.status} />
+3 -3
View File
@@ -110,7 +110,7 @@ export default function TopFive({ onOpen, items: others }: { onOpen: (item: Medi
<RankNumber rank={1} big />
</span>
{first ? (
<button onClick={() => onOpen(first)} className="relative z-10 w-32 lg:w-40">
<button data-prefetch={first.externalId} onClick={() => onOpen(first)} className="relative z-10 w-32 lg:w-40">
<Poster src={first.poster} title={first.title} />
</button>
) : (
@@ -121,7 +121,7 @@ export default function TopFive({ onOpen, items: others }: { onOpen: (item: Medi
<span className="eyebrow text-accent">{t('top.number', { rank: 1 })} · {current.plural}</span>
{first ? (
<>
<button onClick={() => onOpen(first)} className="mt-1.5 block text-start text-lg font-bold leading-snug">
<button data-prefetch={first.externalId} onClick={() => onOpen(first)} className="mt-1.5 block text-start text-lg font-bold leading-snug">
{first.title}
</button>
<div className="mt-1.5 flex flex-wrap items-center gap-x-2 gap-y-1 text-xs text-ink-3">
@@ -149,7 +149,7 @@ export default function TopFive({ onOpen, items: others }: { onOpen: (item: Medi
</span>
<div className="relative z-10 ms-4">
{item ? (
<button onClick={() => onOpen(item)} className="block w-full">
<button data-prefetch={item.externalId} onClick={() => onOpen(item)} className="block w-full">
<Poster src={item.poster} title={item.title} />
</button>
) : (
+1 -1
View File
@@ -174,7 +174,7 @@ export default function PersonSheet({
const it = mine(c.result)
return (
<li key={c.group + c.result.externalId}>
<button onClick={() => (it ? onOpenItem(it) : onOpenSeed(c.result))} className="group block w-full text-start">
<button data-prefetch={it?.externalId ?? c.result.externalId} onClick={() => (it ? onOpenItem(it) : onOpenSeed(c.result))} className="group block w-full text-start">
<div className="relative">
<Poster src={c.result.posterUrl ?? c.result.thumb} title={c.result.title} />
{it && (
+1 -1
View File
@@ -18,7 +18,7 @@ import { useSocial } from './SocialProvider'
function PosterTile({ item, onOpen, caption }: { item: MediaItem; onOpen: () => void; caption?: string }) {
return (
<button onClick={onOpen} className="block w-full text-start">
<button data-prefetch={item.externalId} onClick={onOpen} className="block w-full text-start">
<Poster src={item.poster} title={item.title} />
<p className="mt-1.5 truncate text-[11px] font-medium text-ink-2">{item.title}</p>
<p className="flex h-4 items-center gap-1 text-[11px] text-ink-3">
+1 -1
View File
@@ -98,7 +98,7 @@ export default function AddTitle({
const mine = inLibrary(r)
return (
<li key={r.externalId}>
<button onClick={() => (mine ? onOpenItem(mine) : onPick(r))} className="flex w-full items-center gap-3 py-3 text-start active:bg-surface lg:border-b lg:border-line">
<button data-prefetch={r.externalId} onClick={() => (mine ? onOpenItem(mine) : onPick(r))} className="flex w-full items-center gap-3 py-3 text-start active:bg-surface lg:border-b lg:border-line">
{r.thumb ? (
<img src={r.thumb} alt="" loading="lazy" className="h-[5.25rem] w-14 shrink-0 rounded-lg border border-line bg-surface-2 object-cover" />
) : (
+55 -11
View File
@@ -2,7 +2,7 @@ import { locale, t } from '../../i18n'
import { FilmStrip } from '../ui'
import { Bookmark, Check, ChevronDown, Eye, Heart, Loader2, MessagesSquare, Minus, MoreHorizontal, Pencil, Play, Plus, Share2, Trash2, X } from 'lucide-react'
import { useEffect, useMemo, useRef, useState, type ReactNode } from 'react'
import { getTitleExtras, getTmdbCredits, getTmdbDetails, getTmdbExtras, type SearchResult, type TitleExtras } from '../../lib/catalogApi'
import { cachedPublicRatings, getPublicRatings, getTitleExtras, getTmdbCredits, getTmdbDetails, getTmdbExtras, type PublicRatings, type SearchResult, type TitleExtras } from '../../lib/catalogApi'
import { CRITERIA, STATUS_BY_VALUE, TYPE_BY_VALUE } from '../../lib/constants'
import { genreLabel } from '../../lib/genres'
import { airedCount, nextAirDate, useAiringCache } from '../../lib/airing'
@@ -107,6 +107,26 @@ export default function TitleSheet({ item: initial, seed, onClose, onOpenPerson,
}
}, [externalId, settings.tmdbKey])
// Note du public Trakt (films et séries), à part du reste de la fiche (qui ne l'attend plus) :
// la copie gardée sur l'appareil s'affiche tout de suite, puis est rafraîchie si elle date un peu
const isTmdbTitle = !!externalId?.startsWith('tmdb:')
const [trakt, setTrakt] = useState<PublicRatings | null | undefined>(() => (isTmdbTitle ? cachedPublicRatings(externalId) : undefined))
useEffect(() => {
if (!externalId?.startsWith('tmdb:')) return
// Hors-ligne et rien de gardé : on s'en tient à la note TMDB
if (!navigator.onLine) return setTrakt((v) => v ?? null)
let alive = true
getPublicRatings(externalId).then(
(r) => alive && setTrakt(r),
() => alive && setTrakt((v) => v ?? null),
)
return () => {
alive = false
}
}, [externalId])
// Note finale (Trakt, ou TMDB / AniList quand Trakt n'en a pas) : undefined tant qu'on ne la connaît pas
const publicAvg = trakt ? trakt.average : trakt === null || !isTmdbTitle ? extras?.average : undefined
// Fiche TMDB ajoutée avant le suivi par saison : grande image et saisons récupérées en arrière-plan (et gardées)
useEffect(() => {
const key = settings.tmdbKey?.trim()
@@ -135,9 +155,9 @@ export default function TitleSheet({ item: initial, seed, onClose, onOpenPerson,
// Garde la note du public de la fiche à jour (utilisée par les stats « Moi vs le public »)
useEffect(() => {
if (item && extras?.average != null && Math.abs((item.publicRating ?? 0) - extras.average) >= 0.1) void patchMany([{ id: item.id, patch: { publicRating: extras.average } }])
if (item && publicAvg != null && Math.abs((item.publicRating ?? 0) - publicAvg) >= 0.1) void patchMany([{ id: item.id, patch: { publicRating: publicAvg } }])
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [extras?.average, item?.id])
}, [publicAvg, item?.id])
const [busy, setBusy] = useState(false)
const addingRef = useRef(false)
@@ -166,7 +186,7 @@ export default function TitleSheet({ item: initial, seed, onClose, onOpenPerson,
// On garde l'adresse de l'affiche (le service worker la met en cache : visible hors-ligne). La copier dans
// la fiche l'alourdissait d'environ 50 Ko, renvoyés au serveur à chaque modification et chez les amis.
if (seed.posterUrl) base.poster = seed.posterUrl
if (extras?.average != null) base.publicRating = extras.average
if (publicAvg != null) base.publicRating = publicAvg
const created = await add({
...BLANK,
status: 'a_voir',
@@ -326,8 +346,10 @@ export default function TitleSheet({ item: initial, seed, onClose, onOpenPerson,
}
const heroImage = backdrop ?? extras?.backdrop
const average = extras?.average ?? data.publicRating
const source = externalId?.startsWith('anilist:') ? 'AniList' : externalId ? (extras?.ratingSource ?? 'TMDB') : undefined
// Premier chargement de Trakt (quelques dixièmes de seconde) : place réservée, sans chiffre provisoire qui changerait ensuite
const ratingPending = isTmdbTitle && trakt === undefined
const average = trakt ? trakt.average : ratingPending ? undefined : (extras?.average ?? data.publicRating)
const source = externalId?.startsWith('anilist:') ? 'AniList' : externalId ? (trakt ? 'Trakt' : 'TMDB') : undefined
const runtime = type === 'film' ? (data.duration ?? extras?.runtime) : undefined
const metaLine = [
data.year,
@@ -429,7 +451,16 @@ export default function TitleSheet({ item: initial, seed, onClose, onOpenPerson,
<div className="flex flex-col lg:mt-8 lg:px-6 lg:grid lg:grid-cols-[minmax(0,1fr)_28rem] xl:grid-cols-[minmax(0,1fr)_32rem] lg:items-start lg:gap-6">
<div className="order-1 lg:col-start-2 lg:row-start-1">
{/* Note moyenne du public */}
{source && <PublicRating average={average} votes={extras?.votes} distribution={extras?.distribution} source={source} mine={item?.rating} />}
{source && (
<PublicRating
average={average}
votes={trakt ? trakt.votes : extras?.votes}
distribution={trakt ? trakt.distribution : extras?.distribution}
source={source}
pending={ratingPending}
mine={item?.rating}
/>
)}
{/* Mes actions */}
<section className="card mx-4 mt-4 p-4">
@@ -756,12 +787,15 @@ function PublicRating({
distribution,
source,
mine,
pending,
}: {
average?: number
votes?: number
distribution?: { score: number; amount: number }[]
source: string
mine?: number
/** Note Trakt en cours de chargement : place du graphique réservée, source pas encore annoncée */
pending?: boolean
}) {
const max = Math.max(1, ...(distribution ?? []).map((d) => d.amount))
const compact = new Intl.NumberFormat(locale(), { notation: 'compact', maximumFractionDigits: 1 })
@@ -776,10 +810,13 @@ function PublicRating({
<span className="text-base font-normal text-ink-3">/5</span>
</p>
<p className="mt-1.5 text-xs text-ink-3">
{votes ? `${t('title.votes', { count: votes, n: compact.format(votes) })} · ` : ''}
{source}
{pending ? '\u00a0' : `${votes ? `${t('title.votes', { count: votes, n: compact.format(votes) })} · ` : ''}${source}`}
</p>
</>
) : pending ? (
<p className="mt-1 text-4xl font-bold leading-none text-line-strong" aria-hidden="true">
–
</p>
) : (
<p className="mt-1 text-sm text-ink-3">{t('title.noAverage')}</p>
)}
@@ -789,14 +826,21 @@ function PublicRating({
</p>
)}
</div>
{distribution && distribution.length > 0 && (
{distribution && distribution.length > 0 ? (
<div className="flex h-16 max-w-48 flex-1 items-end gap-[3px]" role="img" aria-label={t('title.distribution')}>
{Array.from({ length: 10 }, (_, k) => {
const amount = distribution.find((d) => d.score === k + 1)?.amount ?? 0
return <span key={k} className="flex-1 rounded-t-sm bg-ink-3" style={{ height: `${Math.max(4, (amount / max) * 100)}%`, opacity: amount ? 1 : 0.3 }} />
})}
</div>
)}
) : pending ? (
// Place réservée pendant le chargement : rien ne bouge quand les barres arrivent
<div className="flex h-16 max-w-48 flex-1 animate-pulse items-end gap-[3px]" aria-hidden="true">
{[6, 5, 5, 7, 10, 18, 32, 52, 70, 60].map((h, k) => (
<span key={k} className="flex-1 rounded-t-sm bg-line" style={{ height: `${h}%` }} />
))}
</div>
) : null}
</section>
)
}