feat(steamdb): integrate version auto-fetch into submit wizard UI

This commit is contained in:
2026-05-15 01:02:13 +08:00
parent 1ba6335ea1
commit dbb0caa7e7
2 changed files with 122 additions and 3 deletions
+62 -2
View File
@@ -129,6 +129,13 @@ export function GameEntryWizard({ gameId, gameVersions, defaultVersionId, editEn
// Step 4: Notes
const [userNotes, setUserNotes] = useState(editEntry?.userNotes ?? "")
// SteamDB version suggestion
const [steamdbVersion, setSteamdbVersion] = useState<{
versionString: string | null
buildId: string | null
} | null>(null)
const [steamdbLoading, setSteamdbLoading] = useState(false)
// Fetch hardware name when slug changes
const handleHardwareChange = useCallback(async (slug: string) => {
setHardwareSlug(slug)
@@ -183,10 +190,39 @@ export function GameEntryWizard({ gameId, gameVersions, defaultVersionId, editEn
if (selectedVersionId === "__new__") {
return newVersionString || "New version"
}
if (selectedVersionId === "__steamdb__") {
return steamdbVersion
? steamdbVersion.versionString || `Build ${steamdbVersion.buildId}`
: "SteamDB version"
}
const v = gameVersions.find((v) => v.id === selectedVersionId)
if (!v) return "Unknown"
return v.versionString || (v.buildId ? `Build ${v.buildId}` : "Unknown version")
}, [selectedVersionId, newVersionString, gameVersions])
}, [selectedVersionId, newVersionString, gameVersions, steamdbVersion])
const fetchSteamDBVersion = useCallback(async () => {
setSteamdbLoading(true)
try {
const res = await fetch(`/api/games/${gameId}/steamdb-version`)
if (!res.ok) return
const data = await res.json()
if (data.versionString || data.buildId) {
setSteamdbVersion({
versionString: data.versionString,
buildId: data.buildId,
})
}
} catch {
// Silently fail — SteamDB is best-effort
} finally {
setSteamdbLoading(false)
}
}, [gameId])
// Fetch SteamDB version on mount
useEffect(() => {
fetchSteamDBVersion()
}, [fetchSteamDBVersion])
const canProceed = () => {
switch (currentStep) {
@@ -194,6 +230,8 @@ export function GameEntryWizard({ gameId, gameVersions, defaultVersionId, editEn
if (hardwareSlug === "") return false
// If new version selected, require version string
if (selectedVersionId === "__new__" && !newVersionString.trim()) return false
// SteamDB option is always valid (data comes from external source)
if (selectedVersionId === "__steamdb__" && !steamdbVersion) return false
return true
case 1: // Performance
return performance.fpsAvg !== undefined && performance.fpsAvg > 0
@@ -228,10 +266,29 @@ export function GameEntryWizard({ gameId, gameVersions, defaultVersionId, editEn
// Resolve the final version ID — create a new version if needed
const resolveVersionId = async (): Promise<string> => {
if (selectedVersionId !== "__new__") {
if (selectedVersionId !== "__new__" && selectedVersionId !== "__steamdb__") {
return selectedVersionId
}
if (selectedVersionId === "__steamdb__" && steamdbVersion) {
// Create version from SteamDB data
const res = await fetch(`/api/games/${gameId}/versions`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
versionString: steamdbVersion.versionString,
buildId: steamdbVersion.buildId,
isLatest: true,
}),
})
if (!res.ok) {
const data = await res.json()
throw new Error(data.error || "Failed to create version from SteamDB")
}
const data = await res.json() as { id: string }
return data.id
}
// Create a new version via API
setIsCreatingVersion(true)
try {
@@ -375,6 +432,9 @@ export function GameEntryWizard({ gameId, gameVersions, defaultVersionId, editEn
antiCheat={antiCheat}
onAntiCheatChange={setAntiCheat}
platformSupport={platformSupport}
steamdbVersion={steamdbVersion}
steamdbLoading={steamdbLoading}
onRefreshSteamDB={fetchSteamDBVersion}
/>
)}
{currentStep === 1 && (
+60 -1
View File
@@ -1,6 +1,6 @@
"use client"
import { GitBranch } from "lucide-react"
import { GitBranch, DatabaseIcon, RefreshCwIcon } from "lucide-react"
import { HardwareStep } from "./hardware-step"
import { AntiCheatStep, type AntiCheatData } from "./anti-cheat-step"
@@ -11,6 +11,11 @@ export interface GameVersionInfo {
isLatest: boolean
}
export interface SteamDBVersion {
versionString: string | null
buildId: string | null
}
interface SetupStepProps {
gameId: string
gameVersions: GameVersionInfo[]
@@ -30,6 +35,9 @@ interface SetupStepProps {
antiCheatName: string | null
antiCheatStatus: "none" | "supported" | "unsupported" | "unknown"
}[]
steamdbVersion: SteamDBVersion | null
steamdbLoading: boolean
onRefreshSteamDB: () => void
}
export function SetupStep({
@@ -48,8 +56,12 @@ export function SetupStep({
antiCheat,
onAntiCheatChange,
platformSupport,
steamdbVersion,
steamdbLoading,
onRefreshSteamDB,
}: SetupStepProps) {
const isNewVersion = selectedVersionId === "__new__"
const isSteamDBVersion = selectedVersionId === "__steamdb__"
return (
<div className="space-y-8">
@@ -80,6 +92,20 @@ export function SetupStep({
onChange={(e) => onVersionChange(e.target.value)}
className="w-full appearance-none px-4 py-3 rounded-lg border border-border bg-text/5 text-text text-sm outline-none focus:border-primary focus:ring-2 focus:ring-primary/50 transition-colors cursor-pointer"
>
{/* SteamDB suggestion — appears at top when available */}
{steamdbVersion && (steamdbVersion.versionString || steamdbVersion.buildId) && (
<option value="__steamdb__" className="bg-primary/10 text-primary">
Latest from SteamDB: {steamdbVersion.versionString || `Build ${steamdbVersion.buildId}`} recommended
</option>
)}
{steamdbLoading && (
<option disabled className="text-text/40">
Fetching latest version from SteamDB...
</option>
)}
<option disabled className="text-text/30 text-xs">
Existing versions
</option>
{gameVersions.map((v) => (
<option key={v.id} value={v.id}>
{v.versionString
@@ -94,6 +120,17 @@ export function SetupStep({
New version...
</option>
</select>
{/* Refresh button for SteamDB */}
<button
type="button"
onClick={onRefreshSteamDB}
disabled={steamdbLoading}
className="flex items-center gap-1 text-xs text-text/40 hover:text-primary transition-colors cursor-pointer mt-1 disabled:opacity-30"
>
<RefreshCwIcon className={`h-3 w-3 ${steamdbLoading ? "animate-spin" : ""}`} />
Refresh from SteamDB
</button>
</div>
{isNewVersion && (
@@ -114,6 +151,28 @@ export function SetupStep({
</p>
</div>
)}
{isSteamDBVersion && steamdbVersion && (
<div className="space-y-3 p-3 rounded-lg border border-primary/30 bg-primary/5">
<div className="flex items-center gap-2">
<DatabaseIcon className="h-4 w-4 text-primary" />
<p className="text-xs font-medium text-primary">SteamDB Suggestion</p>
</div>
<div className="grid grid-cols-2 gap-3">
<div>
<p className="text-xs text-text/40">Version</p>
<p className="text-sm text-text">{steamdbVersion.versionString || "—"}</p>
</div>
<div>
<p className="text-xs text-text/40">Build ID</p>
<p className="text-sm text-text font-mono">{steamdbVersion.buildId || "—"}</p>
</div>
</div>
<p className="text-xs text-text/40">
This version will be created when you submit your benchmark.
</p>
</div>
)}
</div>
</section>