From c1f07cc31eb769c8e6dd5ade31f92fe16a3b641b Mon Sep 17 00:00:00 2001 From: CPTProgrammer <46586216+CPTProgrammer@users.noreply.github.com> Date: Wed, 15 Jul 2026 12:38:50 +0800 Subject: [PATCH] Add dynamic field validation for Modrinth and CurseForge lists --- src/components/ConfigModal.tsx | 36 ++++- src/hooks/useFieldValidations.tsx | 235 ++++++++++++++++++++---------- src/services/project.ts | 4 +- src/types/curseforge/mod.ts | 1 + 4 files changed, 197 insertions(+), 79 deletions(-) diff --git a/src/components/ConfigModal.tsx b/src/components/ConfigModal.tsx index 8b58587..a3be5a0 100644 --- a/src/components/ConfigModal.tsx +++ b/src/components/ConfigModal.tsx @@ -30,6 +30,7 @@ import { import { useFieldValidations, ValidatedFormItem, + ValidationSlot, type FormNamePath, type StaticOnly, type StaticValidationDef, @@ -166,7 +167,38 @@ const STATIC_DEFS: StaticValidationDef[] = [ }, ]; -const LIST_DEFS: ListValidationDef[] = []; +const LIST_DEFS: ListValidationDef[] = [ + // Modrinth 依赖 — 查询依赖项目名称 + { + list: ["modrinth", "dependencies"], + target: "project_id", + deps: ["project_id"], + async validate(getVal, row) { + const id = getVal("project_id") as string | undefined; + if (!id) return null; + const r = await lookupModrinthProject(id); + return r.ok + ? { status: "success", help: `项目:${r.name}` } + : { status: "error", help: r.error }; + }, + }, + // CurseForge 关联项目 — 查询关联项目名称并自动填充 slug + { + list: ["curseforge", "relations", "projects"], + target: "projectID", + deps: ["projectID"], + async validate(getVal, row, setVal) { + const id = getVal("projectID") as string | undefined; + if (!id) return null; + const r = await lookupCurseforgeProject(Number(id)); + if (r.ok) { + setVal("slug", r.slug); + return { status: "success", help: `项目:${r.name}` }; + } + return { status: "error", help: r.error }; + }, + }, +]; // --------------------------------------------------------------------------- // Data-fetching hooks — each Select loads independently, no blocking @@ -613,6 +645,7 @@ function ConfigModalForm({ /> remove(name)} /> + ))}