Bilan de l'année : pages à faire défiler et image à partager
deploy / deploy (push) Successful in 1m0s
deploy / deploy (push) Successful in 1m0s
Le bilan se calcule sur l'appareil à partir de la bibliothèque : titres terminés, temps passé, épisodes, types, genres, pays, mieux notés, coups de cœur, mois le plus chargé et premier titre de l'année. Accessible depuis la page Stats, et mis en avant sur l'accueil en décembre et janvier. La dernière page crée une image à partager. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YVo1qxKoBQCaMd7Ue8PGbe
This commit is contained in:
25 files changed
+922
-1
No files matched your search
@@ -0,0 +1,92 @@
|
||||
import { Sparkles, X } from 'lucide-react'
|
||||
import { lazy, Suspense, useMemo, useState } from 'react'
|
||||
import { t } from '../i18n'
|
||||
import { recapSeasonYear, yearRecap } from '../lib/recap'
|
||||
import type { MediaItem } from '../types'
|
||||
|
||||
// Les pages du bilan ne sont chargées qu'à l'ouverture
|
||||
const YearRecap = lazy(() => import('./YearRecap'))
|
||||
|
||||
/** Ouvre le bilan d'une année (chargé à la demande). */
|
||||
function RecapViewer({ items, year, onClose, onSeeStats }: { items: MediaItem[]; year: string; onClose: () => void; onSeeStats?: () => void }) {
|
||||
const recap = useMemo(() => yearRecap(items, year), [items, year])
|
||||
return (
|
||||
<Suspense fallback={null}>
|
||||
<YearRecap recap={recap} onClose={onClose} onSeeStats={onSeeStats} />
|
||||
</Suspense>
|
||||
)
|
||||
}
|
||||
|
||||
/** Bouton « Mon année 2026 » de la page Stats (si l'année a au moins un titre terminé). */
|
||||
export function RecapButton({ items, year }: { items: MediaItem[]; year: string }) {
|
||||
const [open, setOpen] = useState(false)
|
||||
const finished = useMemo(() => yearRecap(items, year).finished, [items, year])
|
||||
if (!finished) return null
|
||||
return (
|
||||
<>
|
||||
<button type="button" onClick={() => setOpen(true)} className="btn btn-ghost mt-4 w-full justify-start gap-3 px-4 py-3.5 text-start sm:w-auto">
|
||||
<Sparkles size={18} className="text-accent" />
|
||||
<span className="font-semibold">{t('recap.cta', { year })}</span>
|
||||
</button>
|
||||
{open && <RecapViewer items={items} year={year} onClose={() => setOpen(false)} />}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
const hiddenKey = (year: string) => `azuucine:recap-hint-${year}`
|
||||
|
||||
/**
|
||||
* Carte de l'accueil en décembre (année en cours) et en janvier (année passée), masquable,
|
||||
* dès que l'année compte au moins 3 titres terminés.
|
||||
*/
|
||||
export function RecapHint({ items, onSeeStats }: { items: MediaItem[]; onSeeStats: () => void }) {
|
||||
const year = recapSeasonYear()
|
||||
const finished = useMemo(() => (year ? yearRecap(items, year).finished : 0), [items, year])
|
||||
const [hidden, setHidden] = useState(() => {
|
||||
try {
|
||||
return !!year && localStorage.getItem(hiddenKey(year)) === '1'
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
})
|
||||
const [open, setOpen] = useState(false)
|
||||
if (!year || finished < 3 || hidden) return null
|
||||
|
||||
const hide = () => {
|
||||
setHidden(true)
|
||||
try {
|
||||
localStorage.setItem(hiddenKey(year), '1')
|
||||
} catch {
|
||||
/* stockage bloqué : la carte reviendra à la prochaine visite */
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<section className="card mb-6 p-4" aria-label={t('recap.homeTitle', { year })}>
|
||||
<div className="flex items-start gap-3">
|
||||
<Sparkles size={20} className="mt-0.5 shrink-0 text-accent" aria-hidden />
|
||||
<div className="min-w-0 flex-1">
|
||||
<h2 className="font-semibold">{t('recap.homeTitle', { year })}</h2>
|
||||
<p className="mt-1 text-sm text-ink-2">{t('recap.homeText')}</p>
|
||||
<button type="button" onClick={() => setOpen(true)} className="btn btn-primary mt-3 px-4 py-2 text-sm">
|
||||
{t('recap.open')}
|
||||
</button>
|
||||
</div>
|
||||
<button type="button" onClick={hide} aria-label={t('netPill.hide')} className="-me-1.5 -mt-1.5 grid size-8 shrink-0 place-items-center rounded-full text-ink-3 active:bg-surface-2">
|
||||
<X size={16} />
|
||||
</button>
|
||||
</div>
|
||||
{open && (
|
||||
<RecapViewer
|
||||
items={items}
|
||||
year={year}
|
||||
onClose={() => setOpen(false)}
|
||||
onSeeStats={() => {
|
||||
setOpen(false)
|
||||
onSeeStats()
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</section>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,257 @@
|
||||
import { BarChart3, Heart, Share2, X } from 'lucide-react'
|
||||
import { useEffect, useMemo, useRef, useState, type ReactNode } from 'react'
|
||||
import { dateFormat, fmtNumber, t } from '../i18n'
|
||||
import { useBackToClose } from '../lib/backNav'
|
||||
import { useEscape } from '../lib/escape'
|
||||
import { genreLabel } from '../lib/genres'
|
||||
import type { RecapFamily, YearRecap as Recap } from '../lib/recap'
|
||||
import { useScrollLock } from '../lib/scrollLock'
|
||||
import { cx, formatRating } from '../lib/utils'
|
||||
import Poster from './Poster'
|
||||
import SharePreview from './SharePreview'
|
||||
|
||||
const familyLabel = (f: RecapFamily) => (f === 'autre' ? t('stats.tabOther') : t(`typePlural.${f}`))
|
||||
|
||||
/** Grand chiffre d'une page (couleur d'accent). */
|
||||
function Big({ children }: { children: ReactNode }) {
|
||||
return <p className="text-[clamp(3.5rem,18vw,7rem)] font-extrabold leading-none tracking-tight text-accent">{children}</p>
|
||||
}
|
||||
|
||||
/**
|
||||
* Bilan de l'année, page par page comme une story : toucher à droite pour avancer, à gauche pour revenir,
|
||||
* glisser, ou les flèches du clavier. La dernière page propose de partager le bilan en image.
|
||||
*/
|
||||
export default function YearRecap({ recap, onClose, onSeeStats }: { recap: Recap; onClose: () => void; onSeeStats?: () => void }) {
|
||||
useScrollLock()
|
||||
useEscape(onClose)
|
||||
useBackToClose(onClose)
|
||||
const [page, setPage] = useState(0)
|
||||
const [share, setShare] = useState<Blob>()
|
||||
const [busy, setBusy] = useState(false)
|
||||
const down = useRef<number | null>(null)
|
||||
|
||||
const days = Math.floor(recap.minutes / 1440)
|
||||
const maxFamily = Math.max(1, ...recap.families.map((f) => f.count))
|
||||
const monthName = recap.busiest ? dateFormat({ month: 'long' }).format(new Date(`${recap.busiest.key}-15T12:00:00`)) : ''
|
||||
|
||||
// Pages : seulement celles qui ont quelque chose à montrer
|
||||
const pages = useMemo(() => {
|
||||
const list: { key: string; title: string; body: ReactNode }[] = [
|
||||
{
|
||||
key: 'intro',
|
||||
title: t('recap.introTitle', { year: recap.year }),
|
||||
body: (
|
||||
<>
|
||||
<Big>{fmtNumber(recap.finished)}</Big>
|
||||
<p className="mt-3 text-xl font-semibold">{t('recap.finished', { count: recap.finished })}</p>
|
||||
</>
|
||||
),
|
||||
},
|
||||
]
|
||||
if (recap.minutes > 0)
|
||||
list.push({
|
||||
key: 'time',
|
||||
title: t('recap.timeTitle'),
|
||||
body: (
|
||||
<>
|
||||
<Big>{t('common.hours', { h: fmtNumber(Math.round(recap.minutes / 60)) })}</Big>
|
||||
{days > 0 && <p className="mt-3 text-lg text-ink-2">{`${t('stats.nonStopPre')}${t('stats.days', { count: days })}${t('stats.nonStopPost')}`}</p>}
|
||||
{recap.episodes > 0 && <p className="mt-6 text-xl font-semibold">{t('stats.episodesN', { count: recap.episodes })}</p>}
|
||||
</>
|
||||
),
|
||||
})
|
||||
if (recap.families.length)
|
||||
list.push({
|
||||
key: 'types',
|
||||
title: t('recap.typesTitle'),
|
||||
body: (
|
||||
<ul className="w-full max-w-sm space-y-5 text-start">
|
||||
{recap.families.map((f) => (
|
||||
<li key={f.family}>
|
||||
<div className="flex items-baseline justify-between gap-3">
|
||||
<span className="text-lg font-semibold">{familyLabel(f.family)}</span>
|
||||
<span className="text-2xl font-extrabold tabular-nums text-accent">{fmtNumber(f.count)}</span>
|
||||
</div>
|
||||
<div className="mt-1.5 h-2 overflow-hidden rounded-full bg-surface-2">
|
||||
<div className="h-full rounded-full bg-accent-fill" style={{ width: `${(f.count / maxFamily) * 100}%` }} />
|
||||
</div>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
),
|
||||
})
|
||||
if (recap.genres.length)
|
||||
list.push({
|
||||
key: 'genres',
|
||||
title: t('recap.genresTitle'),
|
||||
body: (
|
||||
<>
|
||||
<ol className="space-y-3">
|
||||
{recap.genres.map((g, k) => (
|
||||
<li key={g.label} className={cx('font-extrabold leading-tight', k === 0 ? 'text-5xl text-accent' : 'text-3xl')}>
|
||||
{genreLabel(g.label)}
|
||||
</li>
|
||||
))}
|
||||
</ol>
|
||||
{recap.country && (
|
||||
<p className="mt-10 text-base text-ink-2">
|
||||
{t('recap.topCountry')} · <span aria-hidden="true">{recap.country.flag}</span> <span className="font-semibold text-ink">{recap.country.name}</span>
|
||||
</p>
|
||||
)}
|
||||
</>
|
||||
),
|
||||
})
|
||||
if (recap.best.length)
|
||||
list.push({
|
||||
key: 'best',
|
||||
title: t('recap.bestTitle'),
|
||||
body: (
|
||||
<>
|
||||
<div className="grid w-full max-w-md grid-cols-3 gap-3">
|
||||
{recap.best.map((i) => (
|
||||
<figure key={i.id} className="min-w-0">
|
||||
<Poster src={i.poster} title={i.title} />
|
||||
<figcaption className="mt-2 truncate text-sm font-semibold">{i.title}</figcaption>
|
||||
<p className="text-sm font-bold text-accent">{formatRating(i.rating)} ★</p>
|
||||
</figure>
|
||||
))}
|
||||
</div>
|
||||
{recap.favorites > 0 && (
|
||||
<p className="mt-8 flex items-center gap-2 text-lg font-semibold">
|
||||
<Heart size={18} className="fill-accent text-accent" aria-hidden /> {t('recap.favorites', { count: recap.favorites })}
|
||||
</p>
|
||||
)}
|
||||
</>
|
||||
),
|
||||
})
|
||||
if (recap.busiest || recap.first)
|
||||
list.push({
|
||||
key: 'month',
|
||||
title: recap.busiest ? t('recap.monthTitle') : t('recap.firstTitle'),
|
||||
body: (
|
||||
<>
|
||||
{recap.busiest && (
|
||||
<>
|
||||
<Big>{monthName.charAt(0).toUpperCase() + monthName.slice(1)}</Big>
|
||||
<p className="mt-3 text-xl font-semibold">{t('stats.monthFinished', { count: recap.busiest.count })}</p>
|
||||
</>
|
||||
)}
|
||||
{recap.first && (
|
||||
<div className={cx('flex items-center gap-4 text-start', recap.busiest && 'mt-10')}>
|
||||
<div className="w-20 shrink-0">
|
||||
<Poster src={recap.first.poster} title={recap.first.title} />
|
||||
</div>
|
||||
<div className="min-w-0">
|
||||
{recap.busiest && <p className="text-sm text-ink-3">{t('recap.firstTitle')}</p>}
|
||||
<p className="text-xl font-bold">{recap.first.title}</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
),
|
||||
})
|
||||
list.push({
|
||||
key: 'end',
|
||||
title: t('recap.introTitle', { year: recap.year }),
|
||||
body: (
|
||||
<div className="flex w-full max-w-xs flex-col gap-3">
|
||||
<button type="button" onClick={(e) => (e.stopPropagation(), void makeShare())} disabled={busy} className="btn btn-primary py-3">
|
||||
<Share2 size={18} /> {t('recap.share')}
|
||||
</button>
|
||||
{onSeeStats && (
|
||||
<button type="button" onClick={(e) => (e.stopPropagation(), onSeeStats())} className="btn btn-ghost py-3">
|
||||
<BarChart3 size={18} /> {t('recap.seeStats')}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
),
|
||||
})
|
||||
return list
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [recap, busy])
|
||||
|
||||
const last = pages.length - 1
|
||||
const go = (d: number) => setPage((p) => Math.min(last, Math.max(0, p + d)))
|
||||
|
||||
useEffect(() => {
|
||||
const onKey = (e: KeyboardEvent) => {
|
||||
if (e.key === 'ArrowRight') go(document.dir === 'rtl' ? -1 : 1)
|
||||
else if (e.key === 'ArrowLeft') go(document.dir === 'rtl' ? 1 : -1)
|
||||
}
|
||||
window.addEventListener('keydown', onKey)
|
||||
return () => window.removeEventListener('keydown', onKey)
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [last])
|
||||
|
||||
async function makeShare() {
|
||||
setBusy(true)
|
||||
try {
|
||||
const { renderRecapCard } = await import('../lib/shareCard')
|
||||
setShare(await renderRecapCard(recap))
|
||||
} finally {
|
||||
setBusy(false)
|
||||
}
|
||||
}
|
||||
|
||||
// Toucher : moitié de fin = suivant, début = précédent ; glisser = changer de page
|
||||
const onPointerDown = (e: React.PointerEvent) => {
|
||||
down.current = e.clientX
|
||||
}
|
||||
const onPointerUp = (e: React.PointerEvent<HTMLDivElement>) => {
|
||||
if (down.current == null) return
|
||||
const dx = e.clientX - down.current
|
||||
down.current = null
|
||||
const rtl = document.dir === 'rtl'
|
||||
if (Math.abs(dx) > 50) return go((dx < 0) !== rtl ? 1 : -1)
|
||||
const r = e.currentTarget.getBoundingClientRect()
|
||||
const atStart = rtl ? e.clientX > r.left + r.width * 0.7 : e.clientX < r.left + r.width * 0.3
|
||||
go(atStart ? -1 : 1)
|
||||
}
|
||||
|
||||
const current = pages[page]
|
||||
return (
|
||||
<div className="sheet-in fixed inset-0 z-[60] flex flex-col bg-bg text-ink" role="dialog" aria-modal="true" aria-label={t('recap.introTitle', { year: recap.year })}>
|
||||
<div className="safe-top px-3 pt-2.5">
|
||||
<div className="flex gap-1" aria-hidden>
|
||||
{pages.map((p, k) => (
|
||||
<span key={p.key} className={cx('h-1 flex-1 rounded-full transition-colors', k <= page ? 'bg-ink' : 'bg-line')} />
|
||||
))}
|
||||
</div>
|
||||
<div className="mt-2 flex items-center justify-between">
|
||||
<span className="ps-1 text-sm font-bold">
|
||||
Bobin<span className="text-accent">oo</span> · {recap.year}
|
||||
</span>
|
||||
<button onClick={onClose} className="grid size-10 place-items-center rounded-full text-ink-2" aria-label={t('common.close')}>
|
||||
<X size={22} />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
className="relative flex min-h-0 flex-1 cursor-pointer touch-pan-y select-none flex-col items-center justify-center px-6 pb-[calc(2rem+env(safe-area-inset-bottom))] text-center"
|
||||
onPointerDown={onPointerDown}
|
||||
onPointerUp={onPointerUp}
|
||||
aria-live="polite"
|
||||
>
|
||||
<h2 key={current.key + '-t'} className="sheet-in mb-8 text-lg font-semibold text-ink-2">
|
||||
{current.title}
|
||||
</h2>
|
||||
<div key={current.key} className="sheet-in flex w-full flex-col items-center">
|
||||
{current.body}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Boutons pour le clavier et les lecteurs d'écran (le toucher passe par la zone au-dessus) */}
|
||||
<div className="sr-only">
|
||||
<button onClick={() => go(-1)} disabled={page === 0}>
|
||||
{t('recap.prev')}
|
||||
</button>
|
||||
<button onClick={() => go(1)} disabled={page === last}>
|
||||
{t('recap.next')}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{share && <SharePreview blob={share} filename={`bobinoo-${recap.year}.png`} title={t('recap.shareTitle', { year: recap.year })} onClose={() => setShare(undefined)} />}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user