correction bug
deploy / deploy (push) Successful in 31s

This commit is contained in:
Romain committed 2026-10-04 13:38:33 +02:00
1 parent eaad6f1e77
commit a5da756803
51 files changed
+537 -672

No files matched your search

+2 -7
View File
@@ -1,5 +1,5 @@
import { t } from '../i18n'
import { useEffect } from 'react'
import { useEscape } from '../lib/escape'
interface Props {
open: boolean
@@ -12,12 +12,7 @@ interface Props {
/** Fenêtre « Êtes-vous sûr ? » intégrée à l'app (plus fiable que window.confirm sur mobile). */
export default function ConfirmDialog({ open, title, message, confirmLabel = t('common.confirm'), onConfirm, onCancel }: Props) {
useEffect(() => {
if (!open) return
const onKey = (e: KeyboardEvent) => e.key === 'Escape' && onCancel()
window.addEventListener('keydown', onKey)
return () => window.removeEventListener('keydown', onKey)
}, [open, onCancel])
useEscape(onCancel, open)
if (!open) return null
return (
+2 -1
View File
@@ -39,13 +39,14 @@ export default function DatabaseSearch({ onPick, initialQuery = '', currentExter
// Recherche avec un petit délai pendant la frappe
useEffect(() => {
const q = query.trim()
// Toute réponse d'une recherche précédente devient caduque
const id = ++requestId.current
setError(undefined)
if (q.length < 2) {
setResults([])
setLoading(false)
return
}
const id = ++requestId.current
setLoading(true)
const timer = setTimeout(async () => {
try {
+8 -2
View File
@@ -23,7 +23,13 @@ export default function EpisodeList({ form, onChange }: Props) {
const { settings } = useMedia()
const seasons = form.seasons
const pos = seasonPosition(form)
const [viewSeason, setViewSeason] = useState(pos?.season ?? 1)
const [picked, setViewSeason] = useState(pos?.season ?? 1)
// La saison affichée suit la progression (bouton « Vu : S2 · É1 » de l'en-tête) et reste dans les limites
const current = pos?.season
useEffect(() => {
if (current) setViewSeason(current)
}, [current])
const viewSeason = seasons ? Math.min(Math.max(1, picked), seasons.length) : 1
const [episodes, setEpisodes] = useState<EpisodeInfo[]>()
const [loading, setLoading] = useState(false)
const listRef = useRef<HTMLDivElement>(null)
@@ -33,7 +39,7 @@ export default function EpisodeList({ form, onChange }: Props) {
// Taille de la saison affichée (ou de toute la série si on ne connaît pas le découpage)
const before = seasons ? episodesBeforeSeason(seasons, viewSeason) : 0
const size = seasons ? seasons[viewSeason - 1] : Math.min(episodeCap(form) ?? 0, MAX_GENERIC)
const size = seasons ? (seasons[viewSeason - 1] ?? 0) : Math.min(episodeCap(form) ?? 0, MAX_GENERIC)
useEffect(() => {
if (!isTmdb || !navigator.onLine) return setEpisodes(undefined)
+1 -1
View File
@@ -15,7 +15,7 @@ export function nextEpisodeLabel(item: MediaItem): string | undefined {
if (cap && item.episodesWatched >= cap) return undefined
const pos = seasonPosition({ ...item, episodesWatched: item.episodesWatched + 1, season: undefined })
const ep = t('episodes.short', { n: pos ? pos.episode : item.episodesWatched + 1 })
return pos ? `S${pos.season} · ${ep}` : ep
return pos ? `${t('episodes.seasonShort', { n: pos.season })} · ${ep}` : ep
}
/** Grande bannière de l'accueil : défile entre les titres que je regarde en ce moment (ou le prochain à voir). */
+4 -37
View File
@@ -9,18 +9,19 @@ import Poster from './Poster'
import { RatingBadge } from './Rating'
function Progress({ item }: { item: MediaItem }) {
if (!TYPE_BY_VALUE[item.type].episodic || (!item.episodesWatched && !item.episodesTotal)) return null
const cap = episodeCap(item)
if (!TYPE_BY_VALUE[item.type].episodic || (!item.episodesWatched && !cap)) return null
// Série en plusieurs saisons : progression dans la saison en cours
const pos = seasonPosition(item)
const done = pos ? pos.episode : item.episodesWatched
const size = pos ? pos.size : item.episodesTotal
const size = pos ? pos.size : cap
const pct = size ? Math.min(100, (done / size) * 100) : 0
const season = pos?.season ?? item.season
return (
<div className="mt-1.5">
<div className="flex justify-between text-[10.5px] text-ink-3">
<span>
{season ? `S${season} · ` : ''}{t('card.ep', { n: done })}
{season ? `${t('episodes.seasonShort', { n: season })} · ` : ''}{t('card.ep', { n: done })}
{size ? `/${size}` : ''}
</span>
</div>
@@ -72,37 +73,3 @@ export function MediaCard({ item, onOpen }: { item: MediaItem; onOpen: (item: Me
</article>
)
}
/** Ligne horizontale (accueil : « En cours »), avec compteur +1. */
export function MediaRow({ item, onOpen }: { item: MediaItem; onOpen: (item: MediaItem) => void }) {
const { settings, incrementEpisode } = useMedia()
const episodic = TYPE_BY_VALUE[item.type].episodic
const done = !!episodeCap(item) && item.episodesWatched >= episodeCap(item)!
return (
<article className="card flex items-center gap-3.5 p-3">
<button onClick={() => onOpen(item)} className="flex min-w-0 flex-1 items-center gap-3 text-left">
<div className="w-14 shrink-0">
<Poster src={item.poster} title={item.title} />
</div>
<div className="min-w-0 flex-1">
<div className="flex items-center gap-2">
<TypeBadge item={item} />
<RatingBadge value={item.rating} scale={settings.ratingScale} />
</div>
<h3 className="mt-1.5 truncate text-[15px] font-semibold leading-tight">{item.title}</h3>
{episodic ? <Progress item={item} /> : <StatusPill status={item.status} />}
</div>
</button>
{episodic && !done && (
<button
onClick={() => incrementEpisode(item.id)}
className="flex h-10 shrink-0 items-center gap-0.5 rounded-full border border-accent px-3.5 text-sm text-accent transition-colors active:bg-accent-fill active:text-on-accent"
aria-label={t('card.plusOne', { title: item.title })}
>
<Plus size={14} strokeWidth={2.5} />1
</button>
)}
</article>
)
}
+5 -9
View File
@@ -209,7 +209,7 @@ export default function MediaForm({ item, onClose, onGoToSettings, onOpenItem }:
if (cap && form.episodesWatched >= cap) return { label: t('hero.allSeen'), done: true }
const nextPos = seasonPosition({ ...form, episodesWatched: form.episodesWatched + 1, season: undefined })
const ep = t('episodes.short', { n: nextPos ? nextPos.episode : form.episodesWatched + 1 })
const label = t('hero.seenEp', { ep: nextPos ? `S${nextPos.season} · ${ep}` : ep })
const label = t('hero.seenEp', { ep: nextPos ? `${t('episodes.seasonShort', { n: nextPos.season })} · ${ep}` : ep })
return { label, onClick: () => setForm((f) => withEpisodes(f, f.episodesWatched + 1)) }
}
if (form.status === 'termine') return { label: t('hero.seen'), done: true }
@@ -259,13 +259,8 @@ export default function MediaForm({ item, onClose, onGoToSettings, onOpenItem }:
return next
})
const changeEpisodes = (delta: number) =>
setForm((f) => {
let n = Math.max(0, f.episodesWatched + delta)
const cap = episodeCap(f)
if (cap) n = Math.min(n, cap)
return { ...f, episodesWatched: n }
})
// Même règles que la liste d'épisodes : le statut et les dates suivent
const changeEpisodes = (delta: number) => setForm((f) => withEpisodes(f, f.episodesWatched + delta))
const onPickImage = async (file?: File) => {
if (!file) return
@@ -468,7 +463,8 @@ export default function MediaForm({ item, onClose, onGoToSettings, onOpenItem }:
{/* Épisodes / durée */}
{typeInfo.episodic ? (
<Section title={t('form.episodes')}>
{form.seasons || form.episodesTotal ? (
{/* Liste d'épisodes pour une fiche liée (TMDB / AniList) ; compteur + total modifiable pour une fiche manuelle */}
{form.seasons || (form.externalId && form.episodesTotal) ? (
<EpisodeList form={form} onChange={(n, season) => setForm((f) => withEpisodes(f, n, season))} />
) : (
<div className="card space-y-5 p-4">
-120
View File
@@ -1,120 +0,0 @@
import { locale, t } from '../i18n'
import { Loader2, RefreshCw } from 'lucide-react'
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { loadAiring, needsCheck, novelties, refreshAiring, saveAiring, trackable, type AiringCache } from '../lib/airing'
import { formatDate, todayISO } from '../lib/utils'
import { useMedia } from '../store'
import type { MediaItem } from '../types'
import Poster from './Poster'
import { SectionTitle } from './ui'
const dayLabel = (iso: string) => {
const d = new Date(iso + 'T12:00:00')
const diff = Math.round((d.getTime() - new Date(todayISO() + 'T12:00:00').getTime()) / 86400000)
if (diff <= 0) return t('time.today')
if (diff === 1) return t('time.tomorrow')
if (diff < 7) return d.toLocaleDateString(locale(), { weekday: 'long' })
return t('time.onDate', { date: formatDate(iso) })
}
/** Section « Nouveautés » de l'accueil : nouveaux épisodes et nouvelles saisons. */
export default function NewEpisodes({ onOpen }: { onOpen: (item: MediaItem) => void }) {
const { items, loading, settings, patchMany, update } = useMedia()
const [cache, setCache] = useState<AiringCache>(loadAiring)
const [checking, setChecking] = useState(false)
const started = useRef(false)
const check = useCallback(
async (force = false) => {
setChecking(true)
try {
const next = await refreshAiring(items, loadAiring(), settings.tmdbKey, force)
saveAiring(next)
setCache(next)
// Met à jour le nombre total d'épisodes des séries en cours si de nouveaux sont sortis
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) await patchMany(patches)
} finally {
setChecking(false)
}
},
[items, settings.tmdbKey, patchMany],
)
// Vérification automatique au plus toutes les 12 h, au lancement
useEffect(() => {
if (loading || started.current || !navigator.onLine) return
started.current = true
const c = loadAiring()
if (trackable(items).some((i) => needsCheck(i, c))) void check()
}, [loading, items, check])
const list = useMemo(() => novelties(items, cache), [items, cache])
const tracked = trackable(items).length
const hasAniList = trackable(items).some((i) => i.externalId!.startsWith('anilist:'))
if (!tracked) return null
const resume = (item: MediaItem, aired: number) =>
update(item.id, { status: 'en_cours', episodesTotal: aired, startDate: item.startDate ?? todayISO(), endDate: undefined })
return (
<>
<SectionTitle
action={
<button onClick={() => check(true)} disabled={checking} className="flex items-center gap-1.5 text-xs font-medium text-ink-3">
{checking ? <Loader2 size={13} className="animate-spin" /> : <RefreshCw size={13} />}
{checking ? t('settings.checking') : t('newEp.check')}
</button>
}
>
{t('newEp.title')}
</SectionTitle>
{list.length === 0 ? (
<p className="text-sm text-ink-3">
{checking
? t('newEp.checking')
: !settings.tmdbKey && !hasAniList
? t('newEp.needKey')
: t('newEp.nothing', { count: tracked })}
{!checking && !settings.tmdbKey && hasAniList && ` ${t('newEp.needKeyAlso')}`}
</p>
) : (
<div className="no-scrollbar -mx-4 flex gap-3 overflow-x-auto px-4 pb-1">
{list.map(({ item, info, unwatched, kind }) => (
<div key={item.id} className="card flex w-64 shrink-0 gap-3 p-2.5">
<button onClick={() => onOpen(item)} className="w-14 shrink-0">
<Poster src={item.poster} title={item.title} />
</button>
<div className="flex min-w-0 flex-1 flex-col">
<span className="eyebrow text-accent">
{kind === 'new_season' ? t('newEp.newSeason') : kind === 'new_episodes' ? t('newEp.catchUp') : t('newEp.soon')}
</span>
<button onClick={() => onOpen(item)} className="mt-1 truncate text-left text-sm font-semibold">
{item.title}
</button>
<span className="mt-0.5 text-xs text-ink-2">
{kind === 'upcoming'
? t('newEp.epWhen', { ep: info.next!.episode, when: dayLabel(info.next!.date) })
: t('newEp.available', { count: unwatched })}
</span>
{kind !== 'upcoming' && info.next && (
<span className="text-[11px] text-ink-3">
{t('newEp.next', { ep: info.next.episode, when: dayLabel(info.next.date) })}
</span>
)}
{kind === 'new_season' && (
<button onClick={() => resume(item, info.aired)} className="mt-auto self-start pt-1.5 text-xs font-semibold text-accent">
{t('newEp.resume')} →
</button>
)}
</div>
</div>
))}
</div>
)}
</>
)
}
+4 -3
View File
@@ -3,14 +3,15 @@ import { cx } from '../lib/utils'
/** Affiche du média, ou une vignette sobre (aplat + initiale en serif) si aucune image. */
export default function Poster({ src, title, className }: { src?: string; title: string; className?: string }) {
const [broken, setBroken] = useState(false)
if (src && !broken) {
// On retient quelle image a échoué (une nouvelle affiche doit retenter)
const [broken, setBroken] = useState<string>()
if (src && broken !== src) {
return (
<img
src={src}
alt=""
loading="lazy"
onError={() => setBroken(true)}
onError={() => setBroken(src)}
className={cx('aspect-[2/3] w-full rounded-xl border border-line bg-surface-2 object-cover', className)}
/>
)
+3 -2
View File
@@ -61,13 +61,14 @@ export function RatingInput({ value, onChange, scale, size = 'lg', label }: Inpu
const stars = (value ?? 0) / 2
const pick = (e: MouseEvent<HTMLButtonElement>, index: number) => {
const rect = e.currentTarget.getBoundingClientRect()
const half = e.clientX - rect.left < rect.width / 2
// Clavier (Entrée / Espace) : pas de position de clic, on donne l'étoile entière
const half = e.detail !== 0 && e.clientX - rect.left < rect.width / 2
const next = (index + (half ? 0.5 : 1)) * 2
onChange(next === value ? undefined : next) // retoucher la même valeur efface la note
}
return (
<div className="flex items-center gap-1" role="group" aria-label={label ?? 'Note sur 5'}>
<div className="flex items-center gap-1" role="group" aria-label={label ?? t('rating.outOf5')}>
{Array.from({ length: 5 }, (_, i) => {
const fill = Math.max(0, Math.min(1, stars - i))
return (
+15 -9
View File
@@ -3,6 +3,7 @@ import { locale, t } from '../i18n'
import { Check, Dices, RotateCcw, X } from 'lucide-react'
import { useEffect, useLayoutEffect, useMemo, useRef, useState, type TransitionEvent } from 'react'
import { MEDIA_TYPES, TYPE_BY_VALUE } from '../lib/constants'
import { episodeCap } from '../lib/franchise'
import {
buildPool,
loadFilters,
@@ -61,6 +62,8 @@ export default function Roulette({ onClose, onOpen }: Props) {
const pending = useRef<MediaItem | undefined>(undefined)
const spinningRef = useRef(false)
const resultRef = useRef<MediaItem | undefined>(undefined)
const timers = useRef<number[]>([])
useEffect(() => () => timers.current.forEach((x) => clearTimeout(x)), [])
resultRef.current = result
const xFor = (index: number, jitter = 0) => {
@@ -115,12 +118,15 @@ export default function Roulette({ onClose, onOpen }: Props) {
setAnimate(false)
setOffset(xFor(2))
// On place le rouleau au départ, puis on lance l'animation juste après
window.setTimeout(() => {
setAnimate(true)
setOffset(xFor(TARGET, (Math.random() - 0.5) * (CARD - 30)))
}, 40)
// Filet de sécurité si l'événement de fin d'animation n'arrive pas (onglet en arrière-plan…)
window.setTimeout(finishSpin, SPIN_MS + 400)
timers.current.forEach((x) => clearTimeout(x))
timers.current = [
window.setTimeout(() => {
setAnimate(true)
setOffset(xFor(TARGET, (Math.random() - 0.5) * (CARD - 30)))
}, 40),
// Filet de sécurité si l'événement de fin d'animation n'arrive pas (onglet en arrière-plan…)
window.setTimeout(finishSpin, SPIN_MS + 400),
]
}
const finishSpin = () => {
@@ -214,7 +220,7 @@ export default function Roulette({ onClose, onOpen }: Props) {
{result.year && <span>{result.year}</span>}
<span>
{TYPE_BY_VALUE[result.type].episodic
? `${result.episodesTotal ? `${t('roulette.nEps', { n: result.episodesTotal })} · ` : ''}${t('roulette.perEp', { duration: formatDuration(sessionMinutes(result)) })}`
? `${episodeCap(result) ? `${t('roulette.nEps', { n: episodeCap(result)! })} · ` : ''}${t('roulette.perEp', { duration: formatDuration(sessionMinutes(result)) })}`
: formatDuration(sessionMinutes(result))}
</span>
{result.platform && <span>· {result.platform}</span>}
@@ -222,8 +228,8 @@ export default function Roulette({ onClose, onOpen }: Props) {
</div>
{result.status === 'pause' && (
<p className="mt-2 text-xs text-ink-2">
{result.episodesTotal
? t('roulette.stoppedAtOf', { ep: result.episodesWatched, total: result.episodesTotal })
{episodeCap(result)
? t('roulette.stoppedAtOf', { ep: result.episodesWatched, total: episodeCap(result)! })
: t('roulette.stoppedAt', { ep: result.episodesWatched })}
</p>
)}
+2 -5
View File
@@ -2,6 +2,7 @@ import { t } from '../i18n'
import { Download, Share2, X } from 'lucide-react'
import { useEffect, useMemo, useState } from 'react'
import { shareImage } from '../lib/shareCard'
import { useEscape } from '../lib/escape'
interface Props {
blob: Blob
@@ -28,11 +29,7 @@ export default function SharePreview({ blob, filename, title, onClose }: Props)
setUrl(u)
return () => URL.revokeObjectURL(u)
}, [blob])
useEffect(() => {
const onKey = (e: KeyboardEvent) => e.key === 'Escape' && onClose()
window.addEventListener('keydown', onKey)
return () => window.removeEventListener('keydown', onKey)
}, [onClose])
useEscape(onClose)
const go = async () => {
setBusy(true)
+1 -1
View File
@@ -86,7 +86,7 @@ export default function TopFiveEditor({ category: initialCategory, onClose }: Pr
<div className="flex-1 overflow-y-auto overscroll-contain">
<div className="safe-bottom mx-auto max-w-2xl space-y-6 px-4 py-5 pb-16">
<div className="no-scrollbar -mx-4 flex gap-2 overflow-x-auto px-4">
{TOP_CATEGORIES.map((c) => (
{TOP_CATEGORIES.filter((c) => c.value === category || settings.topCategories.includes(c.value)).map((c) => (
<button key={c.value} onClick={() => switchCategory(c.value)} className={cx('chip py-1! text-[13px]', category === c.value && 'chip-on')}>
{c.plural}
</button>
+16 -2
View File
@@ -1,5 +1,5 @@
import { Camera, ImagePlus, Loader2, Lock, Trash2 } from 'lucide-react'
import { useRef, useState } from 'react'
import { useEffect, useRef, useState } from 'react'
import { t } from '../../i18n'
import { deleteProfileImage, updateProfile, uploadProfileImage, USERNAME_RE, type ProfilePatch } from '../../lib/cloud/social'
import { cropImageToJpeg } from '../../lib/image'
@@ -22,6 +22,20 @@ export default function EditProfile({ onClose }: { onClose: () => void }) {
const avatarInput = useRef<HTMLInputElement>(null)
const bannerInput = useRef<HTMLInputElement>(null)
// Aperçus locaux : libérés dès qu'ils sont remplacés ou que la fenêtre se ferme
useEffect(() => {
const url = avatar.preview
return () => {
if (url?.startsWith('blob:')) URL.revokeObjectURL(url)
}
}, [avatar.preview])
useEffect(() => {
const url = banner.preview
return () => {
if (url?.startsWith('blob:')) URL.revokeObjectURL(url)
}
}, [banner.preview])
const cleanUsername = username.trim().toLowerCase().replace(/^@/, '')
const usernameOk = USERNAME_RE.test(cleanUsername)
const nameOk = displayName.trim().length >= 1 && displayName.trim().length <= 40
@@ -152,7 +166,7 @@ export default function EditProfile({ onClose }: { onClose: () => void }) {
<span className="mt-1 block text-right text-[11px] text-ink-3">{bio.length}/300</span>
</label>
<button type="button" onClick={() => setIsPrivate((v) => !v)} className="flex w-full items-center gap-3 rounded-2xl border border-line px-4 py-3.5 text-left">
<button type="button" role="switch" aria-checked={isPrivate} onClick={() => setIsPrivate((v) => !v)} className="flex w-full items-center gap-3 rounded-2xl border border-line px-4 py-3.5 text-left">
<Lock size={18} className="shrink-0 text-ink-2" />
<span className="flex-1">
<span className="block text-sm font-medium">{t('social.privateAccount')}</span>
+3 -1
View File
@@ -13,7 +13,9 @@ type Tab = 'followers' | 'following' | 'requests'
export default function FollowList({ profile, initial, onClose }: { profile: Profile; initial: 'followers' | 'following'; onClose: () => void }) {
const social = useSocial()
const showRequests = profile.isMe && social.requests.length > 0
const [tab, setTab] = useState<Tab>(showRequests && initial === 'followers' ? 'requests' : initial)
const [picked, setTab] = useState<Tab>(showRequests && initial === 'followers' ? 'requests' : initial)
// Dernière demande acceptée : l'onglet « Demandes » disparaît, on retombe sur les abonnés
const tab: Tab = picked === 'requests' && !showRequests ? 'followers' : picked
const [list, setList] = useState<ProfileCard[]>()
const [busy, setBusy] = useState<string>()
+5 -6
View File
@@ -1,5 +1,5 @@
import { Check, Loader2, Plus, Star } from 'lucide-react'
import { useEffect, useState } from 'react'
import { useState } from 'react'
import { t } from '../../i18n'
import { genreLabel } from '../../lib/genres'
import { useScrollLock } from '../../lib/scrollLock'
@@ -9,6 +9,7 @@ import type { MediaInput, MediaItem } from '../../types'
import { StatusPill, TypeBadge } from '../Badges'
import Poster from '../Poster'
import Avatar from './Avatar'
import { useEscape } from '../../lib/escape'
export interface PeekOwner {
username: string
@@ -27,11 +28,7 @@ export default function ItemPeek({ item, owner, onClose }: { item: MediaItem; ow
useScrollLock()
useEffect(() => {
const onKey = (e: KeyboardEvent) => e.key === 'Escape' && onClose()
window.addEventListener('keydown', onKey)
return () => window.removeEventListener('keydown', onKey)
}, [onClose])
useEscape(onClose)
const addToWatchlist = async () => {
setBusy(true)
@@ -46,11 +43,13 @@ export default function ItemPeek({ item, owner, onClose }: { item: MediaItem; ow
criteria: {},
episodesWatched: 0,
episodesTotal: item.episodesTotal,
seasons: item.seasons,
episodeDuration: item.episodeDuration,
duration: item.duration,
genres: item.genres,
platform: item.platform,
poster: item.poster,
backdrop: item.backdrop,
overview: item.overview,
externalId: item.externalId,
countries: item.countries,
+4 -1
View File
@@ -16,7 +16,10 @@ export default function PeopleSearch({ onClose }: { onClose: () => void }) {
useEffect(() => {
const term = q.trim()
if (term.length < 2) return setResults([])
if (term.length < 2) {
setLoading(false)
return setResults([])
}
let alive = true
setLoading(true)
const timer = setTimeout(() => {
+18 -7
View File
@@ -1,6 +1,6 @@
import { Check, Loader2, Lock, Share2, Star, UserPlus } from 'lucide-react'
import { useCallback, useEffect, useMemo, useState } from 'react'
import { t } from '../../i18n'
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { fmtNumber, t } from '../../i18n'
import { follow, getProfile, getProfileItems, profileLink, unfollow, type Profile } from '../../lib/cloud/social'
import { STATUSES, TOP_CATEGORIES } from '../../lib/constants'
import { cx, formatRating } from '../../lib/utils'
@@ -35,7 +35,7 @@ function PosterTile({ item, onOpen, caption }: { item: MediaItem; onOpen: () =>
function Stat({ value, label, onClick }: { value?: number; label: string; onClick?: () => void }) {
const body = (
<>
<span className="block text-lg font-bold tabular-nums leading-tight">{value == null ? '—' : value.toLocaleString()}</span>
<span className="block text-lg font-bold tabular-nums leading-tight">{value == null ? '—' : fmtNumber(value)}</span>
<span className="block text-[11px] text-ink-3">{label}</span>
</>
)
@@ -51,6 +51,7 @@ function Stat({ value, label, onClick }: { value?: number; label: string; onClic
/** Page de profil (la mienne ou celle d'un autre). */
export default function ProfileView({ username, onClose }: { username: string; onClose: () => void }) {
const social = useSocial()
const { settings } = useMedia()
const [profile, setProfile] = useState<Profile | null>()
const [error, setError] = useState<string>()
const [tab, setTab] = useState<'profile' | 'library'>('profile')
@@ -133,12 +134,14 @@ export default function ProfileView({ username, onClose }: { username: string; o
const topByCategory = useMemo(() => {
const out: { label: string; items: MediaItem[] }[] = []
for (const c of TOP_CATEGORIES) {
// Mon profil : mes réglages locaux font foi tout de suite (même avant la synchro)
const shown = profile?.isMe ? TOP_CATEGORIES.filter((c) => settings.topCategories.includes(c.value)) : TOP_CATEGORIES
for (const c of shown) {
const list = (profile?.top ?? []).filter((i) => i.top?.category === c.value).sort((a, b) => a.top!.rank - b.top!.rank)
if (list.length) out.push({ label: c.plural, items: list })
}
return out
}, [profile])
}, [profile, settings.topCategories])
return (
<Sheet
@@ -335,7 +338,7 @@ function ProfileTab({ profile, topByCategory, onOpen }: { profile: Profile; topB
].map(([v, label]) => (
<div key={label as string} className="card p-4">
<div className="eyebrow">{label}</div>
<div className="mt-2 text-2xl font-bold tabular-nums leading-none">{(v as number).toLocaleString()}</div>
<div className="mt-2 text-2xl font-bold tabular-nums leading-none">{fmtNumber(v as number)}</div>
</div>
))}
</div>
@@ -351,15 +354,23 @@ function LibraryTab({ profile, onOpen }: { profile: Profile; onOpen: (i: MediaIt
const [loading, setLoading] = useState(false)
const [done, setDone] = useState(false)
const request = useRef(0)
const loadPage = useCallback(
async (reset: boolean) => {
// Une réponse arrivée après un changement de filtre ne doit pas écraser la nouvelle liste
const id = ++request.current
setLoading(true)
if (reset) setList([])
try {
const page = await getProfileItems(profile.id, status || null, reset ? 0 : list.length)
if (id !== request.current) return
setList((prev) => (reset ? page : [...prev, ...page]))
setDone(page.length < 48)
} catch {
if (id === request.current) setDone(true)
} finally {
setLoading(false)
if (id === request.current) setLoading(false)
}
},
// eslint-disable-next-line react-hooks/exhaustive-deps
+3 -6
View File
@@ -1,16 +1,13 @@
import { X } from 'lucide-react'
import { useEffect, type ReactNode } from 'react'
import { type ReactNode } from 'react'
import { t } from '../../i18n'
import { useScrollLock } from '../../lib/scrollLock'
import { useEscape } from '../../lib/escape'
/** Écran plein (profil, recherche…) avec en-tête et bouton fermer. */
export default function Sheet({ title, onClose, right, children, label }: { title: ReactNode; onClose: () => void; right?: ReactNode; children: ReactNode; label: string }) {
useScrollLock()
useEffect(() => {
const onKey = (e: KeyboardEvent) => e.key === 'Escape' && onClose()
window.addEventListener('keydown', onKey)
return () => window.removeEventListener('keydown', onKey)
}, [onClose])
useEscape(onClose)
return (
<div className="sheet-in fixed inset-0 z-50 flex flex-col bg-bg" role="dialog" aria-modal="true" aria-label={label}>
<header className="safe-top border-b border-line">
-21
View File
@@ -46,27 +46,6 @@ export function LinkArrow({ onClick, children }: { onClick: () => void; children
)
}
/** Liste de barres horizontales (une seule série → une seule couleur, valeurs écrites en clair). */
export function BarList({ data, format = String }: { data: { label: string; value: number }[]; format?: (v: number) => string }) {
const max = Math.max(1, ...data.map((d) => d.value))
if (!data.some((d) => d.value > 0)) return <p className="text-sm text-ink-3">{t('common.noData')}</p>
return (
<ul className="space-y-3">
{data.map((d) => (
<li key={d.label} className="text-sm" title={`${d.label} : ${format(d.value)}`}>
<div className="mb-1.5 flex justify-between gap-2">
<span className="truncate text-ink-2">{d.label}</span>
<span className="shrink-0 text-xs tabular-nums text-ink">{format(d.value)}</span>
</div>
<div className="h-1 rounded-full bg-surface-2">
<div className="h-full rounded-full bg-accent" style={{ width: `${(d.value / max) * 100}%`, minWidth: d.value ? 4 : 0 }} />
</div>
</li>
))}
</ul>
)
}
export function EmptyState({ title, text, action }: { title: string; text?: string; action?: ReactNode }) {
return (
<div className="card mt-4 flex flex-col items-center px-6 py-12 text-center">