Add customizable tag separator option in tag input

This commit is contained in:
2025-05-31 16:33:30 +08:00
parent 03876d106a
commit f5c14917f9
2 changed files with 22 additions and 5 deletions

View File

@@ -156,12 +156,14 @@ export function QuickAddTagDialog({ onAdded }: { onAdded: (tags: Tag[]) => void
const [error, setError] = useState<string | null>(null) const [error, setError] = useState<string | null>(null)
const [separator, setSeparator] = useState<string>(",")
const handleSubmit = async () => { const handleSubmit = async () => {
if (text.trim().length === 0) { if (text.trim().length === 0) {
return return
} }
setError(null) setError(null)
const names = text.split(",").filter((n) => n.length > 0) const names = text.split(separator).filter((n) => n.length > 0)
const res = await network.getOrCreateTags(names, type) const res = await network.getOrCreateTags(names, type)
if (!res.success) { if (!res.success) {
setError(res.message) setError(res.message)
@@ -184,12 +186,27 @@ export function QuickAddTagDialog({ onAdded }: { onAdded: (tags: Tag[]) => void
<div className="modal-box"> <div className="modal-box">
<h3 className="font-bold text-lg">{t('Add Tags')}</h3> <h3 className="font-bold text-lg">{t('Add Tags')}</h3>
<p className="py-2 text-sm"> <p className="py-2 text-sm">
{t("Input tags separated by commas.")} {t("Input tags separated by separator.")}
<br/> <br/>
{t("If the tag does not exist, it will be created automatically.")} {t("If the tag does not exist, it will be created automatically.")}
<br/> <br/>
{t("Optionally, you can specify a type for the new tags.")} {t("Optionally, you can specify a type for the new tags.")}
</p> </p>
<p className={"flex my-2"}>
<span className={"flex-1"}>{t("Separator")}:</span>
<label className="label text-sm mx-2">
<input type="radio" name="radio-1" className="radio radio-primary" checked={separator == ","} onChange={() => setSeparator(",")}/>
Comma
</label>
<label className="label text-sm mx-2">
<input type="radio" name="radio-2" className="radio radio-primary" checked={separator == ";"} onChange={() => setSeparator(";")}/>
Semicolon
</label>
<label className="label text-sm mx-2">
<input type="radio" name="radio-3" className="radio radio-primary" checked={separator == " "} onChange={() => setSeparator(" ")}/>
Space
</label>
</p>
<TextArea value={text} onChange={(e) => setText(e.target.value)} label={"Tags"}/> <TextArea value={text} onChange={(e) => setText(e.target.value)} label={"Tags"}/>
<Input value={type} onChange={(e) => setType(e.target.value)} label={"Type"}/> <Input value={type} onChange={(e) => setType(e.target.value)} label={"Type"}/>
{error && <ErrorAlert className={"mt-2"} message={error}/>} {error && <ErrorAlert className={"mt-2"} message={error}/>}

View File

@@ -174,7 +174,7 @@ export const i18nData = {
"Other": "Other", "Other": "Other",
"Quick Add": "Quick Add", "Quick Add": "Quick Add",
"Add Tags": "Add Tags", "Add Tags": "Add Tags",
"Input tags separated by commas.": "Input tags separated by commas.", "Input tags separated by separator.": "Input tags separated by separator.",
"If the tag does not exist, it will be created automatically.": "If the tag does not exist, it will be created automatically.", "If the tag does not exist, it will be created automatically.": "If the tag does not exist, it will be created automatically.",
"Optionally, you can specify a type for the new tags.": "Optionally, you can specify a type for the new tags.", "Optionally, you can specify a type for the new tags.": "Optionally, you can specify a type for the new tags.",
} }
@@ -354,7 +354,7 @@ export const i18nData = {
"Other": "其他", "Other": "其他",
"Quick Add": "快速添加", "Quick Add": "快速添加",
"Add Tags": "添加标签", "Add Tags": "添加标签",
"Input tags separated by commas.": "输入标签, 用逗号分隔。", "Input tags separated by separator.": "输入标签, 用分隔符分隔。",
"If the tag does not exist, it will be created automatically.": "如果标签不存在, 将自动创建。", "If the tag does not exist, it will be created automatically.": "如果标签不存在, 将自动创建。",
"Optionally, you can specify a type for the new tags.": "您可以选择为新标签指定一个类型。", "Optionally, you can specify a type for the new tags.": "您可以选择为新标签指定一个类型。",
} }
@@ -534,7 +534,7 @@ export const i18nData = {
"Other": "其他", "Other": "其他",
"Quick Add": "快速添加", "Quick Add": "快速添加",
"Add Tags": "添加標籤", "Add Tags": "添加標籤",
"Input tags separated by commas.": "輸入標籤, 用逗號分隔。", "Input tags separated by separator.": "輸入標籤, 用分隔符分隔。",
"If the tag does not exist, it will be created automatically.": "如果標籤不存在, 將自動創建。", "If the tag does not exist, it will be created automatically.": "如果標籤不存在, 將自動創建。",
"Optionally, you can specify a type for the new tags.": "您可以選擇為新標籤指定一個類型。", "Optionally, you can specify a type for the new tags.": "您可以選擇為新標籤指定一個類型。",
} }