import-comicinfoxml #32

Merged
gpatti merged 3 commits from import-comicinfoxml into main 2026-04-20 03:09:44 +00:00
Showing only changes of commit b12decc802 - Show all commits

View File

@@ -1,6 +1,6 @@
'use client'
import { useEffect, useState, useRef, useCallback } from 'react'
import { useEffect, useMemo, useState, useRef, useCallback } from 'react'
import { useParams } from 'next/navigation'
import type { Tag, TagCategory, ImportedTag, TagMapping, Library } from '@/types'
@@ -335,6 +335,19 @@ function ImportedTagRow({
onMapped: () => void
onIgnore: () => void
}) {
// Auto-match: if prefix mapping exists, find a tag in that category matching the stripped name
const autoMatchedTagId = useMemo(() => {
const colonIdx = importedTag.name.indexOf(': ')
if (colonIdx <= 0) return ''
const prefix = importedTag.name.slice(0, colonIdx).trim().toLowerCase()
const mappedCategoryId = prefixMappings[prefix]
if (!mappedCategoryId) return ''
const strippedName = importedTag.name.slice(colonIdx + 2).trim().toLowerCase()
const group = tagsByCategory.find((g) => g.category.id === mappedCategoryId)
const match = group?.tags.find((t) => t.name.toLowerCase() === strippedName)
return match?.id ?? ''
}, [importedTag.name, prefixMappings, tagsByCategory])
const [selectedTagId, setSelectedTagId] = useState('')
const [saving, setSaving] = useState(false)
const [error, setError] = useState<string | null>(null)
@@ -343,6 +356,11 @@ function ImportedTagRow({
const [newTagCategoryId, setNewTagCategoryId] = useState('')
const [creatingTag, setCreatingTag] = useState(false)
// Apply auto-match when it changes (e.g. prefix mappings updated)
useEffect(() => {
if (autoMatchedTagId) setSelectedTagId(autoMatchedTagId)
}, [autoMatchedTagId])
const startCreating = () => {
// Apply prefix mapping defaults if the imported tag has a colon prefix
const colonIdx = importedTag.name.indexOf(': ')