search existing tags for default
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { useEffect, useState, useRef, useCallback } from 'react'
|
import { useEffect, useMemo, useState, useRef, useCallback } from 'react'
|
||||||
import { useParams } from 'next/navigation'
|
import { useParams } from 'next/navigation'
|
||||||
import type { Tag, TagCategory, ImportedTag, TagMapping, Library } from '@/types'
|
import type { Tag, TagCategory, ImportedTag, TagMapping, Library } from '@/types'
|
||||||
|
|
||||||
@@ -335,6 +335,19 @@ function ImportedTagRow({
|
|||||||
onMapped: () => void
|
onMapped: () => void
|
||||||
onIgnore: () => 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 [selectedTagId, setSelectedTagId] = useState('')
|
||||||
const [saving, setSaving] = useState(false)
|
const [saving, setSaving] = useState(false)
|
||||||
const [error, setError] = useState<string | null>(null)
|
const [error, setError] = useState<string | null>(null)
|
||||||
@@ -343,6 +356,11 @@ function ImportedTagRow({
|
|||||||
const [newTagCategoryId, setNewTagCategoryId] = useState('')
|
const [newTagCategoryId, setNewTagCategoryId] = useState('')
|
||||||
const [creatingTag, setCreatingTag] = useState(false)
|
const [creatingTag, setCreatingTag] = useState(false)
|
||||||
|
|
||||||
|
// Apply auto-match when it changes (e.g. prefix mappings updated)
|
||||||
|
useEffect(() => {
|
||||||
|
if (autoMatchedTagId) setSelectedTagId(autoMatchedTagId)
|
||||||
|
}, [autoMatchedTagId])
|
||||||
|
|
||||||
const startCreating = () => {
|
const startCreating = () => {
|
||||||
// Apply prefix mapping defaults if the imported tag has a colon prefix
|
// Apply prefix mapping defaults if the imported tag has a colon prefix
|
||||||
const colonIdx = importedTag.name.indexOf(': ')
|
const colonIdx = importedTag.name.indexOf(': ')
|
||||||
|
|||||||
Reference in New Issue
Block a user