Images d'épisodes et fiches affichées tout de suite
deploy / deploy (push) Successful in 45s

- Épisodes d'une saison gardés sur l'appareil (titres, dates, images) : la liste s'affiche dès l'ouverture, rafraîchie en arrière-plan après 12 h
- Images des épisodes autour du prochain à voir demandées tout de suite (plus en « paresseux ») et préchargées
- Préchargement au toucher d'une série en cours : saison en cours et images des épisodes suivants (data-prefetch-season / -ep)
- lazyPreload : un écran préchargé (fiche, stats, réglages, profils…) s'affiche sans l'attente d'environ 300 ms que React.lazy imposait à la première ouverture
- L'administration n'est plus préchargée pour tout le monde

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:53:45 +00:00
1 parent 11d4de5894
commit ac27542947
12 files changed
+261 -97

No files matched your search

+23 -9
View File
@@ -1,7 +1,7 @@
import { Check, Loader2, Lock } from 'lucide-react'
import { useEffect, useLayoutEffect, useRef, useState } from 'react'
import { locale, t } from '../i18n'
import { getTmdbSeasonEpisodes, type EpisodeInfo } from '../lib/catalogApi'
import { cachedSeasonEpisodes, episodeWindow, getTmdbSeasonEpisodes, preloadImages, type EpisodeInfo } from '../lib/catalogApi'
import { episodeCap, episodesBeforeSeason, seasonPosition } from '../lib/franchise'
import { tmdbSized } from '../lib/tmdbImage'
import { cx, todayISO } from '../lib/utils'
@@ -35,7 +35,8 @@ export default function EpisodeList({ form, aired, onChange, fallbackImage }: Pr
if (current) setViewSeason(current)
}, [current])
const viewSeason = seasons ? Math.min(Math.max(1, picked), seasons.length) : 1
const [episodes, setEpisodes] = useState<EpisodeInfo[]>()
// Liste reçue pour une saison donnée ; en attendant, la copie gardée sur l'appareil s'affiche tout de suite
const [fetched, setFetched] = useState<{ key: string; list: EpisodeInfo[] }>()
const [loading, setLoading] = useState(false)
const listRef = useRef<HTMLDivElement>(null)
const today = todayISO()
@@ -49,23 +50,36 @@ export default function EpisodeList({ form, aired, onChange, fallbackImage }: Pr
const extra = seasons && viewSeason === seasons.length ? Math.max(0, (episodeCap(form) ?? 0) - episodesBeforeSeason(seasons, seasons.length + 1)) : 0
const size = seasons ? Math.min((seasons[viewSeason - 1] ?? 0) + extra, MAX_GENERIC) : Math.min(episodeCap(form) ?? 0, MAX_GENERIC)
const seasonNum = seasons ? viewSeason : 1
const listKey = `${form.externalId}:${seasonNum}`
const known = isTmdb ? cachedSeasonEpisodes(form.externalId, seasonNum) : undefined
const shownList = fetched?.key === listKey ? fetched.list : known
const episodes = shownList?.length ? shownList : undefined
useEffect(() => {
if (!isTmdb || !navigator.onLine) return setEpisodes(undefined)
if (!isTmdb || !navigator.onLine) return
let alive = true
setLoading(true)
getTmdbSeasonEpisodes(form.externalId!, seasons ? viewSeason : 1, key!)
.then((list) => alive && setEpisodes(list.length ? list : undefined))
.catch(() => alive && setEpisodes(undefined))
// Indicateur seulement quand rien n'est encore affiché (sinon la liste gardée est remplacée sans bruit)
if (!cachedSeasonEpisodes(form.externalId, seasonNum)?.length) setLoading(true)
getTmdbSeasonEpisodes(form.externalId!, seasonNum, key!)
.then((list) => alive && setFetched({ key: `${form.externalId}:${seasonNum}`, list }))
.catch(() => {})
.finally(() => alive && setLoading(false))
return () => {
alive = false
}
}, [isTmdb, form.externalId, viewSeason, seasons, key])
}, [isTmdb, form.externalId, seasonNum, 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))
// Épisodes visibles à l'ouverture (autour du prochain à voir) : images demandées tout de suite
const visible = new Set(episodeWindow(rows, watchedHere + 1).map((e) => e.number))
useEffect(() => {
if (episodes) preloadImages(episodeWindow(episodes, watchedHere + 1).map((e) => e.still))
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [episodes])
// Ouvre la liste au niveau du prochain épisode à voir
useLayoutEffect(() => {
@@ -129,7 +143,7 @@ export default function EpisodeList({ form, aired, onChange, fallbackImage }: Pr
>
<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" />
<img src={e.still} alt="" loading={visible.has(e.number) ? 'eager' : 'lazy'} decoding="async" className="size-full object-cover" />
) : fallbackImage ? (
// Pas d'image pour cet épisode : celle de la série, assombrie, avec le numéro par-dessus
<>
+4 -3
View File
@@ -13,6 +13,7 @@ import { useMedia } from '../store'
import { useToast } from './Toast'
import { FilmStrip } from './ui'
import type { MediaItem } from '../types'
import { prefetchAttrs } from '../lib/prefetch'
/** Où j'en suis : « S2 · É3 » (épisode suivant à voir) */
export function nextEpisodeLabel(item: MediaItem): string | undefined {
@@ -110,7 +111,7 @@ export default function HomeHero({ items, onOpen }: { items: MediaItem[]; onOpen
if (Math.abs(dx) > 45) go(current + (dx < 0 ? 1 : -1))
}}
>
<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 })}>
<button {...prefetchAttrs(item)} 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 +165,7 @@ export default function HomeHero({ items, onOpen }: { items: MediaItem[]; onOpen
<Check size={17} /> {waitingLabel(item)}
</span>
) : null}
<button data-prefetch={item.externalId} onClick={() => onOpen(item)} className="btn btn-ghost px-4">
<button {...prefetchAttrs(item)} onClick={() => onOpen(item)} className="btn btn-ghost px-4">
<Info size={17} /> {t('homeHero.details')}
</button>
</div>
@@ -196,7 +197,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 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 })}>
<button {...prefetchAttrs(item)} 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>
+2 -1
View File
@@ -8,6 +8,7 @@ import type { MediaItem } from '../types'
import { TypeBadge } from './Badges'
import Poster from './Poster'
import { EmptyState } from './ui'
import { prefetchAttrs } from '../lib/prefetch'
type Kind = 'fini' | 'revu' | 'commence' | 'abandonne'
@@ -90,7 +91,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 data-prefetch={e.item.externalId} onClick={() => onOpen(e.item)} className="flex w-full items-center gap-3 py-2.5 text-start">
<button {...prefetchAttrs(e.item)} 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>
+3 -2
View File
@@ -10,6 +10,7 @@ import type { MediaItem } from '../types'
import { StatusPill, TypeBadge } from './Badges'
import Poster from './Poster'
import { RatingBadge } from './Rating'
import { prefetchAttrs } from '../lib/prefetch'
function Progress({ item }: { item: MediaItem }) {
const cap = episodeCap(item)
@@ -52,7 +53,7 @@ export const MediaCard = memo(function MediaCard({ item, onOpen }: { item: Media
return (
<article>
<div className="relative">
<button data-prefetch={item.externalId} onClick={() => onOpen(item)} className="block w-full" aria-label={t('card.open', { title: item.title })}>
<button {...prefetchAttrs(item)} 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 +70,7 @@ export const MediaCard = memo(function MediaCard({ item, onOpen }: { item: Media
</button>
)}
</div>
<button data-prefetch={item.externalId} onClick={() => onOpen(item)} className="block w-full text-start">
<button {...prefetchAttrs(item)} 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} />
+4 -3
View File
@@ -11,6 +11,7 @@ import { RatingBadge } from './Rating'
import TopFiveEditor from './TopFiveEditor'
import SharePreview from './SharePreview'
import { LinkArrow, SectionTitle } from './ui'
import { prefetchAttrs } from '../lib/prefetch'
/** Chiffre géant en contour (rouge pour le n°1, gris pour les autres). */
function RankNumber({ rank, big }: { rank: number; big?: boolean }) {
@@ -110,7 +111,7 @@ export default function TopFive({ onOpen, items: others }: { onOpen: (item: Medi
<RankNumber rank={1} big />
</span>
{first ? (
<button data-prefetch={first.externalId} onClick={() => onOpen(first)} className="relative z-10 w-32 lg:w-40">
<button {...prefetchAttrs(first)} onClick={() => onOpen(first)} className="relative z-10 w-32 lg:w-40">
<Poster src={first.poster} title={first.title} />
</button>
) : (
@@ -121,7 +122,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 data-prefetch={first.externalId} onClick={() => onOpen(first)} className="mt-1.5 block text-start text-lg font-bold leading-snug">
<button {...prefetchAttrs(first)} 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 +150,7 @@ export default function TopFive({ onOpen, items: others }: { onOpen: (item: Medi
</span>
<div className="relative z-10 ms-4">
{item ? (
<button data-prefetch={item.externalId} onClick={() => onOpen(item)} className="block w-full">
<button {...prefetchAttrs(item)} onClick={() => onOpen(item)} className="block w-full">
<Poster src={item.poster} title={item.title} />
</button>
) : (
+13 -22
View File
@@ -1,4 +1,5 @@
import { createContext, lazy, Suspense, useCallback, useContext, useEffect, useMemo, useState, type ReactNode } from 'react'
import { createContext, Suspense, useCallback, useContext, useEffect, useMemo, useState, type ReactNode } from 'react'
import { lazyPreload } from '../../lib/lazyPreload'
import { cachedMyProfile, getFollowRequests, getMyProfile, unreadNotifications, type Profile, type ProfileCard } from '../../lib/cloud/social'
import { useMedia } from '../../store'
import type { MediaItem } from '../../types'
@@ -37,28 +38,18 @@ interface SocialApi {
bumpShared: () => void
}
// Écrans sociaux chargés à la demande (préchargés par App au repos via preloadSocial)
const socialLoaders = {
NotificationsSheet: () => import('./NotificationsSheet'),
EditProfile: () => import('./EditProfile'),
FollowList: () => import('./FollowList'),
PeopleSearch: () => import('./PeopleSearch'),
ProfileView: () => import('./ProfileView'),
TitleReviews: () => import('./TitleReviews'),
ItemPeek: () => import('./ItemPeek'),
SharedLists: () => import('./SharedLists'),
}
const NotificationsSheet = lazy(socialLoaders.NotificationsSheet)
const EditProfile = lazy(socialLoaders.EditProfile)
const FollowList = lazy(socialLoaders.FollowList)
const PeopleSearch = lazy(socialLoaders.PeopleSearch)
const ProfileView = lazy(socialLoaders.ProfileView)
const TitleReviews = lazy(socialLoaders.TitleReviews)
const ItemPeek = lazy(socialLoaders.ItemPeek)
const SharedListSheet = lazy(() => socialLoaders.SharedLists().then((m) => ({ default: m.SharedListSheet })))
const InvitePeople = lazy(() => socialLoaders.SharedLists().then((m) => ({ default: m.InvitePeople })))
// Écrans sociaux chargés à la demande (préchargés par App au repos via preloadSocial ; affichés sans attente une fois préchargés)
const NotificationsSheet = lazyPreload(() => import('./NotificationsSheet'))
const EditProfile = lazyPreload(() => import('./EditProfile'))
const FollowList = lazyPreload(() => import('./FollowList'))
const PeopleSearch = lazyPreload(() => import('./PeopleSearch'))
const ProfileView = lazyPreload(() => import('./ProfileView'))
const TitleReviews = lazyPreload(() => import('./TitleReviews'))
const ItemPeek = lazyPreload(() => import('./ItemPeek'))
const SharedListSheet = lazyPreload(() => import('./SharedLists').then((m) => ({ default: m.SharedListSheet })))
const InvitePeople = lazyPreload(() => import('./SharedLists').then((m) => ({ default: m.InvitePeople })))
export function preloadSocial() {
for (const load of Object.values(socialLoaders)) void load().catch(() => {})
for (const screen of [ProfileView, ItemPeek, NotificationsSheet, TitleReviews, PeopleSearch, FollowList, EditProfile, SharedListSheet, InvitePeople]) void screen.preload().catch(() => {})
}
const SocialContext = createContext<SocialApi>({