Bouton ⚙ sur « Mois par mois » : aperçu de la courbe et une case par mois pour l'afficher ou non (ex. le mois d'un ajout en lot). Les mois masqués n'apparaissent plus dans la courbe ni dans « mois le plus chargé » mais les titres restent comptés partout ailleurs. Réglage synchronisé (statsHiddenMonths), inclus dans la sauvegarde, 18 langues. 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
+239
-14
No files matched your search
@@ -50,12 +50,12 @@ export function Columns({
|
||||
height = 140,
|
||||
label,
|
||||
}: {
|
||||
bars: { key: string; axis: string; value: number; tip: string; highlight?: boolean }[]
|
||||
bars: { key: string; axis: string; value: number; tip: string; highlight?: boolean; /** Masquée par l'utilisateur : pas de barre, libellé barré */ hidden?: boolean }[]
|
||||
height?: number
|
||||
/** Nom du graphique (lecteurs d'écran) */
|
||||
label: string
|
||||
}) {
|
||||
const max = Math.max(1, ...bars.map((b) => b.value))
|
||||
const max = Math.max(1, ...bars.filter((b) => !b.hidden).map((b) => b.value))
|
||||
return (
|
||||
<figure aria-label={label}>
|
||||
<div className="relative flex items-end gap-[2px] border-b border-line" style={{ height }}>
|
||||
@@ -64,8 +64,8 @@ export function Columns({
|
||||
{bars.map((b) => (
|
||||
<div key={b.key} tabIndex={0} aria-label={b.tip} className="group relative flex h-full flex-1 items-end justify-center outline-none">
|
||||
<div
|
||||
className={cx('w-full max-w-9 rounded-t-[4px] transition-opacity', b.value > 0 ? 'bg-accent-fill' : 'bg-transparent', !b.highlight && 'opacity-80 group-hover:opacity-100 group-focus-visible:opacity-100')}
|
||||
style={{ height: b.value > 0 ? `${Math.max(3, (b.value / max) * 100)}%` : 0 }}
|
||||
className={cx('w-full max-w-9 rounded-t-[4px] transition-opacity', b.value > 0 && !b.hidden ? 'bg-accent-fill' : 'bg-transparent', !b.highlight && 'opacity-80 group-hover:opacity-100 group-focus-visible:opacity-100')}
|
||||
style={{ height: b.value > 0 && !b.hidden ? `${Math.max(3, (b.value / max) * 100)}%` : 0 }}
|
||||
/>
|
||||
<span className="pointer-events-none absolute bottom-full z-10 mb-1.5 hidden whitespace-nowrap rounded-lg border border-line bg-surface px-2 py-1 text-xs text-ink shadow-sm group-hover:block group-focus-visible:block">
|
||||
{b.tip}
|
||||
@@ -75,7 +75,7 @@ export function Columns({
|
||||
</div>
|
||||
<div className="mt-1.5 flex gap-[2px]" aria-hidden="true">
|
||||
{bars.map((b) => (
|
||||
<span key={b.key} className={cx('flex-1 truncate text-center text-[10px] text-ink-3', b.highlight && 'font-semibold text-ink')}>
|
||||
<span key={b.key} className={cx('flex-1 truncate text-center text-[10px] text-ink-3', b.highlight && 'font-semibold text-ink', b.hidden && 'line-through opacity-50')}>
|
||||
{b.axis}
|
||||
</span>
|
||||
))}
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
import { Check, X } from 'lucide-react'
|
||||
import { useMemo, useState } from 'react'
|
||||
import { locale, t } from '../../i18n'
|
||||
import { useBackToClose } from '../../lib/backNav'
|
||||
import { useEscape } from '../../lib/escape'
|
||||
import { useScrollLock } from '../../lib/scrollLock'
|
||||
import { availableYears, monthly } from '../../lib/stats'
|
||||
import { cx, formatDuration } from '../../lib/utils'
|
||||
import { useMedia } from '../../store'
|
||||
import { Columns } from './Charts'
|
||||
|
||||
/**
|
||||
* Paramètres des stats : la courbe mois par mois, et en dessous une case par mois pour l'afficher ou non
|
||||
* (ex. le mois où toute la bibliothèque a été ajoutée d'un coup). Les mois masqués suivent le compte (réglages synchronisés).
|
||||
*/
|
||||
export default function StatsSettings({ onClose, initialYear }: { onClose: () => void; initialYear: string }) {
|
||||
const { items, settings, updateSettings } = useMedia()
|
||||
useScrollLock()
|
||||
useEscape(onClose)
|
||||
useBackToClose(onClose)
|
||||
|
||||
const years = useMemo(() => availableYears(items), [items])
|
||||
const [year, setYear] = useState(initialYear && years.includes(initialYear) ? initialYear : '')
|
||||
const months = useMemo(() => monthly(items, year), [items, year])
|
||||
const hidden = new Set(settings.statsHiddenMonths ?? [])
|
||||
|
||||
const setShown = (key: string, shown: boolean) => {
|
||||
const next = new Set(hidden)
|
||||
if (shown) next.delete(key)
|
||||
else next.add(key)
|
||||
updateSettings({ statsHiddenMonths: next.size ? [...next].sort() : undefined })
|
||||
}
|
||||
const label = (key: string) => new Date(`${key}-15T12:00:00`).toLocaleDateString(locale(), { month: 'long', year: 'numeric' })
|
||||
|
||||
return (
|
||||
<div className="sheet sheet-in" role="dialog" aria-modal="true" aria-label={t('stats.settings')}>
|
||||
<header className="safe-top border-b border-line">
|
||||
<div className="mx-auto flex max-w-2xl items-center gap-2 px-3 py-2.5 lg:max-w-3xl">
|
||||
<button onClick={onClose} className="grid size-10 shrink-0 place-items-center rounded-full text-ink-2" aria-label={t('common.close')}>
|
||||
<X size={22} />
|
||||
</button>
|
||||
<h2 className="min-w-0 flex-1 truncate text-center text-base font-semibold">{t('stats.settings')}</h2>
|
||||
<span className="size-10 shrink-0" />
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div className="sheet-scroll">
|
||||
<div className="mx-auto max-w-2xl px-4 pb-[calc(10rem+env(safe-area-inset-bottom))] pt-5 lg:max-w-3xl">
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
<h3 className="eyebrow text-ink-2">{year ? t('stats.monthByMonth', { year }) : t('stats.last12')}</h3>
|
||||
<select value={year} onChange={(e) => setYear(e.target.value)} className="field w-auto py-2 pe-8 text-sm" aria-label={t('stats.period')}>
|
||||
<option value="">{t('stats.last12')}</option>
|
||||
{years.map((y) => (
|
||||
<option key={y} value={y}>
|
||||
{y}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
{/* Aperçu en direct */}
|
||||
<div className="card mt-4 p-4">
|
||||
<Columns
|
||||
label={year ? t('stats.monthByMonth', { year }) : t('stats.last12')}
|
||||
height={150}
|
||||
bars={months.map((m) => ({
|
||||
key: m.key,
|
||||
axis: m.initial,
|
||||
value: m.count,
|
||||
hidden: hidden.has(m.key),
|
||||
tip: hidden.has(m.key) ? `${m.label} : ${t('stats.monthHidden')}` : `${m.label} : ${t('stats.monthFinished', { count: m.count })}`,
|
||||
}))}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<p className="mt-5 text-sm text-ink-2">{t('stats.hideMonthsHint')}</p>
|
||||
|
||||
{/* Une case par mois : cochée = affiché dans la courbe */}
|
||||
<ul className="mt-3 grid grid-cols-2 gap-2 sm:grid-cols-3">
|
||||
{months.map((m) => {
|
||||
const shown = !hidden.has(m.key)
|
||||
return (
|
||||
<li key={m.key}>
|
||||
<button
|
||||
onClick={() => setShown(m.key, !shown)}
|
||||
role="checkbox"
|
||||
aria-checked={shown}
|
||||
className={cx('flex w-full items-center gap-2.5 rounded-xl border px-3 py-2.5 text-start transition-colors', shown ? 'border-line' : 'border-dashed border-line-strong text-ink-3')}
|
||||
>
|
||||
<span className={cx('grid size-5 shrink-0 place-items-center rounded-md border', shown ? 'border-accent bg-accent-fill text-on-accent' : 'border-line-strong')}>
|
||||
{shown && <Check size={13} strokeWidth={2.8} />}
|
||||
</span>
|
||||
<span className="min-w-0">
|
||||
<span className="block truncate text-sm font-medium first-letter:uppercase">{label(m.key)}</span>
|
||||
<span className="block truncate text-xs text-ink-3">
|
||||
{t('stats.monthFinished', { count: m.count })}
|
||||
{m.minutes ? ` · ${formatDuration(m.minutes)}` : ''}
|
||||
</span>
|
||||
</span>
|
||||
</button>
|
||||
</li>
|
||||
)
|
||||
})}
|
||||
</ul>
|
||||
|
||||
{hidden.size > 0 && (
|
||||
<button onClick={() => updateSettings({ statsHiddenMonths: undefined })} className="mt-5 text-sm font-medium text-ink-2">
|
||||
{t('stats.showAllMonths')}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user