From d597d62c1c6ed2a0858dbb608f5c59f59b3cc266 Mon Sep 17 00:00:00 2001 From: nyne Date: Sat, 31 May 2025 12:43:08 +0800 Subject: [PATCH] Add Quick Add Tag functionality and improve tag management in Edit and Publish pages --- frontend/src/components/tag_input.tsx | 60 +++++++++++++++++++++++ frontend/src/i18n.ts | 15 ++++++ frontend/src/network/network.ts | 16 ++++++ frontend/src/pages/edit_resource_page.tsx | 29 +++++++++-- frontend/src/pages/publish_page.tsx | 29 +++++++++-- server/api/tag.go | 44 +++++++++++++++++ server/dao/tag.go | 9 ++++ server/service/tag.go | 27 ++++++++++ 8 files changed, 221 insertions(+), 8 deletions(-) diff --git a/frontend/src/components/tag_input.tsx b/frontend/src/components/tag_input.tsx index babd78b..3ffc953 100644 --- a/frontend/src/components/tag_input.tsx +++ b/frontend/src/components/tag_input.tsx @@ -4,6 +4,9 @@ import {useTranslation} from "react-i18next"; import {network} from "../network/network.ts"; import {LuInfo} from "react-icons/lu"; import {MdSearch} from "react-icons/md"; +import Button from "./button.tsx"; +import Input, {TextArea} from "./input.tsx"; +import {ErrorAlert} from "./alert.tsx"; export default function TagInput({ onAdd, mainTag }: { onAdd: (tag: Tag) => void, mainTag?: boolean }) { const [keyword, setKeyword] = useState("") @@ -142,4 +145,61 @@ class Debounce { this.timer = null } } +} + +export function QuickAddTagDialog({ onAdded }: { onAdded: (tags: Tag[]) => void }) { + const {t} = useTranslation(); + + const [text, setText] = useState("") + + const [type, setType] = useState("") + + const [error, setError] = useState(null) + + const handleSubmit = async () => { + if (text.trim().length === 0) { + return + } + setError(null) + const names = text.split(",").filter((n) => n.length > 0) + const res = await network.getOrCreateTags(names, type) + if (!res.success) { + setError(res.message) + return + } + const tags = res.data! + onAdded(tags) + setText("") + setType("") + const dialog = document.getElementById("quick_add_tag_dialog") as HTMLDialogElement + dialog.close() + } + + return <> + + +
+

{t('Add Tags')}

+

+ {t("Input tags separated by commas.")} +
+ {t("If the tag does not exist, it will be created automatically.")} +
+ {t("Optionally, you can specify a type for the new tags.")} +

+