Bibliothèque : tags perso, actions groupées et « Annuler »

- Tags personnels libres sur chaque titre (fiche → Mon suivi), affichés discrètement
  dans la fiche, filtre par tag dans le catalogue, suggestions = tags déjà utilisés.
  Synchronisés avec la fiche (JSON), inclus dans l'export/import (et repris des tags
  de l'ancienne appli). Privés : retirés par public_item (migration) et côté client.
- Actions groupées dans le catalogue : appui long (mobile), case au survol (ordinateur)
  ou bouton « Sélectionner » ; tout sélectionner, compteur ; statut, listes (ajout /
  retrait), tag (ajout / retrait), suppression avec confirmation. Échap / retour quittent.
- Toast global accessible (role=status) avec « Annuler » (~6 s) après suppression,
  changement de statut, retrait d'une liste, actions groupées. La restauration remet la
  fiche à l'identique avec un updatedAt plus récent que la suppression : la synchro LWW
  recrée bien la fiche côté serveur.
- Store : updateMany, removeMany, restore.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YVo1qxKoBQCaMd7Ue8PGbe
This commit is contained in:
Claude committed 2026-10-09 15:16:32 +00:00
1 parent c246b16e7e
commit 94c27739b2
35 files changed
+1795 -22

No files matched your search

+18 -1
View File
@@ -18,7 +18,7 @@ import {
safeSeasons,
safeStringList,
} from './security'
import { todayISO, uid } from './utils'
import { normalizeText, todayISO, uid } from './utils'
const TYPES = new Set<string>(MEDIA_TYPES.map((t) => t.value))
const STATUS_SET = new Set<string>(STATUSES.map((s) => s.value))
@@ -62,6 +62,21 @@ function safeDates(v: unknown): string[] | undefined {
return out.length ? out : undefined
}
/** Tags perso : texte court, sans doublon (casse et accents ignorés), 30 max. */
export function safeTags(v: unknown): string[] | undefined {
const seen = new Set<string>()
const out: string[] = []
for (const tag of safeStringList(v, LIMITS.tags * 2, LIMITS.tagLength)) {
const s = tag.replace(/\s+/g, ' ').replace(/^#+/, '').trim()
const key = normalizeText(s)
if (!s || seen.has(key)) continue
seen.add(key)
out.push(s)
if (out.length >= LIMITS.tags) break
}
return out.length ? out : undefined
}
/** Valide et nettoie une fiche (import, synchro, écriture locale). Renvoie null si inutilisable. */
export function normalizeItem(raw: unknown): MediaItem | null {
if (!isPlainObject(raw)) return null
@@ -83,6 +98,7 @@ export function normalizeItem(raw: unknown): MediaItem | null {
const cap = episodeCap({ episodesTotal, seasons })
if (cap && episodesWatched > cap) episodesWatched = cap
const listIds = safeStringList(r.listIds, LIMITS.lists, 64).filter(isSafeId)
const tags = safeTags(r.tags)
return {
id: isSafeId(r.id) ? r.id : uid(),
title,
@@ -111,6 +127,7 @@ export function normalizeItem(raw: unknown): MediaItem | null {
externalId: isSafeExternalId(r.externalId) ? r.externalId : undefined,
top: normalizeTop(r.top),
listIds: listIds.length ? listIds : undefined,
tags,
countries: safeCountries(r.countries),
rewatchDates: safeDates(r.rewatchDates),
publicRating: (() => {
+43
View File
@@ -0,0 +1,43 @@
import type { MediaInput, MediaItem, WatchStatus } from '../types'
import { TYPE_BY_VALUE } from './constants'
import { episodeCap } from './franchise'
import { LIMITS } from './security'
import { normalizeText, todayISO } from './utils'
/**
* Nouveau statut → ce qui change sur la fiche (mêmes règles que les boutons de la fiche) :
* « À voir » efface les dates, « Vu » date la fin (et coche tous les épisodes connus)…
*/
export function statusPatch(item: MediaItem, s: WatchStatus): Partial<MediaInput> {
const patch: Partial<MediaInput> = { status: s }
const episodic = TYPE_BY_VALUE[item.type].episodic
const today = todayISO()
if (s === 'a_voir') Object.assign(patch, { startDate: undefined, endDate: undefined })
if (s === 'en_cours') Object.assign(patch, { startDate: episodic && !item.episodesWatched ? item.startDate : (item.startDate ?? today), endDate: undefined })
if (s === 'termine') {
patch.endDate = item.status === 'termine' && item.endDate ? item.endDate : today
if (!item.startDate) patch.startDate = episodic && item.episodesWatched ? today : patch.endDate
const cap = episodeCap(item)
if (episodic && cap) patch.episodesWatched = cap
}
return patch
}
/** Tag saisi → tag enregistré : sans « # », espaces simplifiés, et même écriture qu'un tag existant. */
export function cleanTag(input: string, existing: string[] = []): string {
const s = input.replace(/\s+/g, ' ').replace(/^#+/, '').trim().slice(0, LIMITS.tagLength)
const key = normalizeText(s)
return existing.find((e) => normalizeText(e) === key) ?? s
}
/** Tous les tags utilisés dans la bibliothèque, du plus fréquent au moins fréquent. */
export function allTags(items: MediaItem[]): string[] {
const count = new Map<string, number>()
for (const i of items) for (const tag of i.tags ?? []) count.set(tag, (count.get(tag) ?? 0) + 1)
return [...count.entries()].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).map(([tag]) => tag)
}
export const hasTag = (item: MediaItem, tag: string) => {
const key = normalizeText(tag)
return !!item.tags?.some((x) => normalizeText(x) === key)
}
+12 -2
View File
@@ -86,8 +86,18 @@ function toCard(raw: unknown): ProfileCard | null {
}
}
/** Fiche de quelqu'un d'autre : ses tags et listes perso restent privés (même si un ancien serveur les renvoyait). */
function othersItem(v: unknown): MediaItem | null {
const item = normalizeItem(v)
if (item) {
delete item.tags
delete item.listIds
}
return item
}
const toItems = (v: unknown): MediaItem[] =>
Array.isArray(v) ? v.slice(0, 200).map(normalizeItem).filter((i): i is MediaItem => i !== null) : []
Array.isArray(v) ? v.slice(0, 200).map(othersItem).filter((i): i is MediaItem => i !== null) : []
function toProfile(raw: unknown): Profile | null {
const card = toCard(raw)
@@ -163,7 +173,7 @@ export async function getFeed(before?: string): Promise<FeedEntry[]> {
const out: FeedEntry[] = []
for (const r of raw.slice(0, 50)) {
if (!isPlainObject(r) || !isPlainObject(r.user)) continue
const item = normalizeItem(r.item)
const item = othersItem(r.item)
const name = username(r.user.username)
const createdAt = safeIso(r.created_at)
const kind = r.kind
+3 -1
View File
@@ -167,7 +167,8 @@ export function convertLegacyBackup(data: LegacyFile): { items: MediaItem[]; ski
const genres = splitGenres(rawGenres, isFilm)
if (isFilm && type === 'film' && countries.includes('JP') && rawGenres.includes('Animation')) genres.unshift('Anime')
for (const t of itemTags.get(r.id) ?? []) if (!genres.includes(t) && genres.length < LIMITS.genres) genres.push(t)
// Tags perso de l'ancienne appli → tags personnels (privés), plus mélangés aux genres
const tags = [...new Set((itemTags.get(r.id) ?? []).map((t) => t.slice(0, LIMITS.tagLength)))].slice(0, LIMITS.tags)
const note = typeof r.note === 'number' && Number.isFinite(r.note) && r.note > 0 ? Math.min(10, Math.round(r.note * 2 * 2) / 2) : undefined
const created = toISO(r.date_added) ?? now
@@ -192,6 +193,7 @@ export function convertLegacyBackup(data: LegacyFile): { items: MediaItem[]; ski
startDate,
endDate,
genres,
tags: tags.length ? tags : undefined,
notes: cleanText(
[cleanText(r.comment, LIMITS.notes), cleanText(r.director, LIMITS.shortText) ? `Réalisation : ${cleanText(r.director, LIMITS.shortText)}` : '']
.filter(Boolean)
+2
View File
@@ -26,6 +26,8 @@ export const LIMITS = {
notes: 20000,
overview: 10000,
genres: 40,
tags: 30,
tagLength: 40,
posterDataUrl: 3 * 1024 * 1024, // ~3 Mo par affiche en data URL
searchQuery: 200,
}