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
@@ -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>
)
}