diff --git a/src/components/EpisodeList.tsx b/src/components/EpisodeList.tsx index 5a35ea6..0e1271f 100644 --- a/src/components/EpisodeList.tsx +++ b/src/components/EpisodeList.tsx @@ -88,7 +88,7 @@ export default function EpisodeList({ form, onChange }: Props) { ))} ) : ( - {t('form.episodes')} + )} {loading && } @@ -115,7 +115,6 @@ export default function EpisodeList({ form, onChange }: Props) { ) : ( {e.number} )} - {seen && } diff --git a/src/components/HomeHero.tsx b/src/components/HomeHero.tsx index db1f42a..2afbb68 100644 --- a/src/components/HomeHero.tsx +++ b/src/components/HomeHero.tsx @@ -1,8 +1,10 @@ import { Check, Info, Plus } from 'lucide-react' +import { useEffect, useRef, useState } from 'react' import { t } from '../i18n' import { TYPE_BY_VALUE } from '../lib/constants' import { episodeCap, seasonPosition } from '../lib/franchise' import { genreLabel } from '../lib/genres' +import { cx } from '../lib/utils' import { useMedia } from '../store' import type { MediaItem } from '../types' @@ -16,27 +18,88 @@ export function nextEpisodeLabel(item: MediaItem): string | undefined { 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 }) { +/** Grande bannière de l'accueil : défile entre les titres que je regarde en ce moment (ou le prochain à voir). */ +export default function HomeHero({ items, onOpen }: { items: MediaItem[]; onOpen: (item: MediaItem) => void }) { const { incrementEpisode } = useMedia() - const image = item.backdrop ?? item.poster + // On retient le titre affiché (et pas sa position) : la liste se réordonne quand on avance un épisode + const [currentId, setCurrentId] = useState() + const [pausedAt, setPausedAt] = useState(0) + const touchX = useRef(null) + const count = items.length + const current = Math.max(0, items.findIndex((i) => i.id === currentId)) + const item = items[current] + const latest = useRef(items) + latest.current = items + + // Défilement automatique (toutes les 7 s), relancé après chaque action manuelle + useEffect(() => { + if (count < 2) return + const timer = setInterval(() => { + if (document.visibilityState !== 'visible') return + setCurrentId((id) => { + const list = latest.current + const k = Math.max(0, list.findIndex((i) => i.id === id)) + return list[(k + 1) % list.length]?.id + }) + }, 7000) + return () => clearInterval(timer) + }, [count, pausedAt]) + + const go = (k: number) => { + setCurrentId(items[((k % count) + count) % count]?.id) + setPausedAt(Date.now()) + } + + if (!item) return null 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 ( - + (touchX.current = e.touches[0].clientX)} + onTouchEnd={(e) => { + const start = touchX.current + touchX.current = null + if (start == null || count < 2) return + const dx = e.changedTouches[0].clientX - start + if (Math.abs(dx) > 45) go(current + (dx < 0 ? 1 : -1)) + }} + > 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 && } + {items.map((it, k) => { + const image = it.backdrop ?? it.poster + return image ? ( + + ) : null + })} {item.status === 'en_cours' ? t('homeHero.continue') : t('homeHero.next')} {item.title} {meta && {meta}} - + {episodic && next ? ( - incrementEpisode(item.id)} className="btn btn-primary px-5"> + { + setPausedAt(Date.now()) + void incrementEpisode(item.id) + }} + className="btn btn-primary px-5" + > {t('hero.seenEp', { ep: next })} ) : episodic ? ( @@ -47,6 +110,19 @@ export default function HomeHero({ item, onOpen }: { item: MediaItem; onOpen: (i onOpen(item)} className="btn btn-ghost bg-bg/60 px-4"> {t('homeHero.details')} + {count > 1 && ( + + {items.map((it, k) => ( + go(k)} + className={cx('h-1.5 rounded-full transition-all', k === current ? 'w-5 bg-ink' : 'w-1.5 bg-ink/40')} + aria-label={it.title} + aria-current={k === current} + /> + ))} + + )} diff --git a/src/pages/HomePage.tsx b/src/pages/HomePage.tsx index b2f7f85..16aba94 100644 --- a/src/pages/HomePage.tsx +++ b/src/pages/HomePage.tsx @@ -86,7 +86,9 @@ export default function HomePage({ onOpen, onAdd, onNavigate, onRoulette, onCale 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 byRecent = [...inProgress].sort((a, b) => b.updatedAt.localeCompare(a.updatedAt)) + const firstToWatch = items.find((i) => i.status === 'a_voir') + const featured = (byRecent.length ? byRecent.slice(0, 8) : firstToWatch ? [firstToWatch] : []) const toWatch = items.filter((i) => i.status === 'a_voir').slice(0, 12) const recent = items .filter((i) => i.status === 'termine') @@ -140,7 +142,26 @@ export default function HomePage({ onOpen, onAdd, onNavigate, onRoulette, onCale > ) : ( <> - {featured && } + {featured.length > 0 && } + + + + {/* Roulette : pour les soirs sans idée */} + + + + + + + {t('home.noIdea')} {t('roulette.name')} + + + {stats.toWatch ? t('home.rouletteHint', { count: stats.toWatch }) : t('home.rouletteHintAll')} + + + → + + {inProgress.length > 0 && ( <> @@ -162,25 +183,6 @@ export default function HomePage({ onOpen, onAdd, onNavigate, onRoulette, onCale > )} - - - {/* Roulette : pour les soirs sans idée */} - - - - - - - {t('home.noIdea')} {t('roulette.name')} - - - {stats.toWatch ? t('home.rouletteHint', { count: stats.toWatch }) : t('home.rouletteHintAll')} - - - → - - -
{item.status === 'en_cours' ? t('homeHero.continue') : t('homeHero.next')}
{meta}