Initial commit
This commit is contained in:
commit
459e93d314
100 files changed
+26594
No files matched your search
@@ -0,0 +1,238 @@
|
||||
import { genreLabel, subtypeLabel } from '../lib/genres'
|
||||
import { locale, t } from '../i18n'
|
||||
import { Heart, Search, SlidersHorizontal, X } from 'lucide-react'
|
||||
import { useMemo, useState } from 'react'
|
||||
import { StatusDot } from '../components/Badges'
|
||||
import JournalView from '../components/JournalView'
|
||||
import ListsView from '../components/ListsView'
|
||||
import { MediaCard } from '../components/MediaCard'
|
||||
import { EmptyState, PageHeader } from '../components/ui'
|
||||
import { MEDIA_TYPES, STATUSES } from '../lib/constants'
|
||||
import { cx, normalizeText } from '../lib/utils'
|
||||
import { useMedia } from '../store'
|
||||
import type { MediaItem, MediaType, WatchStatus } from '../types'
|
||||
|
||||
type SortKey = 'recent' | 'rating' | 'title' | 'watched'
|
||||
|
||||
const SORTS: { value: SortKey; readonly label: string }[] = [
|
||||
{ value: 'recent', get label() { return t('catalog.sortRecent') } },
|
||||
{ value: 'watched', get label() { return t('catalog.sortWatched') } },
|
||||
{ value: 'rating', get label() { return t('catalog.sortRating') } },
|
||||
{ value: 'title', get label() { return t('catalog.sortTitle') } },
|
||||
]
|
||||
|
||||
interface Props {
|
||||
onOpen: (item: MediaItem) => void
|
||||
onAdd: () => void
|
||||
}
|
||||
|
||||
export default function CatalogPage({ onOpen, onAdd }: Props) {
|
||||
const { items, settings, lists } = useMedia()
|
||||
const [view, setView] = useState<'titles' | 'journal' | 'lists'>('titles')
|
||||
const [query, setQuery] = useState('')
|
||||
const [types, setTypes] = useState<Set<MediaType>>(new Set())
|
||||
const [status, setStatus] = useState<WatchStatus | ''>('')
|
||||
const [genre, setGenre] = useState('')
|
||||
const [minRating, setMinRating] = useState(0)
|
||||
const [favOnly, setFavOnly] = useState(false)
|
||||
const [sort, setSort] = useState<SortKey>('recent')
|
||||
const [showFilters, setShowFilters] = useState(false)
|
||||
|
||||
const allGenres = useMemo(
|
||||
() => [...new Set(items.flatMap((i) => i.genres))].sort((a, b) => a.localeCompare(b, locale())),
|
||||
[items],
|
||||
)
|
||||
|
||||
const toggleType = (t: MediaType) =>
|
||||
setTypes((prev) => {
|
||||
const next = new Set(prev)
|
||||
if (next.has(t)) next.delete(t)
|
||||
else next.add(t)
|
||||
return next
|
||||
})
|
||||
|
||||
const results = useMemo(() => {
|
||||
const q = normalizeText(query)
|
||||
const filtered = items.filter((i) => {
|
||||
if (types.size && !types.has(i.type)) return false
|
||||
if (status && i.status !== status) return false
|
||||
if (genre && !i.genres.includes(genre)) return false
|
||||
if (minRating && (i.rating ?? 0) < minRating) return false
|
||||
if (favOnly && !i.favorite) return false
|
||||
if (q) {
|
||||
const haystack = normalizeText([i.title, i.originalTitle, i.subtype, i.subtype && subtypeLabel(i.subtype), i.platform, ...i.genres, ...i.genres.map(genreLabel)].filter(Boolean).join(' '))
|
||||
if (!haystack.includes(q)) return false
|
||||
}
|
||||
return true
|
||||
})
|
||||
const sorted = [...filtered]
|
||||
if (sort === 'rating') sorted.sort((a, b) => (b.rating ?? -1) - (a.rating ?? -1))
|
||||
else if (sort === 'title') sorted.sort((a, b) => a.title.localeCompare(b.title, locale()))
|
||||
else if (sort === 'watched')
|
||||
sorted.sort((a, b) => (b.endDate ?? b.startDate ?? '').localeCompare(a.endDate ?? a.startDate ?? ''))
|
||||
return sorted
|
||||
}, [items, query, types, status, genre, minRating, favOnly, sort])
|
||||
|
||||
const activeAdvanced = (genre ? 1 : 0) + (minRating ? 1 : 0) + (favOnly ? 1 : 0)
|
||||
const anyFilter = query || types.size || status || activeAdvanced
|
||||
const resetAll = () => {
|
||||
setQuery('')
|
||||
setTypes(new Set())
|
||||
setStatus('')
|
||||
setGenre('')
|
||||
setMinRating(0)
|
||||
setFavOnly(false)
|
||||
}
|
||||
|
||||
// Options de note minimale selon l'échelle affichée (valeurs internes sur 10)
|
||||
const ratingOptions = settings.ratingScale === '5' ? [2, 4, 6, 8, 9, 10] : [5, 6, 7, 8, 9, 10]
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageHeader
|
||||
title={t('catalog.pageTitle')}
|
||||
accent={t('catalog.pageAccent')}
|
||||
subtitle={
|
||||
view === 'journal'
|
||||
? t('catalog.journalSubtitle')
|
||||
: view === 'lists'
|
||||
? t('account.nLists', { count: lists.length })
|
||||
: anyFilter
|
||||
? t('catalog.filteredCount', { count: results.length })
|
||||
: t('account.nTitles', { count: results.length })
|
||||
}
|
||||
/>
|
||||
<div className="mb-3 grid grid-cols-3 gap-1 rounded-full border border-line p-1">
|
||||
{(['titles', 'journal', 'lists'] as const).map((v) => (
|
||||
<button
|
||||
key={v}
|
||||
onClick={() => setView(v)}
|
||||
className={cx('rounded-full py-2 text-sm font-medium transition-colors', view === v ? 'bg-ink text-bg' : 'text-ink-3')}
|
||||
>
|
||||
{v === 'titles' ? t('catalog.titles') : v === 'journal' ? t('catalog.journal') : t('catalog.lists')}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{view === 'journal' ? (
|
||||
<JournalView onOpen={onOpen} />
|
||||
) : view === 'lists' ? (
|
||||
<ListsView onOpen={onOpen} />
|
||||
) : (
|
||||
<>
|
||||
|
||||
{/* Recherche + filtres (collants en haut) */}
|
||||
<div className="sticky top-0 z-20 -mx-4 space-y-3 bg-bg/90 px-4 pb-3 pt-[max(0.5rem,env(safe-area-inset-top))] backdrop-blur-xl">
|
||||
<div className="flex gap-2">
|
||||
<div className="relative flex-1">
|
||||
<Search size={18} className="pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-ink-3" />
|
||||
<input
|
||||
type="search"
|
||||
value={query}
|
||||
onChange={(e) => setQuery(e.target.value)}
|
||||
placeholder={t('catalog.searchPh')}
|
||||
className="field pl-10"
|
||||
enterKeyHint="search"
|
||||
/>
|
||||
</div>
|
||||
<button
|
||||
onClick={() => setShowFilters((v) => !v)}
|
||||
className={cx('relative grid w-12 place-items-center rounded-xl border border-line bg-surface transition-colors', showFilters && 'border-ink text-ink')}
|
||||
aria-label={t('catalog.moreFilters')}
|
||||
aria-expanded={showFilters}
|
||||
>
|
||||
<SlidersHorizontal size={18} />
|
||||
{activeAdvanced > 0 && (
|
||||
<span className="absolute -right-1.5 -top-1.5 grid size-5 place-items-center rounded-full bg-accent-fill text-[10px] text-on-accent">{activeAdvanced}</span>
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="no-scrollbar -mx-4 flex gap-2 overflow-x-auto px-4">
|
||||
<button onClick={() => setTypes(new Set())} className={cx('chip', types.size === 0 && 'chip-on')}>
|
||||
{t('catalog.all')}
|
||||
</button>
|
||||
{MEDIA_TYPES.map((mt) => (
|
||||
<button key={mt.value} onClick={() => toggleType(mt.value)} className={cx('chip', types.has(mt.value) && 'chip-on')}>
|
||||
{mt.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="no-scrollbar -mx-4 flex gap-2 overflow-x-auto px-4">
|
||||
{STATUSES.map((s) => (
|
||||
<button key={s.value} onClick={() => setStatus(status === s.value ? '' : s.value)} className={cx('chip text-xs', status === s.value && 'chip-on')}>
|
||||
<StatusDot status={s.value} />
|
||||
{s.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{showFilters && (
|
||||
<div className="card grid grid-cols-2 gap-3 p-3">
|
||||
<label className="block">
|
||||
<span className="label">{t('catalog.genre')}</span>
|
||||
<select className="field" value={genre} onChange={(e) => setGenre(e.target.value)}>
|
||||
<option value="">{t('catalog.all')}</option>
|
||||
{allGenres.map((g) => (
|
||||
<option key={g} value={g}>
|
||||
{genreLabel(g)}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<label className="block">
|
||||
<span className="label">{t('catalog.minRating')}</span>
|
||||
<select className="field" value={minRating} onChange={(e) => setMinRating(Number(e.target.value))}>
|
||||
<option value={0}>{t('catalog.allRatings')}</option>
|
||||
{ratingOptions.map((r) => (
|
||||
<option key={r} value={r}>
|
||||
≥ {settings.ratingScale === '5' ? r / 2 : r}/{settings.ratingScale}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<label className="col-span-2 block">
|
||||
<span className="label">{t('catalog.sortBy')}</span>
|
||||
<select className="field" value={sort} onChange={(e) => setSort(e.target.value as SortKey)}>
|
||||
{SORTS.map((s) => (
|
||||
<option key={s.value} value={s.value}>
|
||||
{s.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<button onClick={() => setFavOnly((v) => !v)} className={cx('chip justify-center', favOnly && 'chip-on')}>
|
||||
<Heart size={14} className={favOnly ? 'fill-accent-fill text-accent-fill' : ''} /> {t('catalog.favorites')}
|
||||
</button>
|
||||
<button onClick={resetAll} className="chip justify-center">
|
||||
<X size={14} /> {t('catalog.reset')}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{results.length === 0 ? (
|
||||
<EmptyState
|
||||
title={items.length ? t('catalog.noResults') : t('catalog.nothingYet')}
|
||||
text={items.length ? t('catalog.noResultsHint') : t('catalog.nothingYetHint')}
|
||||
action={
|
||||
items.length ? (
|
||||
<button onClick={resetAll} className="btn btn-ghost">{t('catalog.clearFilters')}</button>
|
||||
) : (
|
||||
<button onClick={onAdd} className="btn btn-primary">{t('nav.addTitle')}</button>
|
||||
)
|
||||
}
|
||||
/>
|
||||
) : (
|
||||
<div className="mt-3 grid grid-cols-2 gap-x-3.5 gap-y-6 sm:grid-cols-3">
|
||||
{results.map((item) => (
|
||||
<MediaCard key={item.id} item={item} onOpen={onOpen} />
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
import { useSocial } from '../components/social/SocialProvider'
|
||||
import { t } from '../i18n'
|
||||
import { CalendarDays, Dices, Plus } from 'lucide-react'
|
||||
import { useEffect, useMemo, useRef, useState } from 'react'
|
||||
import { MediaRow } from '../components/MediaCard'
|
||||
import Avatar from '../components/social/Avatar'
|
||||
import FriendsFeed from '../components/social/FriendsFeed'
|
||||
import Poster from '../components/Poster'
|
||||
import TopFive from '../components/TopFive'
|
||||
import Recommendations from '../components/Recommendations'
|
||||
import type { Tab } from '../components/BottomNav'
|
||||
import { EmptyState, LinkArrow, PageHeader, SectionTitle, StatTile } from '../components/ui'
|
||||
import { CACHE_EVENT, loadAiring, needsCheck, refreshAiring, saveAiring, trackable } from '../lib/airing'
|
||||
import { calendarEvents } from '../lib/releases'
|
||||
import { computeStats } from '../lib/stats'
|
||||
import { formatDuration, todayISO } from '../lib/utils'
|
||||
import { useMedia } from '../store'
|
||||
import type { MediaItem } from '../types'
|
||||
|
||||
interface Props {
|
||||
onOpen: (item: MediaItem) => void
|
||||
onAdd: () => void
|
||||
onNavigate: (tab: Tab) => void
|
||||
onRoulette: () => void
|
||||
onCalendar: () => void
|
||||
}
|
||||
|
||||
function PosterStrip({ items, onOpen }: { items: MediaItem[]; onOpen: (item: MediaItem) => void }) {
|
||||
return (
|
||||
<div className="no-scrollbar -mx-4 flex gap-3 overflow-x-auto px-4 pb-1">
|
||||
{items.map((item) => (
|
||||
<button key={item.id} onClick={() => onOpen(item)} className="w-24 shrink-0 text-left">
|
||||
<Poster src={item.poster} title={item.title} />
|
||||
<p className="mt-2 line-clamp-2 text-xs font-medium leading-snug text-ink-2">{item.title}</p>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default function HomePage({ onOpen, onAdd, onNavigate, onRoulette, onCalendar }: Props) {
|
||||
const { items, loading, account, settings, patchMany } = useMedia()
|
||||
const social = useSocial()
|
||||
const stats = useMemo(() => computeStats(items), [items])
|
||||
// Sorties dans les 7 prochains jours (pastille sur l'icône calendrier)
|
||||
// Vérification discrète des nouveaux épisodes (au plus toutes les 12 h) : pastille du calendrier et nombre d'épisodes à jour
|
||||
const airingStarted = useRef(false)
|
||||
useEffect(() => {
|
||||
if (loading || airingStarted.current || !navigator.onLine) return
|
||||
airingStarted.current = true
|
||||
const cache = loadAiring()
|
||||
if (!trackable(items).some((i) => needsCheck(i, cache))) return
|
||||
void refreshAiring(items, cache, settings.tmdbKey)
|
||||
.then((next) => {
|
||||
saveAiring(next)
|
||||
const patches = trackable(items)
|
||||
.filter((i) => i.status !== 'termine' && next[i.id] && next[i.id].aired > (i.episodesTotal ?? 0))
|
||||
.map((i) => ({ id: i.id, patch: { episodesTotal: next[i.id].aired } }))
|
||||
if (patches.length) return patchMany(patches)
|
||||
})
|
||||
.catch(() => {})
|
||||
}, [loading, items, settings.tmdbKey, patchMany])
|
||||
|
||||
const [cacheVersion, setCacheVersion] = useState(0)
|
||||
useEffect(() => {
|
||||
const bump = () => setCacheVersion((v) => v + 1)
|
||||
window.addEventListener(CACHE_EVENT, bump)
|
||||
return () => window.removeEventListener(CACHE_EVENT, bump)
|
||||
}, [])
|
||||
const soon = useMemo(() => {
|
||||
const today = todayISO()
|
||||
const d = new Date(Date.now() + 7 * 86400000)
|
||||
const end = `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`
|
||||
return calendarEvents(items).filter((e) => e.date >= today && e.date <= end).length
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [items, cacheVersion])
|
||||
|
||||
const inProgress = items.filter((i) => i.status === 'en_cours')
|
||||
const toWatch = items.filter((i) => i.status === 'a_voir').slice(0, 12)
|
||||
const recent = items
|
||||
.filter((i) => i.status === 'termine')
|
||||
.sort((a, b) => (b.endDate ?? b.updatedAt).localeCompare(a.endDate ?? a.updatedAt))
|
||||
.slice(0, 12)
|
||||
|
||||
const seeAll = <LinkArrow onClick={() => onNavigate('catalog')}>{t('home.seeAll')}</LinkArrow>
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageHeader
|
||||
title="Azuu"
|
||||
accent="Cine"
|
||||
subtitle={t('home.subtitle')}
|
||||
action={
|
||||
<span className="flex shrink-0 items-center gap-2">
|
||||
<button
|
||||
onClick={onCalendar}
|
||||
className="relative grid size-11 shrink-0 place-items-center rounded-full border border-line text-ink-2 transition-colors active:bg-surface-2"
|
||||
aria-label={soon ? t('home.calendarSoon', { count: soon }) : t('calendar.title')}
|
||||
>
|
||||
<CalendarDays size={20} />
|
||||
{soon > 0 && (
|
||||
<span className="absolute -right-1 -top-1 grid min-w-5 place-items-center rounded-full bg-accent-fill px-1 text-[10px] font-bold text-on-accent">{soon}</span>
|
||||
)}
|
||||
</button>
|
||||
{social.enabled && (
|
||||
<button onClick={() => (social.me ? social.openProfile(social.me.username) : social.openSearch())} className="relative shrink-0 rounded-full" aria-label={t('social.myProfile')}>
|
||||
<Avatar url={social.me?.avatarUrl} name={social.me?.displayName ?? '?'} size={44} />
|
||||
{social.requests.length > 0 && (
|
||||
<span className="absolute -right-1 -top-1 grid min-w-5 place-items-center rounded-full bg-accent-fill px-1 text-[10px] font-bold text-on-accent">{social.requests.length}</span>
|
||||
)}
|
||||
</button>
|
||||
)}
|
||||
</span>
|
||||
}
|
||||
/>
|
||||
|
||||
{!loading && items.length === 0 ? (
|
||||
<>
|
||||
<EmptyState
|
||||
title={t('home.emptyTitle')}
|
||||
text={account ? t('home.emptyCloud') : t('home.emptyLocal')}
|
||||
action={
|
||||
<button onClick={onAdd} className="btn btn-primary">
|
||||
<Plus size={18} /> {t('nav.addTitle')}
|
||||
</button>
|
||||
}
|
||||
/>
|
||||
<FriendsFeed />
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<StatTile label={t('home.completed')} value={stats.completed} hint={t('home.thisYear', { count: stats.completedThisYear })} />
|
||||
<StatTile label={t('status.en_cours')} value={stats.inProgress} hint={t('home.toWatchN', { count: stats.toWatch })} />
|
||||
<StatTile label={t('home.screenTime')} value={formatDuration(stats.totalMinutes)} hint={t('home.estimate')} />
|
||||
<StatTile label={t('home.episodesSeen')} value={stats.episodesWatched} />
|
||||
</div>
|
||||
|
||||
{/* Roulette : pour les soirs sans idée */}
|
||||
<button onClick={onRoulette} className="card mt-3 flex w-full items-center gap-4 p-4 text-left transition-colors active:bg-surface-2">
|
||||
<span className="grid size-12 shrink-0 place-items-center rounded-full bg-accent-fill text-on-accent">
|
||||
<Dices size={24} />
|
||||
</span>
|
||||
<span className="min-w-0 flex-1">
|
||||
<span className="block font-semibold">
|
||||
{t('home.noIdea')} <span className="text-accent">{t('roulette.name')}</span>
|
||||
</span>
|
||||
<span className="mt-0.5 block text-xs text-ink-3">
|
||||
{stats.toWatch ? t('home.rouletteHint', { count: stats.toWatch }) : t('home.rouletteHintAll')}
|
||||
</span>
|
||||
</span>
|
||||
<span className="text-accent">→</span>
|
||||
</button>
|
||||
|
||||
<FriendsFeed />
|
||||
|
||||
{inProgress.length > 0 && (
|
||||
<>
|
||||
<SectionTitle>{t('status.en_cours')}</SectionTitle>
|
||||
<div className="space-y-2.5">
|
||||
{inProgress.map((item) => (
|
||||
<MediaRow key={item.id} item={item} onOpen={onOpen} />
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
<TopFive onOpen={onOpen} />
|
||||
|
||||
<Recommendations />
|
||||
|
||||
{toWatch.length > 0 && (
|
||||
<>
|
||||
<SectionTitle action={seeAll}>{t('status.a_voir')}</SectionTitle>
|
||||
<PosterStrip items={toWatch} onOpen={onOpen} />
|
||||
</>
|
||||
)}
|
||||
|
||||
{recent.length > 0 && (
|
||||
<>
|
||||
<SectionTitle action={seeAll}>{t('home.recentlyFinished')}</SectionTitle>
|
||||
<PosterStrip items={recent} onOpen={onOpen} />
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,403 @@
|
||||
import { t } from '../i18n'
|
||||
import { LanguageSelect } from '../i18n/react'
|
||||
import { Check, Download, Eye, EyeOff, HardDrive, Trash2, Upload, UserX } from 'lucide-react'
|
||||
import { useEffect, useRef, useState, type ReactNode } from 'react'
|
||||
import AccountSection from '../components/AccountSection'
|
||||
import ConfirmDialog from '../components/ConfirmDialog'
|
||||
import { PageHeader, SectionTitle } from '../components/ui'
|
||||
import { exportBackup, parseBackupFile, type ParsedBackup } from '../lib/backup'
|
||||
import { testTmdbKey } from '../lib/catalogApi'
|
||||
import { checkTmdbProxy, type ProxyState } from '../lib/cloud/api'
|
||||
import { ALL_TOP_CATEGORIES, TOP_CATEGORIES } from '../lib/constants'
|
||||
import { isHexColor, THEME_PRESETS } from '../lib/theme'
|
||||
import { cx } from '../lib/utils'
|
||||
import { useMedia } from '../store'
|
||||
|
||||
type Message = { kind: 'ok' | 'error'; text: string }
|
||||
|
||||
function Row({ icon, title, hint, onClick, danger }: { icon: ReactNode; title: string; hint?: string; onClick: () => void; danger?: boolean }) {
|
||||
return (
|
||||
<button onClick={onClick} className={cx('flex w-full items-center gap-3.5 px-4 py-4 text-left transition-colors active:bg-surface-2', danger && 'text-accent')}>
|
||||
<span className={danger ? 'text-accent' : 'text-ink-2'}>{icon}</span>
|
||||
<span className="flex-1">
|
||||
<span className="block font-medium">{title}</span>
|
||||
{hint && <span className="mt-0.5 block text-xs text-ink-3">{hint}</span>}
|
||||
</span>
|
||||
<span className={danger ? 'text-accent' : 'text-ink-3'}>→</span>
|
||||
</button>
|
||||
)
|
||||
}
|
||||
|
||||
export default function SettingsPage() {
|
||||
const { items, settings, updateSettings, importItems, clearAll, lists, mergeLists, account } = useMedia()
|
||||
const fileRef = useRef<HTMLInputElement>(null)
|
||||
const [pending, setPending] = useState<ParsedBackup>()
|
||||
const [message, setMessage] = useState<Message>()
|
||||
const [confirm, setConfirm] = useState<null | 'reset' | 'replace' | 'delete-account'>(null)
|
||||
const [deleting, setDeleting] = useState(false)
|
||||
const [usage, setUsage] = useState<string>()
|
||||
const [keyDraft, setKeyDraft] = useState(settings.tmdbKey ?? '')
|
||||
const [showKey, setShowKey] = useState(false)
|
||||
const [keyState, setKeyState] = useState<'idle' | 'testing' | 'ok' | 'bad'>(settings.tmdbKey ? 'ok' : 'idle')
|
||||
|
||||
useEffect(() => {
|
||||
navigator.storage
|
||||
?.estimate?.()
|
||||
.then(({ usage: u }) => u != null && setUsage(u < 1e6 ? t('common.kb', { n: Math.max(1, Math.round(u / 1e3)) }) : t('common.mb', { n: (u / 1e6).toFixed(1).replace('.', t('common.decimalSep')) })))
|
||||
.catch(() => {})
|
||||
}, [items.length])
|
||||
|
||||
// Avec un compte : vérifie que le proxy TMDB fonctionne vraiment
|
||||
const [proxy, setProxy] = useState<ProxyState | 'checking'>('checking')
|
||||
const runProxyCheck = async () => {
|
||||
setProxy('checking')
|
||||
setProxy(await checkTmdbProxy())
|
||||
}
|
||||
useEffect(() => {
|
||||
if (account) void runProxyCheck()
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [!!account])
|
||||
|
||||
const saveKey = async () => {
|
||||
const key = keyDraft.trim()
|
||||
if (!key) {
|
||||
updateSettings({ tmdbKey: undefined })
|
||||
setKeyState('idle')
|
||||
return
|
||||
}
|
||||
setKeyState('testing')
|
||||
const ok = await testTmdbKey(key)
|
||||
setKeyState(ok ? 'ok' : 'bad')
|
||||
if (ok) updateSettings({ tmdbKey: key })
|
||||
}
|
||||
|
||||
const onExport = async () => {
|
||||
try {
|
||||
const how = await exportBackup(items, settings, lists)
|
||||
setMessage({ kind: 'ok', text: how === 'shared' ? t('settings.backupShared') : t('settings.backupDownloaded') })
|
||||
} catch (e) {
|
||||
if ((e as DOMException)?.name !== 'AbortError') setMessage({ kind: 'error', text: t('settings.exportFailed') })
|
||||
}
|
||||
}
|
||||
|
||||
const onFile = async (file?: File) => {
|
||||
if (fileRef.current) fileRef.current.value = ''
|
||||
if (!file) return
|
||||
try {
|
||||
const parsed = await parseBackupFile(file)
|
||||
if (!parsed.items.length) throw new Error(t('settings.noValidItems'))
|
||||
setPending(parsed)
|
||||
setMessage(undefined)
|
||||
} catch (e) {
|
||||
setMessage({ kind: 'error', text: (e as Error).message })
|
||||
}
|
||||
}
|
||||
|
||||
// Le message s'affiche en bas de l'écran puis disparaît (visible même en bas de page)
|
||||
useEffect(() => {
|
||||
if (!message) return
|
||||
const timer = setTimeout(() => setMessage(undefined), 3500)
|
||||
return () => clearTimeout(timer)
|
||||
}, [message])
|
||||
|
||||
const confirmImport = async (mode: 'merge' | 'replace') => {
|
||||
if (!pending) return
|
||||
setConfirm(null)
|
||||
await importItems(pending.items, mode)
|
||||
if (pending.settings) updateSettings(pending.settings)
|
||||
if (pending.lists) mergeLists(pending.lists, mode)
|
||||
setMessage({
|
||||
kind: 'ok',
|
||||
text: pending.skipped ? t('settings.importedSkipped', { n: pending.items.length, skipped: pending.skipped }) : t('settings.imported', { count: pending.items.length }),
|
||||
})
|
||||
setPending(undefined)
|
||||
}
|
||||
|
||||
const onDeleteAccount = async () => {
|
||||
if (!account) return
|
||||
setConfirm(null)
|
||||
setDeleting(true)
|
||||
try {
|
||||
await account.deleteAccount()
|
||||
} catch (e) {
|
||||
setMessage({ kind: 'error', text: (e as Error).message })
|
||||
setDeleting(false)
|
||||
}
|
||||
}
|
||||
|
||||
const onReset = async () => {
|
||||
setConfirm(null)
|
||||
await clearAll()
|
||||
setMessage({ kind: 'ok', text: t('settings.cleared') })
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageHeader title={t('settings.pageTitle')} accent={t('settings.pageAccent')} />
|
||||
|
||||
{message && (
|
||||
<p
|
||||
role="status"
|
||||
className={cx(
|
||||
'sheet-in fixed inset-x-4 bottom-24 z-40 mx-auto max-w-md rounded-2xl border bg-surface-2 p-3.5 text-sm text-ink',
|
||||
message.kind === 'ok' ? 'border-line-strong' : 'border-accent',
|
||||
)}
|
||||
>
|
||||
{message.text}
|
||||
</p>
|
||||
)}
|
||||
|
||||
{account && <AccountSection account={account} onMessage={(kind, text) => setMessage({ kind, text })} />}
|
||||
|
||||
<SectionTitle>{t('settings.language')}</SectionTitle>
|
||||
<LanguageSelect />
|
||||
<p className="mt-2.5 text-xs text-ink-3">{t('settings.languageHint')}</p>
|
||||
|
||||
<SectionTitle>{t('settings.rating')}</SectionTitle>
|
||||
<div className="grid grid-cols-2 gap-1 rounded-full border border-line p-1">
|
||||
{(['5', '10'] as const).map((scale) => (
|
||||
<button
|
||||
key={scale}
|
||||
onClick={() => updateSettings({ ratingScale: scale })}
|
||||
className={cx('rounded-full py-2.5 text-sm font-medium transition-colors', settings.ratingScale === scale ? 'bg-ink text-bg' : 'text-ink-3')}
|
||||
>
|
||||
{scale === '5' ? t('settings.scale5') : t('settings.scale10')}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<p className="mt-2.5 text-xs text-ink-3">{t('settings.ratingHint')}</p>
|
||||
|
||||
<SectionTitle>{t('settings.theme')}</SectionTitle>
|
||||
<div className="grid grid-cols-6 gap-3">
|
||||
{THEME_PRESETS.map((p) => {
|
||||
const on = settings.accentColor.toLowerCase() === p.color
|
||||
return (
|
||||
<button
|
||||
key={p.color}
|
||||
onClick={() => updateSettings({ accentColor: p.color })}
|
||||
className="flex flex-col items-center gap-1.5"
|
||||
aria-pressed={on}
|
||||
aria-label={t('settings.themeX', { name: p.name })}
|
||||
>
|
||||
<span
|
||||
className={cx('grid size-10 place-items-center rounded-full transition', on ? 'ring-2 ring-ink ring-offset-2 ring-offset-bg' : '')}
|
||||
style={{ background: p.color }}
|
||||
>
|
||||
{on && <Check size={17} strokeWidth={3} className="text-on-accent" />}
|
||||
</span>
|
||||
<span className={cx('text-[11px]', on ? 'text-ink' : 'text-ink-3')}>{p.name}</span>
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
<label className="mt-4 flex items-center gap-3 rounded-2xl border border-line px-4 py-3">
|
||||
<span className="relative size-8 shrink-0 overflow-hidden rounded-full border border-line-strong" style={{ background: settings.accentColor }}>
|
||||
<input
|
||||
type="color"
|
||||
value={settings.accentColor}
|
||||
onChange={(e) => isHexColor(e.target.value) && updateSettings({ accentColor: e.target.value })}
|
||||
className="absolute inset-0 size-full cursor-pointer opacity-0"
|
||||
aria-label={t('settings.pickColor')}
|
||||
/>
|
||||
</span>
|
||||
<span className="flex-1 text-sm">
|
||||
{t('settings.freeColor')}
|
||||
<span className="block text-xs text-ink-3">{t('settings.freeColorHint')}</span>
|
||||
</span>
|
||||
<span className="text-xs uppercase text-ink-3">{settings.accentColor}</span>
|
||||
</label>
|
||||
|
||||
<SectionTitle>{t('settings.databases')}</SectionTitle>
|
||||
<div className="card space-y-4 p-4">
|
||||
<div>
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="font-medium">AniList</span>
|
||||
<span className="eyebrow">{t('settings.anilistActive')}</span>
|
||||
</div>
|
||||
<p className="mt-1 text-xs text-ink-3">{t('settings.noConfig')}</p>
|
||||
</div>
|
||||
{account ? (
|
||||
<div className="border-t border-line pt-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="font-medium">TMDB</span>
|
||||
<span className={cx('eyebrow', proxy === 'ok' && 'text-ink', (proxy === 'missing-key' || proxy === 'not-deployed' || proxy === 'error') && 'text-accent')}>
|
||||
{proxy === 'ok'
|
||||
? t('settings.tmdbActive')
|
||||
: proxy === 'checking'
|
||||
? t('settings.checking')
|
||||
: proxy === 'offline'
|
||||
? t('settings.offline')
|
||||
: proxy === 'missing-key'
|
||||
? t('settings.proxyMissingKey')
|
||||
: proxy === 'not-deployed'
|
||||
? t('settings.proxyNotDeployed')
|
||||
: t('settings.unavailable')}
|
||||
</span>
|
||||
</div>
|
||||
<p className="mt-1 text-xs text-ink-3">
|
||||
{proxy === 'missing-key'
|
||||
? t('settings.proxyMissingKeyHint')
|
||||
: proxy === 'not-deployed'
|
||||
? t('settings.proxyNotDeployedHint')
|
||||
: proxy === 'error'
|
||||
? t('settings.proxyErrorHint')
|
||||
: t('settings.proxyOkHint')}
|
||||
</p>
|
||||
{proxy !== 'ok' && proxy !== 'checking' && (
|
||||
<button onClick={() => void runProxyCheck()} className="mt-2 text-xs font-medium text-ink-3">
|
||||
{t('settings.recheck')} <span className="text-accent">→</span>
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<div className="border-t border-line pt-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="font-medium">TMDB</span>
|
||||
<span className={cx('eyebrow', keyState === 'ok' && 'text-ink', keyState === 'bad' && 'text-accent')}>
|
||||
{keyState === 'ok' ? t('settings.tmdbActive') : keyState === 'bad' ? t('settings.keyRefused') : keyState === 'testing' ? t('settings.checking') : t('settings.notConfigured')}
|
||||
</span>
|
||||
</div>
|
||||
<p className="mt-1 text-xs leading-relaxed text-ink-3">
|
||||
{t('settings.tmdbHelp')}
|
||||
</p>
|
||||
<div className="mt-3 flex gap-2">
|
||||
<div className="relative flex-1">
|
||||
<input
|
||||
className="field pr-11 text-sm"
|
||||
type={showKey ? 'text' : 'password'}
|
||||
value={keyDraft}
|
||||
onChange={(e) => {
|
||||
setKeyDraft(e.target.value)
|
||||
setKeyState('idle')
|
||||
}}
|
||||
placeholder={t('settings.tmdbKey')}
|
||||
autoComplete="off"
|
||||
autoCapitalize="off"
|
||||
spellCheck={false}
|
||||
/>
|
||||
<button type="button" onClick={() => setShowKey((v) => !v)} className="absolute right-3 top-1/2 -translate-y-1/2 text-ink-3" aria-label={showKey ? t('settings.hideKey') : t('settings.showKey')}>
|
||||
{showKey ? <EyeOff size={17} /> : <Eye size={17} />}
|
||||
</button>
|
||||
</div>
|
||||
<button onClick={saveKey} disabled={keyState === 'testing'} className="btn btn-light px-4 text-sm">
|
||||
{keyDraft.trim() ? t('settings.validate') : t('settings.remove')}
|
||||
</button>
|
||||
</div>
|
||||
<p className="mt-2 text-[11px] text-ink-3">{t('settings.keyLocal')}</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<SectionTitle>Top 5</SectionTitle>
|
||||
<p className="mb-3 text-xs text-ink-3">{t('settings.topHint')}</p>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{TOP_CATEGORIES.map((c) => {
|
||||
const on = settings.topCategories.includes(c.value)
|
||||
return (
|
||||
<button
|
||||
key={c.value}
|
||||
onClick={() =>
|
||||
updateSettings({
|
||||
topCategories: on
|
||||
? settings.topCategories.filter((v) => v !== c.value)
|
||||
: ALL_TOP_CATEGORIES.filter((v) => v === c.value || settings.topCategories.includes(v)),
|
||||
})
|
||||
}
|
||||
className={cx('chip', on && 'chip-on')}
|
||||
aria-pressed={on}
|
||||
>
|
||||
{on && <Check size={14} />}
|
||||
{c.plural}
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
{settings.topCategories.length === 0 && <p className="mt-2 text-xs text-ink-3">{t('settings.topNone')}</p>}
|
||||
|
||||
<SectionTitle>{t('settings.backup')}</SectionTitle>
|
||||
<div className="card divide-y divide-line overflow-hidden">
|
||||
<Row icon={<Download size={19} />} title={t('settings.export')} hint={t('settings.exportHint', { count: items.length })} onClick={onExport} />
|
||||
<Row icon={<Upload size={19} />} title={t('settings.import')} hint={t('settings.importHint')} onClick={() => fileRef.current?.click()} />
|
||||
<input ref={fileRef} type="file" accept="application/json,.json" hidden onChange={(e) => onFile(e.target.files?.[0])} />
|
||||
</div>
|
||||
|
||||
{pending && (
|
||||
<div className="card mt-3 space-y-3 border-ink p-4">
|
||||
<p className="text-sm">
|
||||
{pending.format === 'legacy' && <span className="eyebrow mb-2 block text-ink">{t('settings.legacyDetected')}</span>}
|
||||
{pending.skipped ? t('settings.foundSkipped', { n: pending.items.length, skipped: pending.skipped }) : t('settings.found', { count: pending.items.length })}
|
||||
</p>
|
||||
<div className="grid grid-cols-2 gap-2">
|
||||
<button onClick={() => confirmImport('merge')} className="btn btn-light text-sm">
|
||||
{t('settings.merge')}
|
||||
</button>
|
||||
<button onClick={() => setConfirm('replace')} className="btn btn-ghost text-sm">
|
||||
{t('settings.replaceAll')}
|
||||
</button>
|
||||
</div>
|
||||
<p className="text-xs text-ink-3">{t('settings.mergeHint')}</p>
|
||||
<button onClick={() => setPending(undefined)} className="w-full text-xs text-ink-3">
|
||||
{t('common.cancel')}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<SectionTitle>{t('settings.storage')}</SectionTitle>
|
||||
<div className="card space-y-3.5 p-4 text-sm">
|
||||
<div className="flex items-center gap-3">
|
||||
<HardDrive size={18} className="text-ink-3" />
|
||||
<span className="flex-1 text-ink-2">{t('settings.used')}</span>
|
||||
<span className="text-xs">{usage ?? '—'}</span>
|
||||
</div>
|
||||
<p className="border-t border-line pt-3.5 text-xs leading-relaxed text-ink-3">
|
||||
{account
|
||||
? t('settings.storageCloud')
|
||||
: t('settings.storageLocal')}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<SectionTitle>{t('settings.danger')}</SectionTitle>
|
||||
<div className="card overflow-hidden">
|
||||
<Row icon={<Trash2 size={19} />} title={t('settings.clearAll')} hint={account ? t('settings.clearAllHintCloud', { count: items.length }) : t('settings.clearAllHint', { count: items.length })} onClick={() => setConfirm('reset')} danger />
|
||||
{account && (
|
||||
<div className="border-t border-line">
|
||||
<Row
|
||||
icon={<UserX size={19} />}
|
||||
title={deleting ? t('settings.deleting') : t('settings.deleteAccount')}
|
||||
hint={t('settings.deleteAccountHint')}
|
||||
onClick={() => !deleting && setConfirm('delete-account')}
|
||||
danger
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<p className="mt-10 text-center text-xs text-ink-3">AzuuCine v2.2 · {account ? t('settings.footerCloud') : t('settings.footerLocal')}</p>
|
||||
|
||||
<ConfirmDialog
|
||||
open={confirm === 'reset'}
|
||||
title={t('confirm.title')}
|
||||
message={account ? t('settings.clearConfirmCloud', { count: items.length }) : t('settings.clearConfirm', { count: items.length })}
|
||||
confirmLabel={t('settings.clearAllConfirm')}
|
||||
onConfirm={onReset}
|
||||
onCancel={() => setConfirm(null)}
|
||||
/>
|
||||
<ConfirmDialog
|
||||
open={confirm === 'delete-account'}
|
||||
title={t('settings.deleteAccountTitle')}
|
||||
message={t('settings.deleteAccountMessage')}
|
||||
confirmLabel={t('settings.deleteForever')}
|
||||
onConfirm={onDeleteAccount}
|
||||
onCancel={() => setConfirm(null)}
|
||||
/>
|
||||
<ConfirmDialog
|
||||
open={confirm === 'replace'}
|
||||
title={t('confirm.title')}
|
||||
message={t('settings.replaceConfirm')}
|
||||
confirmLabel={t('settings.replace')}
|
||||
onConfirm={() => confirmImport('replace')}
|
||||
onCancel={() => setConfirm(null)}
|
||||
/>
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,429 @@
|
||||
import { genreLabel } from '../lib/genres'
|
||||
import { locale, t } from '../i18n'
|
||||
import { Star } from 'lucide-react'
|
||||
import { useMemo, useState, type ReactNode } from 'react'
|
||||
import Disagreements from '../components/Disagreements'
|
||||
import Poster from '../components/Poster'
|
||||
import { EmptyState, PageHeader, SectionTitle } from '../components/ui'
|
||||
import { MEDIA_TYPES, STATUSES } from '../lib/constants'
|
||||
import { availableYears, computeStats, countries, itemsForPeriod, monthly, records, watchMinutes } from '../lib/stats'
|
||||
import { cx, formatDuration, formatRating } from '../lib/utils'
|
||||
import { useMedia } from '../store'
|
||||
import type { MediaItem, MediaType } from '../types'
|
||||
|
||||
/** Couleurs des types (palette catégorielle validée pour fond sombre, ordre fixe). */
|
||||
const TYPE_COLORS: Record<MediaType, string> = {
|
||||
film: '#3987e5',
|
||||
serie: '#d95926',
|
||||
anime: '#199e70',
|
||||
kdrama: '#c98500',
|
||||
cdrama: '#d55181',
|
||||
autre: '#008300',
|
||||
}
|
||||
|
||||
type Tab = 'overview' | 'habits' | 'tastes'
|
||||
const TABS: { value: Tab; readonly label: string }[] = [
|
||||
{ value: 'overview', get label() { return t('stats.overview') } },
|
||||
{ value: 'habits', get label() { return t('stats.habits') } },
|
||||
{ value: 'tastes', get label() { return t('stats.tastes') } },
|
||||
]
|
||||
|
||||
const fmtInt = (n: number) => n.toLocaleString(locale())
|
||||
|
||||
/** Colonnes verticales d'une seule couleur ; toucher une colonne affiche sa valeur. */
|
||||
function Columns({
|
||||
data,
|
||||
format,
|
||||
height = 140,
|
||||
selected,
|
||||
onSelect,
|
||||
}: {
|
||||
data: { key: string; label: string; value: number }[]
|
||||
format: (v: number) => string
|
||||
height?: number
|
||||
selected?: string
|
||||
onSelect: (key: string) => void
|
||||
}) {
|
||||
const max = Math.max(1, ...data.map((d) => d.value))
|
||||
return (
|
||||
<div>
|
||||
<div className="flex items-end gap-1.5" style={{ height }}>
|
||||
{data.map((d) => {
|
||||
const on = d.key === selected
|
||||
return (
|
||||
<button
|
||||
key={d.key}
|
||||
onClick={() => onSelect(d.key)}
|
||||
className="group relative flex h-full flex-1 items-end"
|
||||
aria-label={`${d.label} : ${format(d.value)}`}
|
||||
title={`${d.label} : ${format(d.value)}`}
|
||||
>
|
||||
<span
|
||||
className={cx('w-full rounded-t-[4px] transition-colors', on ? 'bg-accent' : 'bg-accent/45')}
|
||||
style={{ height: `${(d.value / max) * 100}%`, minHeight: d.value ? 3 : 0 }}
|
||||
/>
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
<div className="mt-2 flex gap-1.5 border-t border-line pt-1.5">
|
||||
{data.map((d) => (
|
||||
<span key={d.key} className={cx('flex-1 text-center text-[10px]', d.key === selected ? 'font-semibold text-ink' : 'text-ink-3')}>
|
||||
{d.label}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function Tile({ label, value, hint }: { label: string; value: ReactNode; hint?: string }) {
|
||||
return (
|
||||
<div className="card p-4">
|
||||
<div className="eyebrow">{label}</div>
|
||||
<div className="mt-2 text-2xl font-bold leading-none tabular-nums">{value}</div>
|
||||
{hint && <div className="mt-1.5 text-xs text-ink-3">{hint}</div>}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function MiniPoster({ item, caption }: { item: MediaItem; caption: string }) {
|
||||
return (
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="w-12 shrink-0">
|
||||
<Poster src={item.poster} title={item.title} />
|
||||
</div>
|
||||
<div className="min-w-0">
|
||||
<p className="truncate text-sm font-semibold">{item.title}</p>
|
||||
<p className="text-xs text-ink-3">{caption}</p>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default function StatsPage() {
|
||||
const { items, settings, loading } = useMedia()
|
||||
const scale = settings.ratingScale
|
||||
const years = useMemo(() => availableYears(items), [items])
|
||||
const [year, setYear] = useState('')
|
||||
const [tab, setTab] = useState<Tab>('overview')
|
||||
const [metric, setMetric] = useState<'count' | 'minutes'>('count')
|
||||
const [month, setMonth] = useState<string>()
|
||||
const [ratingBin, setRatingBin] = useState<string>()
|
||||
|
||||
const scoped = useMemo(() => itemsForPeriod(items, year), [items, year])
|
||||
const s = useMemo(() => computeStats(scoped), [scoped])
|
||||
const months = useMemo(() => monthly(items, year), [items, year])
|
||||
const geo = useMemo(() => countries(scoped), [scoped])
|
||||
const rec = useMemo(() => records(scoped), [scoped])
|
||||
|
||||
if (loading) return <PageHeader title={t('stats.pageTitle')} accent={t('stats.pageAccent')} />
|
||||
if (items.length === 0) {
|
||||
return (
|
||||
<>
|
||||
<PageHeader title={t('stats.pageTitle')} accent={t('stats.pageAccent')} />
|
||||
<EmptyState title={t('stats.emptyTitle')} text={t('stats.emptyText')} />
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
const hours = Math.round(s.totalMinutes / 60)
|
||||
const days = s.totalMinutes / 1440
|
||||
const typeTotal = s.byType.reduce((sum, bt) => sum + bt.minutes, 0)
|
||||
const typeRows = s.byType.filter((bt) => bt.value > 0).sort((a, b) => b.minutes - a.minutes)
|
||||
|
||||
// Mois sélectionné par défaut : le plus chargé
|
||||
const busiest = months.reduce((best, m) => (m[metric] > best[metric] ? m : best), months[0])
|
||||
const shownMonth = months.find((m) => m.key === month) ?? busiest
|
||||
|
||||
// Histogramme des notes
|
||||
const ratingCols =
|
||||
scale === '5'
|
||||
? s.ratingBuckets.map((v, i) => ({ key: String(i), label: formatRating(i + 1, '5'), value: v }))
|
||||
: s.ratingBuckets.map((v, i) => ({ key: String(i), label: String(i + 1), value: v }))
|
||||
const shownRating = ratingCols.find((c) => c.key === ratingBin) ?? ratingCols.reduce((a, b) => (b.value > a.value ? b : a), ratingCols[0])
|
||||
|
||||
const maxGenre = Math.max(1, ...s.topGenres.map((g) => g.value))
|
||||
const maxCountry = Math.max(1, ...geo.list.map((c) => c.count))
|
||||
const periodLabel = year || t('stats.sinceStart')
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageHeader title={t('stats.pageTitle')} accent={t('stats.pageAccent')} subtitle={year ? t('stats.subtitleYear', { count: s.total, year }) : t('stats.subtitle', { count: s.total })} />
|
||||
|
||||
{/* Période + onglets, collants en haut */}
|
||||
<div className="sticky top-0 z-20 -mx-4 space-y-2.5 bg-bg/95 px-4 pb-3 pt-[max(0.5rem,env(safe-area-inset-top))] backdrop-blur-md">
|
||||
<div className="no-scrollbar -mx-4 flex gap-2 overflow-x-auto px-4">
|
||||
{['', ...years].map((y) => (
|
||||
<button key={y || 'all'} onClick={() => setYear(y)} className={cx('chip py-1! text-[13px]', year === y && 'chip-on')}>
|
||||
{y || t('common.all')}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<div className="grid grid-cols-3 gap-1 rounded-full border border-line p-1">
|
||||
{TABS.map((tb) => (
|
||||
<button
|
||||
key={tb.value}
|
||||
onClick={() => setTab(tb.value)}
|
||||
className={cx('rounded-full py-2 text-xs font-semibold transition-colors', tab === tb.value ? 'bg-ink text-bg' : 'text-ink-3')}
|
||||
>
|
||||
{tb.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{tab === 'overview' && (
|
||||
<>
|
||||
{/* Le grand chiffre */}
|
||||
<div className="card mt-3 p-5">
|
||||
<span className="eyebrow">{t('home.screenTime')} · {periodLabel}</span>
|
||||
<div className="mt-2 flex items-baseline gap-2">
|
||||
<span className="text-5xl font-bold tabular-nums leading-none">{fmtInt(hours)}</span>
|
||||
<span className="text-xl font-semibold text-accent">{t('stats.hours', { count: hours })}</span>
|
||||
</div>
|
||||
<p className="mt-2 text-sm text-ink-2">
|
||||
{t('stats.nonStopPre')}
|
||||
<span className="font-semibold text-ink">{days >= 1 ? t('stats.days', { count: Math.round(days) }) : formatDuration(s.totalMinutes)}</span>
|
||||
{t('stats.nonStopPost')}
|
||||
{' · '}
|
||||
{t('stats.finishedN', { count: s.completed })} · {t('stats.episodesN', { count: s.episodesWatched })}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Répartition par type : barre empilée + légende */}
|
||||
<SectionTitle>{t('stats.timeByType')}</SectionTitle>
|
||||
{typeTotal > 0 ? (
|
||||
<>
|
||||
<div className="flex h-4 gap-[2px] overflow-hidden rounded-full">
|
||||
{typeRows.map((row) =>
|
||||
row.minutes > 0 ? (
|
||||
<span key={row.type} style={{ flexGrow: row.minutes, background: TYPE_COLORS[row.type] }} title={`${row.label} : ${formatDuration(row.minutes)}`} />
|
||||
) : null,
|
||||
)}
|
||||
</div>
|
||||
<ul className="mt-4 space-y-2.5">
|
||||
{typeRows.map((row) => (
|
||||
<li key={row.type} className="flex items-center gap-3 text-sm">
|
||||
<span className="size-3 shrink-0 rounded-full" style={{ background: TYPE_COLORS[row.type] }} />
|
||||
<span className="flex-1 text-ink-2">{row.label}</span>
|
||||
<span className="text-xs text-ink-3">{t('journal.seen', { count: row.completed })}</span>
|
||||
<span className="w-16 text-right text-xs font-semibold tabular-nums">{formatDuration(row.minutes)}</span>
|
||||
<span className="w-10 text-right text-xs tabular-nums text-ink-3">{Math.round((row.minutes / typeTotal) * 100)} %</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</>
|
||||
) : (
|
||||
<p className="text-sm text-ink-3">{t('stats.noTime')}</p>
|
||||
)}
|
||||
|
||||
<div className="mt-8 grid grid-cols-2 gap-3">
|
||||
<Tile
|
||||
label={t('stats.avgRating')}
|
||||
value={
|
||||
s.avgRating != null ? (
|
||||
<span className="flex items-center gap-1.5">
|
||||
<Star size={20} className="fill-accent text-accent" />
|
||||
{formatRating(Math.round(s.avgRating * 10) / 10, scale)}
|
||||
<span className="text-sm font-normal text-ink-3">/{scale}</span>
|
||||
</span>
|
||||
) : (
|
||||
'—'
|
||||
)
|
||||
}
|
||||
hint={t('stats.rated', { count: s.ratedCount })}
|
||||
/>
|
||||
<Tile label={t('home.completed')} value={fmtInt(s.completed)} hint={year ? t('stats.inYear', { year }) : t('home.thisYear', { count: s.completedThisYear })} />
|
||||
</div>
|
||||
|
||||
{/* Statuts en pastilles */}
|
||||
<SectionTitle>{t('stats.statuses')}</SectionTitle>
|
||||
<div className="grid grid-cols-5 gap-2 text-center">
|
||||
{s.byStatus.map((st) => (
|
||||
<div key={st.status} className="rounded-2xl border border-line py-3">
|
||||
<div className="text-lg font-bold tabular-nums">{st.value}</div>
|
||||
<div className="mt-0.5 text-[10px] leading-tight text-ink-3">{STATUSES.find((x) => x.value === st.status)?.label}</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
{tab === 'habits' && (
|
||||
<>
|
||||
<SectionTitle
|
||||
action={
|
||||
<div className="flex rounded-full border border-line p-0.5">
|
||||
{(['count', 'minutes'] as const).map((m) => (
|
||||
<button
|
||||
key={m}
|
||||
onClick={() => setMetric(m)}
|
||||
className={cx('rounded-full px-2.5 py-0.5 text-[11px] font-semibold', metric === m ? 'bg-ink text-bg' : 'text-ink-3')}
|
||||
>
|
||||
{m === 'count' ? t('catalog.titles') : t('stats.hoursTab')}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
}
|
||||
>
|
||||
{year ? t('stats.monthByMonth', { year }) : t('stats.last12')}
|
||||
</SectionTitle>
|
||||
<div className="card p-4">
|
||||
<p className="mb-4 text-sm">
|
||||
<span className="font-semibold capitalize">{new Date(`${shownMonth.key}-15T12:00:00`).toLocaleDateString(locale(), { month: 'long', year: 'numeric' })}</span>
|
||||
<span className="text-ink-2">
|
||||
{' · '}
|
||||
{t('stats.monthFinished', { count: shownMonth.count })} · {formatDuration(shownMonth.minutes)}
|
||||
</span>
|
||||
</p>
|
||||
<Columns
|
||||
data={months.map((m) => ({ key: m.key, label: m.initial, value: metric === 'count' ? m.count : m.minutes }))}
|
||||
format={(v) => (metric === 'count' ? t('account.nTitles', { count: v }) : formatDuration(v))}
|
||||
selected={shownMonth.key}
|
||||
onSelect={setMonth}
|
||||
/>
|
||||
{busiest[metric] > 0 && (
|
||||
<p className="mt-3 text-xs text-ink-3">
|
||||
{t('stats.busiest')} <span className="text-ink">{new Date(`${busiest.key}-15T12:00:00`).toLocaleDateString(locale(), { month: 'long', year: 'numeric' })}</span>
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<SectionTitle>{t('stats.records')}</SectionTitle>
|
||||
<div className="space-y-3">
|
||||
{rec.marathon && (
|
||||
<div className="card p-3.5">
|
||||
<span className="eyebrow text-accent">{t('stats.marathon')}</span>
|
||||
<div className="mt-2">
|
||||
<MiniPoster item={rec.marathon.item} caption={`${t('stats.episodesN', { count: rec.marathon.episodes })} · ${formatDuration(watchMinutes(rec.marathon.item))}`} />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{rec.longestFilm && (
|
||||
<div className="card p-3.5">
|
||||
<span className="eyebrow text-accent">{t('stats.longestFilm')}</span>
|
||||
<div className="mt-2">
|
||||
<MiniPoster item={rec.longestFilm} caption={formatDuration(rec.longestFilm.duration ?? 0)} />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{!rec.marathon && !rec.longestFilm && <p className="text-sm text-ink-3">{t('stats.noRecords')}</p>}
|
||||
</div>
|
||||
|
||||
{s.topPlatforms.length > 0 && (
|
||||
<>
|
||||
<SectionTitle>{t('stats.platforms')}</SectionTitle>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{s.topPlatforms.map((p, i) => (
|
||||
<span key={p.label} className={cx('chip', i === 0 && 'chip-on')}>
|
||||
{p.label}
|
||||
<span className="text-xs opacity-60">{p.value}</span>
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
|
||||
{tab === 'tastes' && (
|
||||
<>
|
||||
{rec.bestRated && rec.bestRated.length > 0 && (
|
||||
<>
|
||||
<SectionTitle>{t('stats.bestRated')} · {periodLabel}</SectionTitle>
|
||||
<div className="no-scrollbar -mx-4 flex gap-3 overflow-x-auto px-4 pb-1">
|
||||
{rec.bestRated.map((item) => (
|
||||
<div key={item.id} className="w-24 shrink-0">
|
||||
<Poster src={item.poster} title={item.title} />
|
||||
<p className="mt-1.5 truncate text-xs font-medium text-ink-2">{item.title}</p>
|
||||
<p className="flex items-center gap-1 text-[11px] text-ink-3">
|
||||
<Star size={10} className="fill-accent text-accent" />
|
||||
{formatRating(item.rating, scale)}
|
||||
</p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
<SectionTitle>{t('stats.myRatings')}</SectionTitle>
|
||||
{s.ratedCount > 0 ? (
|
||||
<div className="card p-4">
|
||||
<p className="mb-4 text-sm">
|
||||
<span className="font-semibold">{t('account.nTitles', { count: shownRating.value })}</span>
|
||||
<span className="text-ink-2"> {t('stats.ratedAs', { count: shownRating.value, rating: `${shownRating.label}${scale === '5' ? ' ★' : '/10'}` })}</span>
|
||||
</p>
|
||||
<Columns data={ratingCols} format={(v) => t('account.nTitles', { count: v })} height={110} selected={shownRating.key} onSelect={setRatingBin} />
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-sm text-ink-3">{t('stats.noRatings')}</p>
|
||||
)}
|
||||
|
||||
<Disagreements scoped={scoped} />
|
||||
|
||||
<SectionTitle>{t('stats.favGenres')}</SectionTitle>
|
||||
{s.topGenres.length ? (
|
||||
<div className="flex flex-wrap items-baseline gap-x-4 gap-y-2">
|
||||
{s.topGenres.map((g, i) => {
|
||||
const r = g.value / maxGenre
|
||||
return (
|
||||
<span
|
||||
key={g.label}
|
||||
className={cx('font-bold leading-tight', i === 0 ? 'text-accent' : r > 0.6 ? 'text-ink' : 'text-ink-2')}
|
||||
style={{ fontSize: `${0.85 + r * 1.15}rem` }}
|
||||
title={t('account.nTitles', { count: g.value })}
|
||||
>
|
||||
{genreLabel(g.label)}
|
||||
<sup className="ml-0.5 text-[10px] font-medium text-ink-3">{g.value}</sup>
|
||||
</span>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-sm text-ink-3">{t('stats.noGenres')}</p>
|
||||
)}
|
||||
|
||||
<SectionTitle>{t('stats.countries')}</SectionTitle>
|
||||
{geo.list.length ? (
|
||||
<ul className="space-y-3">
|
||||
{geo.list.slice(0, 8).map((c) => (
|
||||
<li key={c.code} className="flex items-center gap-3 text-sm">
|
||||
<span className="w-7 text-center text-xl leading-none">{c.flag}</span>
|
||||
<span className="w-28 truncate text-ink-2">{c.name}</span>
|
||||
<span className="h-2 flex-1 overflow-hidden rounded-full bg-surface-2">
|
||||
<span className="block h-full rounded-full bg-accent" style={{ width: `${(c.count / maxCountry) * 100}%` }} />
|
||||
</span>
|
||||
<span className="w-8 text-right text-xs font-semibold tabular-nums">{c.count}</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
) : null}
|
||||
{geo.missing > 0 && (
|
||||
<p className="mt-3 text-xs text-ink-3">
|
||||
{geo.list.length === 0 ? t('stats.noCountryLegacy', { count: geo.missing }) : t('stats.noCountry', { count: geo.missing })}
|
||||
</p>
|
||||
)}
|
||||
|
||||
<SectionTitle>{t('stats.byType')}</SectionTitle>
|
||||
<div className="grid grid-cols-3 gap-2">
|
||||
{MEDIA_TYPES.map((mt) => {
|
||||
const row = s.byType.find((b) => b.type === mt.value)!
|
||||
return (
|
||||
<div key={mt.value} className="rounded-2xl border border-line p-3">
|
||||
<span className="mb-2 block h-1 w-6 rounded-full" style={{ background: TYPE_COLORS[mt.value] }} />
|
||||
<div className="text-xl font-bold tabular-nums">{row.value}</div>
|
||||
<div className="text-[11px] text-ink-3">{mt.label}</div>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
<p className="mt-8 text-xs text-ink-3">
|
||||
{t('stats.footnote')}
|
||||
</p>
|
||||
</>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user