Propagate MC version ranges from VersionTable to PublishModal

This commit is contained in:
CPTProgrammer 2026-07-16 16:05:13 +08:00
parent 9a2305d5e0
commit 54d6a7659a
No known key found for this signature in database
3 changed files with 59 additions and 22 deletions

View File

@ -8,6 +8,7 @@ import { VersionTable } from "./VersionTable";
import { PublishModal } from "./PublishModal";
import type { Config } from "@/types";
import type { ParsedProject } from "@/services/project";
import type { McVersionEntry } from "@/lib/utils/mcVersion";
const { Title } = Typography;
@ -27,6 +28,7 @@ export function MainPage({ initialConfigs }: MainPageProps) {
null,
);
const [projectLoading, setProjectLoading] = useState(false);
const [versionRanges, setVersionRanges] = useState<McVersionEntry[] | null>(null);
// ------- ConfigSelector callbacks -------
@ -92,6 +94,7 @@ export function MainPage({ initialConfigs }: MainPageProps) {
project={parsedProject}
loading={projectLoading}
onLoadingChange={setProjectLoading}
onRangesChange={setVersionRanges}
/>
{/* Publish button */}
@ -122,6 +125,7 @@ export function MainPage({ initialConfigs }: MainPageProps) {
open={publishOpen}
config={selectedConfig}
project={parsedProject}
versionRanges={versionRanges}
onClose={handlePublishClose}
/>
)}

View File

@ -1,6 +1,6 @@
"use client";
import { useState, useCallback } from "react";
import { useState, useCallback, useMemo } from "react";
import {
Modal,
Steps,
@ -21,6 +21,8 @@ import { ReloadOutlined } from "@ant-design/icons";
import type { BaseVersion, Config, UploadReleaseType } from "@/types";
import type { ParsedProject } from "@/services/project";
import { platforms } from "@/services/publish.schemas";
import { Template } from "@/lib/utils/template";
import type { McVersionEntry } from "@/lib/utils/mcVersion";
const { Text } = Typography;
@ -33,9 +35,8 @@ interface PublishVersion {
mc_version: string;
artifact: string | null;
sources: string | null;
// version label that matches the platform's versioning
label: string;
// already exists on this platform?
modrinthVersion: string;
modrinthVersionName: string;
existsModrinth: boolean;
existsCurseforge: boolean;
}
@ -44,6 +45,7 @@ interface PublishModalProps {
open: boolean;
config: Config;
project: ParsedProject;
versionRanges: McVersionEntry[] | null;
onClose: () => void;
}
@ -68,6 +70,7 @@ export function PublishModal({
open,
config,
project,
versionRanges,
onClose,
}: PublishModalProps) {
const { token } = theme.useToken();
@ -117,16 +120,41 @@ export function PublishModal({
}
}, []);
// Pre-compute version display values
const versionTmpl = useMemo(() => new Template(config.modrinth.version), [config.modrinth.version]);
const versionNameTmpl = useMemo(() => new Template(config.modrinth.version_name), [config.modrinth.version_name]);
const rangeMap = useMemo(() => {
const map = new Map<string, string>();
if (versionRanges) {
for (const entry of versionRanges) {
map.set(entry.version, entry.wildcard);
}
}
return map;
}, [versionRanges]);
// Build publish version rows from project artifacts
const publishVersions: PublishVersion[] = project.artifacts.map((a) => ({
key: a.mc_version,
mc_version: a.mc_version,
artifact: a.artifact,
sources: a.sources,
label: "", // TODO: compute from version template
existsModrinth: existingModrinth.includes(a.mc_version),
existsCurseforge: existingCurseforge.includes(a.mc_version),
}));
const publishVersions: PublishVersion[] = useMemo(() =>
project.artifacts.map((a) => {
const tmplValues = {
version: project.version,
mc_version: a.mc_version,
mc_version_range: rangeMap.get(a.mc_version) ?? a.mc_version,
};
return {
key: a.mc_version,
mc_version: a.mc_version,
artifact: a.artifact,
sources: a.sources,
modrinthVersion: versionTmpl.format(tmplValues),
modrinthVersionName: versionNameTmpl.format(tmplValues),
existsModrinth: existingModrinth.includes(a.mc_version),
existsCurseforge: existingCurseforge.includes(a.mc_version),
};
}),
[project, versionTmpl, versionNameTmpl, rangeMap, existingModrinth, existingCurseforge],
);
// --------------- Steps handling ---------------
@ -175,16 +203,14 @@ export function PublishModal({
const renderStep1 = () => {
const modrinthColumns = [
{
title: "MC 版本",
dataIndex: "mc_version",
key: "mc_version",
width: 100,
title: "版本号",
dataIndex: "modrinthVersion",
key: "modrinthVersion",
},
{
title: "构建产物",
dataIndex: "artifact",
key: "artifact",
ellipsis: true,
title: "版本名称",
dataIndex: "modrinthVersionName",
key: "modrinthVersionName",
},
{
title: "",
@ -215,7 +241,7 @@ export function PublishModal({
width: 100,
},
{
title: "构建产物",
title: "显示名称",
dataIndex: "artifact",
key: "artifact",
ellipsis: true,

View File

@ -17,12 +17,14 @@ interface VersionTableProps {
project: ParsedProject | null;
loading: boolean;
onLoadingChange: (loading: boolean) => void;
onRangesChange?: (ranges: McVersionEntry[] | null) => void;
}
export function VersionTable({
project,
loading,
onLoadingChange,
onRangesChange,
}: VersionTableProps) {
const { token } = theme.useToken();
// ── MC version union from both platforms ──
@ -95,6 +97,11 @@ export function VersionTable({
.map((v) => ({ value: v, label: v }));
}, [project, allMcVersions]);
// Report ranges to parent when they change
useEffect(() => {
onRangesChange?.(versionRanges);
}, [versionRanges, onRangesChange]);
// Reset lastVersionEnd to latest in the same series
useEffect(() => {
if (allMcVersions.length === 0 || !project) return;