From c7a1f5062eed80fb6f722c915c36bf3aeb60fd7d Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 15:30:04 +0000 Subject: [PATCH] =?UTF-8?q?Import=20=C2=AB=20Coller=20une=20liste=20=C2=BB?= =?UTF-8?q?=20:=20depuis=20l'app=20Notes=20ou=20n'importe=20quel=20texte?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Une ligne par titre : note (4,5/5, 8/10, ★★★★), année, statut (vu, en cours, à voir), progression S3E12 et avis reconnus - Sections « Films », « Séries à voir »… appliquées aux lignes suivantes - Recherche TMDB + AniList, écran de vérification : décocher une ligne ou choisir un autre titre - Textes dans les 18 langues Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01YVo1qxKoBQCaMd7Ue8PGbe --- src/components/ImportTextReview.tsx | 195 +++++++++++++++++++++++ src/components/ImportWizard.tsx | 130 ++++++++++++++-- src/i18n/locales/ar.ts | 13 ++ src/i18n/locales/de.ts | 13 ++ src/i18n/locales/en.ts | 13 ++ src/i18n/locales/es.ts | 13 ++ src/i18n/locales/fr.ts | 13 ++ src/i18n/locales/hi.ts | 13 ++ src/i18n/locales/id.ts | 13 ++ src/i18n/locales/it.ts | 13 ++ src/i18n/locales/ja.ts | 13 ++ src/i18n/locales/ko.ts | 13 ++ src/i18n/locales/nl.ts | 13 ++ src/i18n/locales/pl.ts | 13 ++ src/i18n/locales/pt.ts | 13 ++ src/i18n/locales/ru.ts | 13 ++ src/i18n/locales/th.ts | 13 ++ src/i18n/locales/tr.ts | 13 ++ src/i18n/locales/vi.ts | 13 ++ src/i18n/locales/zh.ts | 13 ++ src/lib/import/resolve.ts | 107 ++++++++++++- src/lib/import/sources.ts | 2 +- src/lib/import/textList.ts | 233 ++++++++++++++++++++++++++++ 23 files changed, 884 insertions(+), 17 deletions(-) create mode 100644 src/components/ImportTextReview.tsx create mode 100644 src/lib/import/textList.ts diff --git a/src/components/ImportTextReview.tsx b/src/components/ImportTextReview.tsx new file mode 100644 index 0000000..a6b327f --- /dev/null +++ b/src/components/ImportTextReview.tsx @@ -0,0 +1,195 @@ +import { Check, Loader2, Search } from 'lucide-react' +import { useState } from 'react' +import { t, type TKey } from '../i18n' +import { searchAll, type SearchResult } from '../lib/catalogApi' +import { matchFor, type Match } from '../lib/import/resolve' +import type { TextEntry } from '../lib/import/textList' +import { cx } from '../lib/utils' +import Poster from './Poster' +import { RatingBadge } from './Rating' + +/** + * Vérification d'une liste collée : chaque ligne avec le titre trouvé. + * On peut décocher une ligne, ou choisir un autre titre (recherche intégrée). + */ +export default function ImportTextReview({ + entries, + matches, + unsure, + excluded, + tmdbKey, + onToggle, + onChange, + onContinue, +}: { + entries: TextEntry[] + matches: Map + unsure: Set + excluded: Set + tmdbKey?: string + onToggle: (key: string) => void + onChange: (key: string, match: Match) => void + onContinue: () => void +}) { + const [editing, setEditing] = useState() + const kept = entries.filter((e) => !excluded.has(e.key) && matches.has(e.key)).length + const toCheck = entries.filter((e) => !excluded.has(e.key) && (unsure.has(e.key) || !matches.has(e.key))).length + // Les lignes à vérifier d'abord + const ordered = [...entries].sort((a, b) => rank(a) - rank(b)) + function rank(e: TextEntry) { + return !matches.has(e.key) ? 0 : unsure.has(e.key) ? 1 : 2 + } + + return ( + <> +

{t('import.text.reviewHint')}

+ {toCheck > 0 &&

{t('import.text.toCheck', { n: toCheck })}

} +
    + {ordered.map((e) => { + const m = matches.get(e.key) + const off = excluded.has(e.key) + const doubt = !m || unsure.has(e.key) + return ( +
  • +
    + +
    + +
    +
    +

    {e.line}

    + {m ? ( +

    + {m.result.title} + + {' · '} + {t(`type.${m.meta.type ?? m.result.typeGuess}` as TKey)} + {m.result.year ? ` · ${m.result.year}` : ''} + +

    + ) : ( +

    {t('import.text.none')}

    + )} +
    + {t(`status.${e.status}` as TKey)} + + {e.notes && « {e.notes} »} +
    +
    + {doubt && m && !off && {t('import.text.check')}} + +
    +
    +
    + {editing === e.key && ( + { + onChange(e.key, match) + setEditing(undefined) + }} + /> + )} +
  • + ) + })} +
+ + + ) +} + +/** Recherche d'un autre titre pour une ligne. */ +function Picker({ initial, tmdbKey, onPick }: { initial: string; tmdbKey?: string; onPick: (m: Match) => void }) { + const [q, setQ] = useState(initial) + const [results, setResults] = useState() + const [busy, setBusy] = useState(false) + const [error, setError] = useState() + + const run = async () => { + const query = q.trim() + if (!query || busy) return + setBusy(true) + setError(undefined) + try { + setResults((await searchAll(query, tmdbKey?.trim() || undefined)).slice(0, 8)) + } catch (err) { + setError((err as Error)?.message || t('search.offline')) + } finally { + setBusy(false) + } + } + + const pick = async (r: SearchResult) => { + setBusy(true) + try { + onPick(await matchFor(r, tmdbKey?.trim() || undefined)) + } finally { + setBusy(false) + } + } + + return ( +
+
{ + ev.preventDefault() + void run() + }} + > + setQ(ev.target.value.slice(0, 200))} + aria-label={t('import.text.search')} + enterKeyHint="search" + autoFocus + /> + +
+ {error &&

{error}

} + {results && !results.length &&

{t('import.text.none')}

} + {results && results.length > 0 && ( +
    + {results.map((r) => ( +
  • + +
  • + ))} +
+ )} +
+ ) +} diff --git a/src/components/ImportWizard.tsx b/src/components/ImportWizard.tsx index 2d105b2..c829608 100644 --- a/src/components/ImportWizard.tsx +++ b/src/components/ImportWizard.tsx @@ -2,10 +2,12 @@ import { ArrowLeft, Check, ChevronDown, FileUp, Loader2, X } from 'lucide-react' import { useEffect, useMemo, useRef, useState, type DragEvent } from 'react' import { t, type TKey } from '../i18n' import { useBackToClose } from '../lib/backNav' +import ImportTextReview from './ImportTextReview' import { useEscape } from '../lib/escape' import { ImportFileError, readImportFile, type TextFile } from '../lib/import/files' import { buildImportPlan, countByKind, type ImportPlan } from '../lib/import/merge' -import { CancelledError, fetchAniListUser, isAniListUserName, resolveEntries, type CancelToken, type Match, type Progress } from '../lib/import/resolve' +import { CancelledError, fetchAniListUser, isAniListUserName, resolveEntries, resolveTextEntries, withProgress, type CancelToken, type Match, type Progress } from '../lib/import/resolve' +import { parseTextList, TEXT_MAX_CHARS, type TextEntry } from '../lib/import/textList' import { letterboxdRole, parseLetterboxd, parseMal, parseTvTime, type ImportEntry, type ImportSource } from '../lib/import/sources' import { useScrollLock } from '../lib/scrollLock' import { LIMITS } from '../lib/security' @@ -18,16 +20,18 @@ import { useMedia } from '../store' * Tout se passe sur l'appareil ; la synchro existante enverra ensuite les fiches au compte. */ -type Step = 'source' | 'input' | 'working' | 'preview' | 'done' +type Step = 'source' | 'input' | 'working' | 'review' | 'preview' | 'done' const SOURCES: { id: ImportSource; name: string; mark: string; accept?: string; multiple?: boolean }[] = [ + { id: 'text', name: '', mark: 'Aa' }, { id: 'letterboxd', name: 'Letterboxd', mark: 'Lb', accept: '.zip,.csv,application/zip,text/csv', multiple: true }, { id: 'tvtime', name: 'TV Time', mark: 'TV', accept: '.zip,.csv,application/zip,text/csv', multiple: true }, { id: 'mal', name: 'MyAnimeList', mark: 'MAL', accept: '.xml,.gz,application/xml,text/xml,application/gzip' }, { id: 'anilist', name: 'AniList', mark: 'AL' }, ] -const NEEDS_TMDB: ImportSource[] = ['letterboxd', 'tvtime'] +const NEEDS_TMDB: ImportSource[] = ['text', 'letterboxd', 'tvtime'] +const sourceName = (s: { id: ImportSource; name: string }) => (s.id === 'text' ? t('import.text.name') : s.name) /** Message lisible pour une erreur de lecture / de réseau. */ function errorText(e: unknown): string { @@ -69,6 +73,11 @@ export default function ImportWizard({ onClose }: { onClose: () => void }) { const [showMissing, setShowMissing] = useState(false) const [result, setResult] = useState<{ added: number; updated: number; unchanged: number; notFound: number }>() const [dragging, setDragging] = useState(false) + // Liste collée + const [pasted, setPasted] = useState('') + const [defaultStatus, setDefaultStatus] = useState<'termine' | 'a_voir'>('termine') + const [unsure, setUnsure] = useState>(new Set()) + const [excluded, setExcluded] = useState>(new Set()) const [now, setNow] = useState(Date.now()) const token = useRef({ cancelled: false }) const fileRef = useRef(null) @@ -93,10 +102,15 @@ export default function ImportWizard({ onClose }: { onClose: () => void }) { const info = SOURCES.find((s) => s.id === source) const hasTmdb = !!settings.tmdbKey?.trim() - const plan: ImportPlan | undefined = useMemo( - () => (step === 'preview' ? buildImportPlan(entries, matches, items, { includeUnmatched }) : undefined), - [step, entries, matches, items, includeUnmatched], - ) + const plan: ImportPlan | undefined = useMemo(() => { + if (step !== 'preview') return undefined + // Liste collée : seulement les lignes gardées, avec la progression « S3E12 » convertie en épisodes + const list = + source === 'text' + ? (entries as TextEntry[]).filter((e) => !excluded.has(e.key) && matches.has(e.key)).map((e) => withProgress(e, matches.get(e.key))) + : entries + return buildImportPlan(list, matches, items, { includeUnmatched: source === 'text' ? false : includeUnmatched }) + }, [step, source, entries, matches, items, includeUnmatched, excluded]) const run = async (load: () => Promise) => { const tk = { cancelled: false } @@ -127,10 +141,36 @@ export default function ImportWizard({ onClose }: { onClose: () => void }) { const onFiles = (list: FileList | null | undefined) => { const files = Array.from(list ?? []) if (fileRef.current) fileRef.current.value = '' - if (!files.length || !source || source === 'anilist') return + if (!files.length || !source || source === 'anilist' || source === 'text') return void run(() => readEntries(source, files)) } + const onText = () => { + const list = parseTextList(pasted, { defaultStatus }) + if (!list.length) return setError(t('import.err.empty')) + const tk = { cancelled: false } + token.current = tk + setError(undefined) + setEntries(list) + setStep('working') + setPhase('resolving') + setProgress({ done: 0, total: list.length }) + resolveTextEntries(list, { tmdbKey: settings.tmdbKey, token: tk, onProgress: (p) => !tk.cancelled && setProgress(p) }) + .then(({ found, unsure }) => { + if (tk.cancelled) return + setEntries([...list]) + setMatches(found) + setUnsure(unsure) + setExcluded(new Set()) + setStep('review') + }) + .catch((e) => { + if (e instanceof CancelledError || tk.cancelled) return + setError(errorText(e)) + setStep('input') + }) + } + const onAniList = () => { const name = userName.trim() if (!isAniListUserName(name)) return setError(t('import.err.user')) @@ -148,7 +188,7 @@ export default function ImportWizard({ onClose }: { onClose: () => void }) { setPhase('saving') try { await importItems([...plan.added, ...plan.updated], 'merge') - setResult({ added: plan.added.length, updated: plan.updated.length, unchanged: plan.unchanged, notFound: includeUnmatched ? 0 : plan.notFound.length }) + setResult({ added: plan.added.length, updated: plan.updated.length, unchanged: plan.unchanged, notFound: includeUnmatched || source === 'text' ? 0 : plan.notFound.length }) setStep('done') } catch (e) { setError(errorText(e)) @@ -164,7 +204,7 @@ export default function ImportWizard({ onClose }: { onClose: () => void }) { const back = () => { setError(undefined) - setStep(step === 'preview' ? 'input' : 'source') + setStep(step === 'preview' ? (source === 'text' ? 'review' : 'input') : step === 'review' ? 'input' : 'source') } const pct = progress.total ? Math.round((progress.done / progress.total) * 100) : 0 @@ -175,14 +215,14 @@ export default function ImportWizard({ onClose }: { onClose: () => void }) {
- {step === 'input' || step === 'preview' ? ( + {step === 'input' || step === 'review' || step === 'preview' ? ( ) : ( )} -

{info && step !== 'source' ? info.name : t('import.title')}

+

{info && step !== 'source' ? sourceName(info) : t('import.title')}

@@ -207,7 +247,7 @@ export default function ImportWizard({ onClose }: { onClose: () => void }) { > {s.mark} - {s.name} + {sourceName(s)} {t(`import.src.${s.id}` as TKey)} → @@ -236,7 +276,36 @@ export default function ImportWizard({ onClose }: { onClose: () => void }) {

{t('import.noTmdb')}

)} - {info.id === 'anilist' ? ( + {info.id === 'text' ? ( +
+