Merge branch 'worktree-agent-ac9eaf6c2d9810cbb' into claude/relaxed-maxwell-c10wof

# Conflicts:
#	src/i18n/locales/ar.ts
#	src/i18n/locales/de.ts
#	src/i18n/locales/en.ts
#	src/i18n/locales/es.ts
#	src/i18n/locales/fr.ts
#	src/i18n/locales/hi.ts
#	src/i18n/locales/id.ts
#	src/i18n/locales/it.ts
#	src/i18n/locales/ja.ts
#	src/i18n/locales/ko.ts
#	src/i18n/locales/nl.ts
#	src/i18n/locales/pl.ts
#	src/i18n/locales/pt.ts
#	src/i18n/locales/ru.ts
#	src/i18n/locales/th.ts
#	src/i18n/locales/tr.ts
#	src/i18n/locales/vi.ts
#	src/i18n/locales/zh.ts
This commit is contained in:
Claude committed 2026-10-09 15:17:14 +00:00
commit 0dab749134
35 files changed
+1795 -22

No files matched your search

+3 -1
View File
@@ -9,6 +9,7 @@ import ConfirmDialog from './ConfirmDialog'
import { MediaCard } from './MediaCard'
import Poster from './Poster'
import { EmptyState } from './ui'
import { useLibraryActions } from './library/useLibraryActions'
/** Mosaïque 2×2 des premières affiches d'une liste. */
function Mosaic({ items }: { items: MediaItem[] }) {
@@ -60,6 +61,7 @@ export function NewListForm({ onCreated, autoFocus }: { onCreated?: (list: Custo
function ListDetail({ list, onBack, onOpen }: { list: CustomList; onBack: () => void; onOpen: (item: MediaItem) => void }) {
const { items, renameList, deleteList, toggleInList } = useMedia()
const actions = useLibraryActions()
const [renaming, setRenaming] = useState(false)
const [name, setName] = useState(list.name)
const [adding, setAdding] = useState(false)
@@ -130,7 +132,7 @@ function ListDetail({ list, onBack, onOpen }: { list: CustomList; onBack: () =>
const inList = item.listIds?.includes(list.id)
return (
<li key={item.id}>
<button onClick={() => toggleInList(item.id, list.id)} className="flex w-full items-center gap-3 py-2.5 text-start">
<button onClick={() => (inList ? void actions.removeFromList([item.id], list.id) : void toggleInList(item.id, list.id))} className="flex w-full items-center gap-3 py-2.5 text-start">
<div className="w-9 shrink-0">
<Poster src={item.poster} title={item.title} />
</div>
+5 -3
View File
@@ -12,10 +12,12 @@ interface Props {
display?: (value: string) => string
/** Valeur enregistrée à partir du texte saisi (ex. nom de référence d'un genre) */
normalize?: (input: string) => string
/** Propose aussi les suggestions avant de taper (ex. tags perso déjà utilisés) */
showAll?: boolean
}
/** Saisie de tags libres ; des suggestions apparaissent quand on commence à taper. */
export default function TagInput({ value, onChange, suggestions, placeholder, display = (v) => v, normalize = (v) => v }: Props) {
export default function TagInput({ value, onChange, suggestions, placeholder, display = (v) => v, normalize = (v) => v, showAll = false }: Props) {
const [text, setText] = useState('')
const add = (raw: string) => {
@@ -30,9 +32,9 @@ export default function TagInput({ value, onChange, suggestions, placeholder, di
const q = normalizeText(text)
const taken = new Set(value.map((v) => normalizeText(display(v))))
// Suggestions seulement pendant la saisie (pas de rangée de genres affichée en permanence)
if (!q) return []
if (!q && !showAll) return []
return suggestions.filter((s) => !taken.has(normalizeText(s)) && normalizeText(s).includes(q)).slice(0, 12)
}, [text, value, suggestions])
}, [text, value, suggestions, showAll])
return (
<div>
+122
View File
@@ -0,0 +1,122 @@
import { t } from '../i18n'
import { Undo2, X } from 'lucide-react'
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, type ReactNode } from 'react'
/**
* Petits messages en bas de l'écran (« Supprimé · Annuler »), au-dessus de la barre de navigation.
* Un seul à la fois : un nouveau message remplace le précédent (dont l'annulation n'est plus proposée).
*/
export interface ToastOptions {
/** Bouton « Annuler » : remet les choses comme avant. */
undo?: () => void | Promise<void>
/** Durée d'affichage en ms (6 s avec « Annuler », 3 s sinon). */
duration?: number
}
interface ToastApi {
show: (message: string, opts?: ToastOptions) => void
dismiss: () => void
}
interface ToastState extends ToastOptions {
id: number
message: string
}
const ToastContext = createContext<ToastApi | null>(null)
export function ToastProvider({ children }: { children: ReactNode }) {
const [toast, setToast] = useState<ToastState | null>(null)
const seq = useRef(0)
const dismiss = useCallback(() => setToast(null), [])
const show = useCallback((message: string, opts: ToastOptions = {}) => {
seq.current += 1
setToast({ id: seq.current, message, ...opts })
}, [])
const api = useMemo(() => ({ show, dismiss }), [show, dismiss])
return (
<ToastContext.Provider value={api}>
{children}
<ToastViewport toast={toast} onDismiss={dismiss} onShow={show} />
</ToastContext.Provider>
)
}
/** Accès aux messages. Hors du fournisseur (tests, aperçu), les appels ne font rien. */
export function useToast(): ToastApi {
return useContext(ToastContext) ?? NOOP
}
const NOOP: ToastApi = { show: () => {}, dismiss: () => {} }
function ToastViewport({ toast, onDismiss, onShow }: { toast: ToastState | null; onDismiss: () => void; onShow: ToastApi['show'] }) {
const [paused, setPaused] = useState(false)
const [undoing, setUndoing] = useState(false)
const remaining = useRef(0)
const startedAt = useRef(0)
// Nouveau message : compte à rebours complet
useEffect(() => {
if (!toast) return
remaining.current = toast.duration ?? (toast.undo ? 6000 : 3000)
setUndoing(false)
}, [toast])
// Le compte à rebours s'arrête tant que le doigt / la souris / le clavier est sur le message
useEffect(() => {
if (!toast || paused) return
startedAt.current = Date.now()
const id = setTimeout(onDismiss, remaining.current)
return () => {
clearTimeout(id)
remaining.current = Math.max(1500, remaining.current - (Date.now() - startedAt.current))
}
}, [toast, paused, onDismiss])
const undo = async () => {
if (!toast?.undo || undoing) return
setUndoing(true)
try {
await toast.undo()
onShow(t('toast.undone'))
} catch {
onShow(t('toast.undoFailed'))
}
}
return (
<div
role="status"
aria-live="polite"
aria-atomic="true"
className="pointer-events-none fixed inset-x-0 bottom-[calc(5.25rem+env(safe-area-inset-bottom))] z-[80] flex justify-center px-4 lg:bottom-6 lg:ps-64"
>
{toast && (
<div
key={toast.id}
className="sheet-in pointer-events-auto flex w-full max-w-md items-center gap-3 rounded-2xl bg-ink py-2.5 ps-4 pe-2 text-bg shadow-lg"
onPointerEnter={() => setPaused(true)}
onPointerLeave={() => setPaused(false)}
onFocus={() => setPaused(true)}
onBlur={() => setPaused(false)}
>
<p className="min-w-0 flex-1 text-sm font-medium leading-snug">{toast.message}</p>
{toast.undo && (
<button
onClick={() => void undo()}
disabled={undoing}
className="inline-flex shrink-0 items-center gap-1.5 rounded-full border border-bg/30 px-3 py-1.5 text-sm font-semibold transition active:scale-95 disabled:opacity-50"
>
<Undo2 size={15} /> {t('toast.undo')}
</button>
)}
<button onClick={onDismiss} className="grid size-8 shrink-0 place-items-center rounded-full opacity-70" aria-label={t('common.close')}>
<X size={16} />
</button>
</div>
)}
</div>
)
}
+101
View File
@@ -0,0 +1,101 @@
import { t } from '../../i18n'
import { Check } from 'lucide-react'
import { useRef, type ReactNode } from 'react'
import { cx } from '../../lib/utils'
interface Props {
title: string
selecting: boolean
selected: boolean
onToggle: () => void
/** Appui long (téléphone) ou case à cocher (ordinateur) : entre en mode sélection avec ce titre. */
onStartSelect: () => void
children: ReactNode
}
const LONG_PRESS_MS = 450
/**
* Enveloppe d'une carte du catalogue pour la sélection multiple :
* - téléphone : appui long sur la carte ;
* - ordinateur : case à cocher au survol ;
* - en mode sélection, toucher la carte la coche / décoche (au lieu d'ouvrir la fiche).
*/
export default function SelectableCard({ title, selecting, selected, onToggle, onStartSelect, children }: Props) {
const timer = useRef<ReturnType<typeof setTimeout>>(undefined)
const origin = useRef<{ x: number; y: number }>(undefined)
const fired = useRef(false)
const cancel = () => {
clearTimeout(timer.current)
timer.current = undefined
origin.current = undefined
}
return (
<div
className="group relative select-none [-webkit-touch-callout:none]"
onPointerDown={(e) => {
fired.current = false
if (selecting || e.pointerType === 'mouse') return
origin.current = { x: e.clientX, y: e.clientY }
timer.current = setTimeout(() => {
fired.current = true
timer.current = undefined
navigator.vibrate?.(12)
onStartSelect()
}, LONG_PRESS_MS)
}}
onPointerMove={(e) => {
// Le doigt glisse (défilement) : ce n'est pas un appui long
if (origin.current && Math.hypot(e.clientX - origin.current.x, e.clientY - origin.current.y) > 10) cancel()
}}
onPointerUp={cancel}
onPointerCancel={cancel}
onPointerLeave={cancel}
onContextMenu={(e) => {
// Pas de menu « Enregistrer l'image » pendant l'appui long
if (fired.current || timer.current) e.preventDefault()
}}
onClickCapture={(e) => {
// Le « clic » qui suit un appui long ne doit pas ouvrir la fiche
if (fired.current) {
e.preventDefault()
e.stopPropagation()
fired.current = false
}
}}
>
{children}
{selecting ? (
<button
type="button"
onClick={onToggle}
aria-pressed={selected}
aria-label={t('select.toggle', { title })}
className={cx('absolute -inset-1 z-10 rounded-2xl transition-colors', selected ? 'bg-accent-fill/15 ring-2 ring-accent' : 'active:bg-ink/5')}
>
<span
className={cx(
'absolute end-3 top-3 grid size-7 place-items-center rounded-full border-2 transition-colors',
selected ? 'border-accent-fill bg-accent-fill text-on-accent' : 'border-ink/70 bg-bg/70 text-transparent',
)}
>
<Check size={15} strokeWidth={3} />
</span>
</button>
) : (
// Ordinateur : case à cocher au survol (ou au clavier) pour commencer une sélection
<button
type="button"
onClick={onStartSelect}
aria-label={t('select.toggle', { title })}
className="absolute end-2 top-2 z-10 hidden size-7 place-items-center rounded-full border-2 border-ink/70 bg-bg/85 text-transparent opacity-0 transition-opacity group-hover:opacity-100 focus-visible:opacity-100 pointer-fine:grid"
>
<Check size={15} strokeWidth={3} />
</button>
)}
</div>
)
}
+219
View File
@@ -0,0 +1,219 @@
import { t } from '../../i18n'
import { CircleDot, ListPlus, Minus, Plus, Tag, Trash2, X } from 'lucide-react'
import { useMemo, useState, type ReactNode } from 'react'
import { useBackToClose } from '../../lib/backNav'
import { allTags, cleanTag, hasTag } from '../../lib/bulk'
import { STATUSES } from '../../lib/constants'
import { useEscape } from '../../lib/escape'
import { cx, normalizeText } from '../../lib/utils'
import { useMedia } from '../../store'
import type { MediaItem, WatchStatus } from '../../types'
import { StatusDot } from '../Badges'
import ConfirmDialog from '../ConfirmDialog'
import { NewListForm } from '../ListsView'
import { useLibraryActions } from './useLibraryActions'
type Panel = null | 'status' | 'list' | 'tag' | 'delete'
interface Props {
/** Fiches sélectionnées */
selected: MediaItem[]
/** Action terminée : on quitte le mode sélection */
onDone: () => void
}
/** Barre d'actions groupées (en bas, à la place de la barre de navigation). */
export default function SelectionBar({ selected, onDone }: Props) {
const actions = useLibraryActions()
const [panel, setPanel] = useState<Panel>(null)
const ids = selected.map((i) => i.id)
const none = selected.length === 0
const run = async (fn: () => Promise<void>) => {
setPanel(null)
await fn()
onDone()
}
return (
<>
<div className="safe-bottom fixed inset-x-0 bottom-0 z-40 border-t border-line bg-bg/95 backdrop-blur-md lg:start-60 lg:bottom-6 lg:mx-auto lg:max-w-xl lg:rounded-2xl lg:border lg:pb-0">
<div className="mx-auto grid max-w-2xl grid-cols-4 px-2" role="toolbar" aria-label={t('select.actions')}>
<BarButton icon={<CircleDot size={21} />} label={t('select.status')} onClick={() => setPanel('status')} disabled={none} />
<BarButton icon={<ListPlus size={21} />} label={t('select.list')} onClick={() => setPanel('list')} disabled={none} />
<BarButton icon={<Tag size={21} />} label={t('select.tag')} onClick={() => setPanel('tag')} disabled={none} />
<BarButton icon={<Trash2 size={21} />} label={t('common.delete')} onClick={() => setPanel('delete')} disabled={none} danger />
</div>
</div>
{panel === 'status' && (
<PickerSheet title={t('select.statusTitle', { count: selected.length })} onClose={() => setPanel(null)}>
{STATUSES.map((s) => {
const already = selected.every((i) => i.status === s.value)
return (
<button
key={s.value}
onClick={() => void run(() => actions.setStatus(ids, s.value as WatchStatus))}
disabled={already}
className="flex w-full items-center gap-3 rounded-xl px-3 py-3.5 text-start text-[15px] text-ink active:bg-surface-2 disabled:opacity-40"
>
<StatusDot status={s.value} className="size-2.5" />
{s.label}
</button>
)
})}
</PickerSheet>
)}
{panel === 'list' && <ListPicker selected={selected} onClose={() => setPanel(null)} run={run} />}
{panel === 'tag' && <TagPicker selected={selected} onClose={() => setPanel(null)} run={run} />}
<ConfirmDialog
open={panel === 'delete'}
title={t('confirm.title')}
message={t('select.deleteConfirm', { count: selected.length })}
confirmLabel={t('common.delete')}
onConfirm={() => void run(() => actions.deleteItems(ids))}
onCancel={() => setPanel(null)}
/>
</>
)
}
function BarButton({ icon, label, onClick, disabled, danger }: { icon: ReactNode; label: string; onClick: () => void; disabled?: boolean; danger?: boolean }) {
return (
<button
onClick={onClick}
disabled={disabled}
className={cx('flex flex-col items-center gap-1 pb-2 pt-2.5 text-[11px] font-medium transition-colors disabled:opacity-35', danger ? 'text-accent' : 'text-ink')}
>
{icon}
{label}
</button>
)
}
/** Petite feuille en bas de l'écran ; Échap ou le geste retour la ferment sans quitter la sélection. */
function PickerSheet({ title, onClose, children }: { title: string; onClose: () => void; children: ReactNode }) {
useEscape(onClose)
useBackToClose(onClose)
return (
<div className="fixed inset-0 z-[60] flex items-end justify-center bg-black/70 sm:items-center" onClick={onClose}>
<div
role="dialog"
aria-modal="true"
aria-label={title}
className="sheet-in safe-bottom max-h-[85dvh] w-full max-w-md overflow-y-auto overscroll-contain rounded-t-3xl border border-line-strong bg-surface p-3 sm:rounded-3xl"
onClick={(e) => e.stopPropagation()}
>
<div className="mb-1 flex items-center justify-between gap-2 ps-3">
<h2 className="text-base font-semibold">{title}</h2>
<button onClick={onClose} className="grid size-10 place-items-center rounded-full text-ink-3" aria-label={t('common.close')}>
<X size={20} />
</button>
</div>
{children}
</div>
</div>
)
}
type Run = (fn: () => Promise<void>) => Promise<void>
function ListPicker({ selected, onClose, run }: { selected: MediaItem[]; onClose: () => void; run: Run }) {
const { lists } = useMedia()
const actions = useLibraryActions()
const ids = selected.map((i) => i.id)
return (
<PickerSheet title={t('select.listTitle', { count: selected.length })} onClose={onClose}>
{lists.length === 0 && <p className="px-3 pb-3 text-sm text-ink-3">{t('select.noLists')}</p>}
<ul className="divide-y divide-line">
{lists.map((l) => {
const inside = selected.filter((i) => i.listIds?.includes(l.id)).length
return (
<li key={l.id} className="flex items-center gap-2 px-3 py-2.5">
<div className="min-w-0 flex-1">
<p className="truncate text-[15px]">{l.name}</p>
<p className="text-xs text-ink-3">{t('select.inList', { n: inside, total: selected.length })}</p>
</div>
<button
onClick={() => void run(() => actions.removeFromList(ids, l.id))}
disabled={inside === 0}
className="grid size-9 place-items-center rounded-full border border-line text-ink-2 disabled:opacity-30"
aria-label={t('select.removeFrom', { list: l.name })}
>
<Minus size={16} />
</button>
<button
onClick={() => void run(() => actions.addToList(ids, l.id))}
disabled={inside === selected.length}
className="grid size-9 place-items-center rounded-full bg-accent-fill text-on-accent disabled:opacity-30"
aria-label={t('select.addTo', { list: l.name })}
>
<Plus size={16} />
</button>
</li>
)
})}
</ul>
<div className="mt-2 px-1 pb-1">
<NewListForm onCreated={(l) => void run(() => actions.addToList(ids, l.id, l.name))} />
</div>
</PickerSheet>
)
}
function TagPicker({ selected, onClose, run }: { selected: MediaItem[]; onClose: () => void; run: Run }) {
const { items } = useMedia()
const actions = useLibraryActions()
const ids = selected.map((i) => i.id)
const existing = useMemo(() => allTags(items), [items])
// Tags déjà portés par au moins une fiche sélectionnée (pour les retirer)
const present = useMemo(() => allTags(selected), [selected])
const [text, setText] = useState('')
const q = normalizeText(text)
const suggestions = existing.filter((tag) => !selected.every((i) => hasTag(i, tag)) && (!q || normalizeText(tag).includes(q))).slice(0, 16)
const add = (raw: string) => {
const tag = cleanTag(raw, existing)
if (tag) void run(() => actions.addTag(ids, tag))
}
return (
<PickerSheet title={t('select.tagTitle', { count: selected.length })} onClose={onClose}>
<form
className="flex gap-2 px-1"
onSubmit={(e) => {
e.preventDefault()
add(text)
}}
>
<input className="field" value={text} onChange={(e) => setText(e.target.value)} placeholder={t('tags.placeholder')} maxLength={40} autoFocus enterKeyHint="done" aria-label={t('tags.label')} />
<button disabled={!cleanTag(text)} className="btn btn-light shrink-0 px-4 text-sm">
{t('common.add')}
</button>
</form>
{suggestions.length > 0 && (
<div className="mt-3 flex flex-wrap gap-1.5 px-1">
{suggestions.map((tag) => (
<button key={tag} onClick={() => add(tag)} className="chip py-1! text-xs">
+ {tag}
</button>
))}
</div>
)}
{present.length > 0 && (
<div className="mt-5 border-t border-line px-1 pt-3">
<span className="label">{t('select.removeTag')}</span>
<div className="flex flex-wrap gap-1.5">
{present.map((tag) => (
<button key={tag} onClick={() => void run(() => actions.removeTag(ids, tag))} className="chip py-1! text-xs" aria-label={t('common.removeX', { name: tag })}>
#{tag} <X size={13} />
</button>
))}
</div>
</div>
)}
<p className="mt-4 px-1 pb-1 text-xs text-ink-3">{t('tags.private')}</p>
</PickerSheet>
)
}
@@ -0,0 +1,98 @@
import { t } from '../../i18n'
import { useCallback, useMemo } from 'react'
import { STATUS_BY_VALUE } from '../../lib/constants'
import { hasTag, statusPatch } from '../../lib/bulk'
import { LIMITS } from '../../lib/security'
import { normalizeText } from '../../lib/utils'
import { useMedia } from '../../store'
import type { MediaItem, WatchStatus } from '../../types'
import { useToast } from '../Toast'
/**
* Actions sur la bibliothèque qui proposent « Annuler » (suppression, statut, listes, tags).
* L'annulation remet les fiches exactement comme avant (voir `restore` dans le store).
*/
export function useLibraryActions() {
const { items, lists, updateMany, removeMany, restore } = useMedia()
const toast = useToast()
const pick = useCallback((ids: Iterable<string>) => {
const wanted = new Set(ids)
return items.filter((i) => wanted.has(i.id))
}, [items])
const undoable = useCallback(
(message: string, snapshots: MediaItem[]) => toast.show(message, { undo: () => restore(snapshots) }),
[toast, restore],
)
const listName = useCallback((id: string) => lists.find((l) => l.id === id)?.name ?? '', [lists])
return useMemo(
() => ({
/** Supprime des fiches (avec « Annuler »). */
async deleteItems(ids: Iterable<string>) {
const snapshots = pick(ids)
if (!snapshots.length) return
await removeMany(snapshots.map((i) => i.id))
undoable(
snapshots.length === 1 ? t('toast.deleted', { title: snapshots[0].title }) : t('toast.deletedMany', { count: snapshots.length }),
snapshots,
)
},
/** Change le statut (dates et épisodes suivent, comme sur la fiche). */
async setStatus(ids: Iterable<string>, status: WatchStatus) {
const snapshots = pick(ids).filter((i) => i.status !== status)
if (!snapshots.length) return
await updateMany(snapshots.map((i) => ({ id: i.id, patch: statusPatch(i, status) })))
const label = STATUS_BY_VALUE[status].label
undoable(
snapshots.length === 1 ? t('toast.status', { title: snapshots[0].title, status: label }) : t('toast.statusMany', { count: snapshots.length, status: label }),
snapshots,
)
},
async addToList(ids: Iterable<string>, listId: string, name?: string) {
const snapshots = pick(ids).filter((i) => !i.listIds?.includes(listId))
if (!snapshots.length) return
await updateMany(snapshots.map((i) => ({ id: i.id, patch: { listIds: [...(i.listIds ?? []), listId] } })))
undoable(t('toast.addedToList', { count: snapshots.length, list: name ?? listName(listId) }), snapshots)
},
async removeFromList(ids: Iterable<string>, listId: string) {
const snapshots = pick(ids).filter((i) => i.listIds?.includes(listId))
if (!snapshots.length) return
await updateMany(snapshots.map((i) => ({ id: i.id, patch: { listIds: i.listIds!.filter((x) => x !== listId) } })))
undoable(
snapshots.length === 1 ? t('toast.removedFromList', { title: snapshots[0].title, list: listName(listId) }) : t('toast.removedFromListMany', { count: snapshots.length, list: listName(listId) }),
snapshots,
)
},
async addTag(ids: Iterable<string>, tag: string) {
const snapshots = pick(ids).filter((i) => !hasTag(i, tag) && (i.tags?.length ?? 0) < LIMITS.tags)
if (!snapshots.length || !tag) return
await updateMany(snapshots.map((i) => ({ id: i.id, patch: { tags: [...(i.tags ?? []), tag] } })))
undoable(t('toast.tagged', { count: snapshots.length, tag }), snapshots)
},
async removeTag(ids: Iterable<string>, tag: string) {
const key = normalizeText(tag)
const snapshots = pick(ids).filter((i) => hasTag(i, tag))
if (!snapshots.length) return
await updateMany(
snapshots.map((i) => {
const tags = i.tags!.filter((x) => normalizeText(x) !== key)
return { id: i.id, patch: { tags: tags.length ? tags : undefined } }
}),
)
undoable(t('toast.untagged', { count: snapshots.length, tag }), snapshots)
},
/** « Annuler » pour un changement fait ailleurs (fiche) : remet ces copies. */
offerUndo: undoable,
}),
[pick, removeMany, updateMany, undoable, listName],
)
}
+48 -6
View File
@@ -15,6 +15,9 @@ import { backdropSrcSet, tmdbSized } from '../../lib/tmdbImage'
import { renderItemCard, slug } from '../../lib/shareCard'
import { cx, formatDate, formatDuration, formatRating, todayISO } from '../../lib/utils'
import { useMedia } from '../../store'
import { allTags, cleanTag } from '../../lib/bulk'
import { useLibraryActions } from '../library/useLibraryActions'
import TagInput from '../TagInput'
import type { MediaInput, MediaItem, RatingScale, WatchStatus } from '../../types'
import ConfirmDialog from '../ConfirmDialog'
import EpisodeList from '../EpisodeList'
@@ -44,7 +47,8 @@ interface Props {
* Vu / En cours / À voir, note, coup de cœur, avis, épisodes, casting et note moyenne du public.
*/
export default function TitleSheet({ item: initial, seed, onClose, onGoToSettings }: Props) {
const { items, settings, add, update, remove, lists, patchMany } = useMedia()
const { items, settings, add, update, lists, patchMany } = useMedia()
const actions = useLibraryActions()
const social = useSocial()
useScrollLock()
useEscape(onClose)
@@ -184,7 +188,11 @@ export default function TitleSheet({ item: initial, seed, onClose, onGoToSetting
const cap = episodeCap(item ?? { episodesTotal: data.episodesTotal, seasons: data.seasons })
if (episodic && cap) patch.episodesWatched = cap
}
void save(patch)
// Changement de statut d'un titre déjà suivi : « Annuler » remet la fiche telle quelle (dates, épisodes…)
const before = item
void save(patch).then(() => {
if (before) actions.offerUndo(t('toast.status', { title: before.title, status: STATUS_BY_VALUE[s].label }), [before])
})
}
/**
@@ -255,13 +263,25 @@ export default function TitleSheet({ item: initial, seed, onClose, onGoToSetting
}
}
const onDelete = async () => {
const onDelete = () => {
if (!item) return
setConfirmDelete(false)
await remove(item.id)
// Le message « Supprimé · Annuler » reste affiché après la fermeture de la fiche
void actions.deleteItems([item.id])
onClose()
}
/** Suivi modifié ; retirer le titre d'une liste propose « Annuler ». */
const changeTracking = (patch: Partial<MediaInput>) => {
if (!item) return
const before = item
const removed = patch.listIds ? (before.listIds ?? []).filter((id) => !patch.listIds!.includes(id)) : []
void update(before.id, patch).then(() => {
const list = removed.length === 1 ? lists.find((l) => l.id === removed[0]) : undefined
if (list) actions.offerUndo(t('toast.removedFromList', { title: before.title, list: list.name }), [before])
})
}
const heroImage = backdrop ?? extras?.backdrop
const average = extras?.average ?? data.publicRating
const source = externalId?.startsWith('anilist:') ? 'AniList' : externalId ? 'TMDB' : undefined
@@ -325,6 +345,16 @@ export default function TitleSheet({ item: initial, seed, onClose, onGoToSetting
<Check size={13} className="text-accent" /> {t('title.inLibrary')} · {STATUS_BY_VALUE[status].label}
</p>
)}
{/* Mes tags perso : discrets, visibles par moi seul */}
{item?.tags && item.tags.length > 0 && (
<ul className="mt-2 flex flex-wrap gap-1.5" aria-label={t('tags.label')}>
{item.tags.map((tag) => (
<li key={tag} className="rounded-full border border-line px-2 py-0.5 text-[11px] text-ink-3">
#{tag}
</li>
))}
</ul>
)}
</div>
</div>
@@ -496,7 +526,7 @@ export default function TitleSheet({ item: initial, seed, onClose, onGoToSetting
)}
{/* Mon suivi : dates, plateforme, listes, revisionnages */}
{item && <Tracking item={item} lists={lists} onChange={(patch) => void update(item.id, patch)} />}
{item && <Tracking item={item} lists={lists} tagSuggestions={allTags(items)} onChange={changeTracking} />}
</div>
</div>
</div>
@@ -689,7 +719,7 @@ function Synopsis({ text }: { text: string }) {
}
/** Dates, plateforme, listes et revisionnages : enregistrés dès qu'on les change. */
function Tracking({ item, lists, onChange }: { item: MediaItem; lists: { id: string; name: string }[]; onChange: (p: Partial<MediaInput>) => void }) {
function Tracking({ item, lists, tagSuggestions, onChange }: { item: MediaItem; lists: { id: string; name: string }[]; tagSuggestions: string[]; onChange: (p: Partial<MediaInput>) => void }) {
const [open, setOpen] = useState(false)
// Plus récent en premier (la sauvegarde les range dans l'autre sens)
const rewatches = [...(item.rewatchDates ?? [])].sort().reverse()
@@ -741,6 +771,18 @@ function Tracking({ item, lists, onChange }: { item: MediaItem; lists: { id: str
)}
<NewListForm onCreated={(l) => onChange({ listIds: [...(item.listIds ?? []), l.id] })} />
</div>
<div>
<span className="label">{t('tags.label')}</span>
<TagInput
value={item.tags ?? []}
onChange={(tags) => onChange({ tags: tags.length ? tags.slice(0, 30) : undefined })}
suggestions={tagSuggestions}
placeholder={t('tags.placeholder')}
normalize={(v) => cleanTag(v, tagSuggestions)}
showAll
/>
<p className="mt-1.5 text-xs text-ink-3">{t('tags.private')}</p>
</div>
<div>
<span className="label">{t('form.rewatches')}</span>
{rewatches.length > 0 && (