Stats : ajouts en lot détectés, « date inconnue » et écran « Dates à corriger »
deploy / deploy (push) Successful in 35s
deploy / deploy (push) Successful in 35s
- Les titres « terminés » le jour d'un ajout en lot (≥ 15 titres créés ou terminés le même jour) ne faussent plus la courbe mois par mois ni les années ; ils restent comptés dans les totaux. Note sous la courbe + lien. - Fiche : « Je ne sais plus » pour la date de fin ; dates approximatives (année ou mois) affichées comme telles. - Écran « Dates à corriger » : sélection multiple (filtre par type), année et mois facultatif, ou « Je ne sais plus » ; onglet des dates approximatives. - Nouveau champ endApprox (synchro, 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
+772
-22
No files matched your search
@@ -0,0 +1,204 @@
|
||||
import { Check, X } from 'lucide-react'
|
||||
import { useMemo, useState } from 'react'
|
||||
import { locale, t } from '../../i18n'
|
||||
import { useBackToClose } from '../../lib/backNav'
|
||||
import { MEDIA_TYPES, TYPE_BY_VALUE } from '../../lib/constants'
|
||||
import { approxPatch, bulkDays, dateQuality, endLabel, needsFix, type DateQuality } from '../../lib/dating'
|
||||
import { useEscape } from '../../lib/escape'
|
||||
import { useScrollLock } from '../../lib/scrollLock'
|
||||
import { cx, formatDate } from '../../lib/utils'
|
||||
import { useMedia } from '../../store'
|
||||
import type { MediaItem, MediaType } from '../../types'
|
||||
import Poster from '../Poster'
|
||||
|
||||
type Tab = 'fix' | 'approx'
|
||||
|
||||
/**
|
||||
* « Dates à corriger » : les titres terminés dont la date de fin est celle d'un ajout en lot (ou absente).
|
||||
* On en sélectionne plusieurs et on leur donne une année (et un mois si on s'en souvient), ou « je ne sais plus ».
|
||||
*/
|
||||
export default function DatesSheet({ onClose }: { onClose: () => void }) {
|
||||
const { items, updateMany } = useMedia()
|
||||
useScrollLock()
|
||||
useEscape(onClose)
|
||||
useBackToClose(onClose)
|
||||
|
||||
// Les jours d'ajout en lot sont figés à l'ouverture : corriger une partie des titres ne fait pas « disparaître » le lot
|
||||
const [bulk] = useState(() => bulkDays(items))
|
||||
const [tab, setTab] = useState<Tab>('fix')
|
||||
const [type, setType] = useState<MediaType | ''>('')
|
||||
const [selected, setSelected] = useState<Set<string>>(new Set())
|
||||
const [year, setYear] = useState('')
|
||||
const [month, setMonth] = useState('')
|
||||
const [busy, setBusy] = useState(false)
|
||||
|
||||
const all = useMemo(
|
||||
() =>
|
||||
items
|
||||
.filter((i) => i.status === 'termine')
|
||||
.map((i) => ({ item: i, q: dateQuality(i, bulk) }))
|
||||
.filter(({ q }) => q !== 'exact'),
|
||||
[items, bulk],
|
||||
)
|
||||
const toFix = all.filter(({ q }) => needsFix(q))
|
||||
const approx = all.filter(({ q }) => !needsFix(q))
|
||||
const pool = tab === 'fix' ? toFix : approx
|
||||
const types = MEDIA_TYPES.filter((m) => pool.some(({ item }) => item.type === m.value))
|
||||
// Filtre devenu vide (tous ses titres corrigés) : on revient à « Tout »
|
||||
const activeType = type && types.some((m) => m.value === type) ? type : ''
|
||||
const list = pool.filter(({ item }) => !activeType || item.type === activeType).sort((a, b) => a.item.title.localeCompare(b.item.title, locale()))
|
||||
|
||||
const toggle = (id: string) =>
|
||||
setSelected((s) => {
|
||||
const n = new Set(s)
|
||||
if (n.has(id)) n.delete(id)
|
||||
else n.add(id)
|
||||
return n
|
||||
})
|
||||
const allOn = list.length > 0 && list.every(({ item }) => selected.has(item.id))
|
||||
|
||||
const thisYear = new Date().getFullYear()
|
||||
const years = Array.from({ length: thisYear - 1949 }, (_, k) => thisYear - k)
|
||||
const months = Array.from({ length: 12 }, (_, k) => k + 1).filter((m) => Number(year) !== thisYear || m <= new Date().getMonth() + 1)
|
||||
const monthName = (m: number) => new Date(2000, m - 1, 15).toLocaleDateString(locale(), { month: 'long' })
|
||||
|
||||
const apply = async (choice: { year: number; month?: number } | 'unknown') => {
|
||||
const chosen = items.filter((i) => selected.has(i.id))
|
||||
if (!chosen.length) return
|
||||
setBusy(true)
|
||||
try {
|
||||
await updateMany(chosen.map((i) => ({ id: i.id, patch: approxPatch(i, choice) })))
|
||||
setSelected(new Set())
|
||||
} finally {
|
||||
setBusy(false)
|
||||
}
|
||||
}
|
||||
|
||||
const statusText = (item: MediaItem, q: DateQuality) =>
|
||||
q === 'bulk' ? t('dates.bulk', { date: formatDate(item.endDate) }) : q === 'missing' ? t('dates.missing') : endLabel(item)
|
||||
|
||||
return (
|
||||
<div className="sheet sheet-in" role="dialog" aria-modal="true" aria-label={t('dates.title')}>
|
||||
<header className="safe-top border-b border-line">
|
||||
<div className="mx-auto max-w-2xl px-3 pb-3 pt-2.5 lg:max-w-none lg:px-10">
|
||||
<div className="flex items-center gap-2">
|
||||
<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('dates.title')}</h2>
|
||||
<span className="size-10 shrink-0" />
|
||||
</div>
|
||||
<div className="mt-2 grid grid-cols-2 gap-1 rounded-full border border-line p-1" role="tablist">
|
||||
{(['fix', 'approx'] as const).map((x) => (
|
||||
<button
|
||||
key={x}
|
||||
role="tab"
|
||||
aria-selected={tab === x}
|
||||
onClick={() => {
|
||||
setTab(x)
|
||||
setType('')
|
||||
setSelected(new Set())
|
||||
}}
|
||||
className={cx('rounded-full py-2 text-sm font-medium transition-colors', tab === x ? 'bg-ink text-bg' : 'text-ink-3')}
|
||||
>
|
||||
{x === 'fix' ? t('dates.tabFix') : t('dates.tabApprox')} <span className="opacity-60">{x === 'fix' ? toFix.length : approx.length}</span>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div className="sheet-scroll">
|
||||
<div className="mx-auto max-w-2xl px-4 pb-[calc(16rem+env(safe-area-inset-bottom))] pt-4 lg:max-w-none lg:px-10">
|
||||
{tab === 'fix' && toFix.length > 0 && <p className="text-sm leading-relaxed text-ink-2">{t('dates.hint')}</p>}
|
||||
|
||||
{list.length > 0 && (
|
||||
<div className="mt-4 flex flex-wrap items-center gap-2">
|
||||
<button onClick={() => setType('')} className={cx('chip', !activeType && 'chip-on')}>
|
||||
{t('search.tabAll')}
|
||||
</button>
|
||||
{types.length > 1 &&
|
||||
types.map((m) => (
|
||||
<button key={m.value} onClick={() => setType(m.value)} className={cx('chip', activeType === m.value && 'chip-on')}>
|
||||
{TYPE_BY_VALUE[m.value].label}
|
||||
</button>
|
||||
))}
|
||||
<button
|
||||
onClick={() => setSelected(allOn ? new Set() : new Set(list.map(({ item }) => item.id)))}
|
||||
className="ms-auto text-sm font-medium text-ink-2"
|
||||
>
|
||||
{allOn ? t('dates.selectNone') : t('dates.selectAll')}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{list.length === 0 ? (
|
||||
<p className="mt-12 text-center text-sm text-ink-3">{tab === 'fix' ? t('dates.empty') : t('dates.emptyApprox')}</p>
|
||||
) : (
|
||||
<ul className="mt-3 divide-y divide-line lg:grid lg:grid-cols-2 lg:gap-x-10 lg:divide-y-0 xl:grid-cols-3">
|
||||
{list.map(({ item, q }) => {
|
||||
const on = selected.has(item.id)
|
||||
return (
|
||||
<li key={item.id} className="lg:border-b lg:border-line">
|
||||
<button onClick={() => toggle(item.id)} aria-pressed={on} className="flex w-full items-center gap-3 py-2.5 text-start">
|
||||
<span className={cx('grid size-6 shrink-0 place-items-center rounded-md border', on ? 'border-accent bg-accent-fill text-on-accent' : 'border-line-strong')}>
|
||||
{on && <Check size={15} strokeWidth={2.6} />}
|
||||
</span>
|
||||
<span className="w-10 shrink-0">
|
||||
<Poster src={item.poster} title={item.title} />
|
||||
</span>
|
||||
<span className="min-w-0 flex-1">
|
||||
<span className="block truncate text-sm font-semibold">{item.title}</span>
|
||||
<span className="block truncate text-xs text-ink-3">{[item.year, TYPE_BY_VALUE[item.type].label].filter(Boolean).join(' · ')}</span>
|
||||
<span className={cx('block truncate text-xs', needsFix(q) ? 'text-accent' : 'text-ink-2')}>{statusText(item, q)}</span>
|
||||
</span>
|
||||
</button>
|
||||
</li>
|
||||
)
|
||||
})}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Barre d'action : apparaît dès qu'un titre est sélectionné */}
|
||||
{selected.size > 0 && (
|
||||
<div className="safe-bottom fixed inset-x-0 bottom-0 z-10 border-t border-line bg-bg/95 backdrop-blur-md">
|
||||
<div className="mx-auto max-w-2xl space-y-2.5 px-4 py-3 lg:max-w-3xl">
|
||||
<p className="text-sm font-medium">{t('dates.selected', { count: selected.size })}</p>
|
||||
<div className="flex gap-2">
|
||||
<select value={year} onChange={(e) => setYear(e.target.value)} className="field min-w-0 flex-1 py-2 text-sm" aria-label={t('dates.yearPh')}>
|
||||
<option value="">{t('dates.yearPh')}</option>
|
||||
{years.map((y) => (
|
||||
<option key={y} value={y}>
|
||||
{y}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<select value={month} onChange={(e) => setMonth(e.target.value)} disabled={!year} className="field min-w-0 flex-1 py-2 text-sm" aria-label={t('dates.monthPh')}>
|
||||
<option value="">{t('dates.monthPh')}</option>
|
||||
{months.map((m) => (
|
||||
<option key={m} value={m}>
|
||||
{monthName(m)}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div className="grid grid-cols-2 gap-2">
|
||||
<button onClick={() => void apply('unknown')} disabled={busy} className="btn btn-ghost py-2.5 text-sm">
|
||||
{t('dates.dunno')}
|
||||
</button>
|
||||
<button
|
||||
onClick={() => void apply({ year: Number(year), month: month && months.includes(Number(month)) ? Number(month) : undefined })}
|
||||
disabled={busy || !year}
|
||||
className="btn btn-primary py-2.5 text-sm"
|
||||
>
|
||||
{t('dates.apply')}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import { approxPatch, endLabel } from '../../lib/dating'
|
||||
import { locale, t } from '../../i18n'
|
||||
import { Bookmark, Check, ChevronDown, Eye, Heart, Loader2, MessagesSquare, Minus, MoreHorizontal, Pencil, Play, Plus, Share2, Trash2, X } from 'lucide-react'
|
||||
import { useEffect, useMemo, useRef, useState, type ReactNode } from 'react'
|
||||
@@ -183,11 +184,13 @@ export default function TitleSheet({ item: initial, seed, onClose, onGoToSetting
|
||||
if (s === status) return
|
||||
const patch: Partial<MediaInput> = { status: s }
|
||||
const today = todayISO()
|
||||
if (s === 'a_voir') Object.assign(patch, { startDate: undefined, endDate: undefined })
|
||||
if (s === 'a_voir') Object.assign(patch, { startDate: undefined, endDate: undefined, endApprox: undefined })
|
||||
// Série : la date de début est celle du premier épisode coché
|
||||
if (s === 'en_cours') Object.assign(patch, { startDate: episodic && !item?.episodesWatched ? item?.startDate : (item?.startDate ?? today), endDate: undefined })
|
||||
if (s === 'en_cours') Object.assign(patch, { startDate: episodic && !item?.episodesWatched ? item?.startDate : (item?.startDate ?? today), endDate: undefined, endApprox: undefined })
|
||||
if (s === 'termine') {
|
||||
patch.endDate = item?.status === 'termine' && item.endDate ? item.endDate : today
|
||||
const keep = item?.status === 'termine' && item.endDate
|
||||
patch.endDate = keep ? item.endDate : today
|
||||
if (!keep) patch.endApprox = undefined
|
||||
if (!item?.startDate) patch.startDate = episodic && item?.episodesWatched ? today : patch.endDate
|
||||
const cap = episodeCap(item ?? { episodesTotal: data.episodesTotal, seasons: data.seasons })
|
||||
if (episodic && cap) patch.episodesWatched = cap
|
||||
@@ -214,7 +217,8 @@ export default function TitleSheet({ item: initial, seed, onClose, onGoToSetting
|
||||
}
|
||||
// Date de fin seulement pour un titre terminé (noter une série en cours ne la termine pas)
|
||||
const finished = (patch.status ?? item?.status) === 'termine'
|
||||
if (finished && !item?.endDate) patch.endDate = today
|
||||
// (« date inconnue » choisie exprès : on ne la remplace pas)
|
||||
if (finished && !item?.endDate && !item?.endApprox) patch.endDate = today
|
||||
if (finished && !item?.startDate) patch.startDate = today
|
||||
}
|
||||
void save(patch)
|
||||
@@ -769,7 +773,7 @@ function Tracking({ item, lists, tagSuggestions, onChange }: { item: MediaItem;
|
||||
const rewatches = [...(item.rewatchDates ?? [])].sort().reverse()
|
||||
const summary = [
|
||||
item.startDate && `${t('form.startShort')} ${formatDate(item.startDate)}`,
|
||||
item.endDate && `${t('form.endShort')} ${formatDate(item.endDate)}`,
|
||||
endLabel(item) && `${t('form.endShort')} ${endLabel(item)}`,
|
||||
rewatches.length ? t('title.rewatchCount', { count: rewatches.length }) : undefined,
|
||||
].filter(Boolean)
|
||||
|
||||
@@ -789,10 +793,30 @@ function Tracking({ item, lists, tagSuggestions, onChange }: { item: MediaItem;
|
||||
<span className="label">{t('form.startShort')}</span>
|
||||
<input className="field" type="date" value={item.startDate ?? ''} max={todayISO()} onChange={(e) => onChange({ startDate: e.target.value || undefined })} />
|
||||
</label>
|
||||
<label className="block">
|
||||
<span className="label">{t('form.endShort')}</span>
|
||||
<input className="field" type="date" value={item.endDate ?? ''} max={todayISO()} onChange={(e) => onChange({ endDate: e.target.value || undefined })} />
|
||||
</label>
|
||||
<div>
|
||||
<label className="block">
|
||||
<span className="label">
|
||||
{t('form.endShort')}
|
||||
{(item.endApprox === 'year' || item.endApprox === 'month') && <span className="ms-1.5 font-normal normal-case text-ink-3">· {t('dates.approxLabel')}</span>}
|
||||
</span>
|
||||
{item.endApprox === 'unknown' ? (
|
||||
<span className="field block text-ink-3">{t('dates.unknown')}</span>
|
||||
) : (
|
||||
<input className="field" type="date" value={item.endDate ?? ''} max={todayISO()} onChange={(e) => onChange({ endDate: e.target.value || undefined, endApprox: undefined })} />
|
||||
)}
|
||||
</label>
|
||||
{item.status === 'termine' && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onChange(item.endApprox === 'unknown' ? { endApprox: undefined } : approxPatch(item, 'unknown'))}
|
||||
aria-pressed={item.endApprox === 'unknown'}
|
||||
className={cx('chip mt-2 text-xs', item.endApprox === 'unknown' && 'chip-on')}
|
||||
>
|
||||
{item.endApprox === 'unknown' && <Check size={13} />}
|
||||
{t('dates.dunno')}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<span className="label">{t('lists.myLists')}</span>
|
||||
|
||||
Reference in new issue
Block a user