Fix wrong selection in PublishModal

This commit is contained in:
CPTProgrammer 2026-07-18 22:50:10 +08:00
parent bf716627a1
commit 6b32cafeeb
No known key found for this signature in database
2 changed files with 12 additions and 4 deletions

View File

@ -170,6 +170,8 @@ export function PublishModal({
CurseForgeFile[] CurseForgeFile[]
>([]); >([]);
const [canSelect, setCanSelect] = useState(false);
const loadExisting = useCallback(async () => { const loadExisting = useCallback(async () => {
setLoadingExisting(true); setLoadingExisting(true);
try { try {
@ -305,6 +307,8 @@ export function PublishModal({
.sort((a, b) => compareParsed(a.parsed, b.parsed)) .sort((a, b) => compareParsed(a.parsed, b.parsed))
.map((e) => e.row); .map((e) => e.row);
if (!loadingExisting) setCanSelect(true);
return [...pending, ...existing]; return [...pending, ...existing];
}, [publishVersions, modrinthExistingVersions, matchedMrNames, config.modrinth.version]); }, [publishVersions, modrinthExistingVersions, matchedMrNames, config.modrinth.version]);
@ -381,7 +385,7 @@ export function PublishModal({
} }
}, [open]); }, [open]);
useEffect(() => { useEffect(() => {
if (!loadingExisting && publishVersions.length > 0 && !initRef.current) { if (canSelect && publishVersions.length > 0 && !initRef.current) {
initRef.current = true; initRef.current = true;
setSelectedModrinth( setSelectedModrinth(
publishVersions.filter((v) => !v.existsModrinth).map((v) => v.key), publishVersions.filter((v) => !v.existsModrinth).map((v) => v.key),
@ -390,7 +394,7 @@ export function PublishModal({
publishVersions.filter((v) => !v.existsCurseforge).map((v) => v.key), publishVersions.filter((v) => !v.existsCurseforge).map((v) => v.key),
); );
} }
}, [loadingExisting, publishVersions]); }, [canSelect, publishVersions]);
// --------------- Steps handling --------------- // --------------- Steps handling ---------------

View File

@ -87,7 +87,9 @@ export async function compareVersions(
// ── Modrinth按 version 模板生成 version_number 后匹配 ── // ── Modrinth按 version 模板生成 version_number 后匹配 ──
const modrinth: Record<string, VersionMatch> = {}; const modrinth: Record<string, VersionMatch> = {};
const modrinthTmpl = new Template(config.modrinth.version); const modrinthTmpl = new Template(config.modrinth.version, {
filename_format: config.filename_format,
});
for (const mc_version of mc_versions) { for (const mc_version of mc_versions) {
const generatedVersion = modrinthTmpl.format({ version, mc_version }); const generatedVersion = modrinthTmpl.format({ version, mc_version });
@ -101,7 +103,9 @@ export async function compareVersions(
// ── CurseForge按 filename_format 模板生成文件名后匹配 ── // ── CurseForge按 filename_format 模板生成文件名后匹配 ──
const curseforge: Record<string, FileMatch> = {}; const curseforge: Record<string, FileMatch> = {};
const curseforgeTmpl = new Template(config.filename_format); const curseforgeTmpl = new Template(config.curseforge.version_name, {
filename_format: config.filename_format,
});
for (const mc_version of mc_versions) { for (const mc_version of mc_versions) {
const generatedFilename = curseforgeTmpl.format({ version, mc_version }); const generatedFilename = curseforgeTmpl.format({ version, mc_version });