Import « Coller une liste » : depuis l'app Notes ou n'importe quel texte
deploy / deploy (push) Successful in 52s
deploy / deploy (push) Successful in 52s
- 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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YVo1qxKoBQCaMd7Ue8PGbe
This commit is contained in:
23 files changed
+884
-17
No files matched your search
+115
-15
@@ -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<Set<string>>(new Set())
|
||||
const [excluded, setExcluded] = useState<Set<string>>(new Set())
|
||||
const [now, setNow] = useState(Date.now())
|
||||
const token = useRef<CancelToken>({ cancelled: false })
|
||||
const fileRef = useRef<HTMLInputElement>(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<ImportEntry[]>) => {
|
||||
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 }) {
|
||||
<div className="sheet sheet-in z-[60]" role="dialog" aria-modal="true" aria-label={t('import.title')}>
|
||||
<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-none lg:px-10">
|
||||
{step === 'input' || step === 'preview' ? (
|
||||
{step === 'input' || step === 'review' || step === 'preview' ? (
|
||||
<button onClick={back} className="grid size-10 shrink-0 place-items-center rounded-full text-ink-2 rtl:-scale-x-100" aria-label={t('import.back')}>
|
||||
<ArrowLeft size={21} />
|
||||
</button>
|
||||
) : (
|
||||
<span className="size-10 shrink-0" />
|
||||
)}
|
||||
<h2 className="min-w-0 flex-1 truncate text-center text-base font-semibold">{info && step !== 'source' ? info.name : t('import.title')}</h2>
|
||||
<h2 className="min-w-0 flex-1 truncate text-center text-base font-semibold">{info && step !== 'source' ? sourceName(info) : t('import.title')}</h2>
|
||||
<button onClick={close} className="grid size-10 shrink-0 place-items-center rounded-full text-ink-2" aria-label={t('common.close')}>
|
||||
<X size={22} />
|
||||
</button>
|
||||
@@ -207,7 +247,7 @@ export default function ImportWizard({ onClose }: { onClose: () => void }) {
|
||||
>
|
||||
<span className="grid size-12 shrink-0 place-items-center rounded-xl border border-line-strong bg-surface-2 text-sm font-bold tracking-tight text-ink">{s.mark}</span>
|
||||
<span className="min-w-0 flex-1">
|
||||
<span className="block font-semibold">{s.name}</span>
|
||||
<span className="block font-semibold">{sourceName(s)}</span>
|
||||
<span className="mt-0.5 block text-xs text-ink-3">{t(`import.src.${s.id}` as TKey)}</span>
|
||||
</span>
|
||||
<span className="text-ink-3 rtl:-scale-x-100">→</span>
|
||||
@@ -236,7 +276,36 @@ export default function ImportWizard({ onClose }: { onClose: () => void }) {
|
||||
<p className="mt-5 rounded-2xl border border-dashed border-line-strong p-3.5 text-xs leading-relaxed text-ink-2">{t('import.noTmdb')}</p>
|
||||
)}
|
||||
|
||||
{info.id === 'anilist' ? (
|
||||
{info.id === 'text' ? (
|
||||
<div className="mt-6">
|
||||
<textarea
|
||||
className="field min-h-56 w-full resize-y py-3 leading-relaxed"
|
||||
value={pasted}
|
||||
onChange={(e) => setPasted(e.target.value.slice(0, TEXT_MAX_CHARS))}
|
||||
placeholder={t('import.text.placeholder')}
|
||||
aria-label={t('import.text.name')}
|
||||
spellCheck={false}
|
||||
/>
|
||||
<p className="mt-4 text-sm font-medium">{t('import.text.default')}</p>
|
||||
<div className="mt-2 grid grid-cols-2 gap-2" role="radiogroup" aria-label={t('import.text.default')}>
|
||||
{(['termine', 'a_voir'] as const).map((st) => (
|
||||
<button
|
||||
key={st}
|
||||
type="button"
|
||||
role="radio"
|
||||
aria-checked={defaultStatus === st}
|
||||
onClick={() => setDefaultStatus(st)}
|
||||
className={cx('btn', defaultStatus === st ? 'btn-primary' : 'btn-ghost')}
|
||||
>
|
||||
{st === 'termine' ? t('import.text.seen') : t('status.a_voir')}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<button type="button" onClick={onText} disabled={!pasted.trim()} className="btn btn-primary mt-5 w-full">
|
||||
{t('import.text.analyze')}
|
||||
</button>
|
||||
</div>
|
||||
) : info.id === 'anilist' ? (
|
||||
<form
|
||||
className="mt-6 flex gap-2"
|
||||
onSubmit={(e) => {
|
||||
@@ -312,6 +381,37 @@ export default function ImportWizard({ onClose }: { onClose: () => void }) {
|
||||
</div>
|
||||
)}
|
||||
|
||||
{step === 'review' && source === 'text' && (
|
||||
<ImportTextReview
|
||||
entries={entries as TextEntry[]}
|
||||
matches={matches}
|
||||
unsure={unsure}
|
||||
excluded={excluded}
|
||||
tmdbKey={settings.tmdbKey}
|
||||
onToggle={(key) =>
|
||||
setExcluded((prev) => {
|
||||
const next = new Set(prev)
|
||||
if (!next.delete(key)) next.add(key)
|
||||
return next
|
||||
})
|
||||
}
|
||||
onChange={(key, match) => {
|
||||
setMatches((prev) => new Map(prev).set(key, match))
|
||||
setUnsure((prev) => {
|
||||
const next = new Set(prev)
|
||||
next.delete(key)
|
||||
return next
|
||||
})
|
||||
setExcluded((prev) => {
|
||||
const next = new Set(prev)
|
||||
next.delete(key)
|
||||
return next
|
||||
})
|
||||
}}
|
||||
onContinue={() => setStep('preview')}
|
||||
/>
|
||||
)}
|
||||
|
||||
{step === 'preview' && plan && kinds && (
|
||||
<>
|
||||
<p className="text-sm text-ink-2">{t('import.found', { n: entries.length })}</p>
|
||||
@@ -336,7 +436,7 @@ export default function ImportWizard({ onClose }: { onClose: () => void }) {
|
||||
<Line label={t('import.notFound')} value={plan.notFound.length} accent={plan.notFound.length > 0} />
|
||||
</div>
|
||||
|
||||
{plan.notFound.length > 0 && (
|
||||
{source !== 'text' && plan.notFound.length > 0 && (
|
||||
<div className="mt-3">
|
||||
<button onClick={() => setShowMissing((v) => !v)} className="flex items-center gap-1.5 text-sm font-medium text-ink-2" aria-expanded={showMissing}>
|
||||
<ChevronDown size={16} className={cx('transition-transform', showMissing && 'rotate-180')} />
|
||||
|
||||
Reference in new issue
Block a user