feat(steamdb): integrate version auto-fetch into submit wizard UI
This commit is contained in:
@@ -129,6 +129,13 @@ export function GameEntryWizard({ gameId, gameVersions, defaultVersionId, editEn
|
|||||||
// Step 4: Notes
|
// Step 4: Notes
|
||||||
const [userNotes, setUserNotes] = useState(editEntry?.userNotes ?? "")
|
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
|
// Fetch hardware name when slug changes
|
||||||
const handleHardwareChange = useCallback(async (slug: string) => {
|
const handleHardwareChange = useCallback(async (slug: string) => {
|
||||||
setHardwareSlug(slug)
|
setHardwareSlug(slug)
|
||||||
@@ -183,10 +190,39 @@ export function GameEntryWizard({ gameId, gameVersions, defaultVersionId, editEn
|
|||||||
if (selectedVersionId === "__new__") {
|
if (selectedVersionId === "__new__") {
|
||||||
return newVersionString || "New version"
|
return newVersionString || "New version"
|
||||||
}
|
}
|
||||||
|
if (selectedVersionId === "__steamdb__") {
|
||||||
|
return steamdbVersion
|
||||||
|
? steamdbVersion.versionString || `Build ${steamdbVersion.buildId}`
|
||||||
|
: "SteamDB version"
|
||||||
|
}
|
||||||
const v = gameVersions.find((v) => v.id === selectedVersionId)
|
const v = gameVersions.find((v) => v.id === selectedVersionId)
|
||||||
if (!v) return "Unknown"
|
if (!v) return "Unknown"
|
||||||
return v.versionString || (v.buildId ? `Build ${v.buildId}` : "Unknown version")
|
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 = () => {
|
const canProceed = () => {
|
||||||
switch (currentStep) {
|
switch (currentStep) {
|
||||||
@@ -194,6 +230,8 @@ export function GameEntryWizard({ gameId, gameVersions, defaultVersionId, editEn
|
|||||||
if (hardwareSlug === "") return false
|
if (hardwareSlug === "") return false
|
||||||
// If new version selected, require version string
|
// If new version selected, require version string
|
||||||
if (selectedVersionId === "__new__" && !newVersionString.trim()) return false
|
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
|
return true
|
||||||
case 1: // Performance
|
case 1: // Performance
|
||||||
return performance.fpsAvg !== undefined && performance.fpsAvg > 0
|
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
|
// Resolve the final version ID — create a new version if needed
|
||||||
const resolveVersionId = async (): Promise<string> => {
|
const resolveVersionId = async (): Promise<string> => {
|
||||||
if (selectedVersionId !== "__new__") {
|
if (selectedVersionId !== "__new__" && selectedVersionId !== "__steamdb__") {
|
||||||
return selectedVersionId
|
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
|
// Create a new version via API
|
||||||
setIsCreatingVersion(true)
|
setIsCreatingVersion(true)
|
||||||
try {
|
try {
|
||||||
@@ -375,6 +432,9 @@ export function GameEntryWizard({ gameId, gameVersions, defaultVersionId, editEn
|
|||||||
antiCheat={antiCheat}
|
antiCheat={antiCheat}
|
||||||
onAntiCheatChange={setAntiCheat}
|
onAntiCheatChange={setAntiCheat}
|
||||||
platformSupport={platformSupport}
|
platformSupport={platformSupport}
|
||||||
|
steamdbVersion={steamdbVersion}
|
||||||
|
steamdbLoading={steamdbLoading}
|
||||||
|
onRefreshSteamDB={fetchSteamDBVersion}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{currentStep === 1 && (
|
{currentStep === 1 && (
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import { GitBranch } from "lucide-react"
|
import { GitBranch, DatabaseIcon, RefreshCwIcon } from "lucide-react"
|
||||||
import { HardwareStep } from "./hardware-step"
|
import { HardwareStep } from "./hardware-step"
|
||||||
import { AntiCheatStep, type AntiCheatData } from "./anti-cheat-step"
|
import { AntiCheatStep, type AntiCheatData } from "./anti-cheat-step"
|
||||||
|
|
||||||
@@ -11,6 +11,11 @@ export interface GameVersionInfo {
|
|||||||
isLatest: boolean
|
isLatest: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface SteamDBVersion {
|
||||||
|
versionString: string | null
|
||||||
|
buildId: string | null
|
||||||
|
}
|
||||||
|
|
||||||
interface SetupStepProps {
|
interface SetupStepProps {
|
||||||
gameId: string
|
gameId: string
|
||||||
gameVersions: GameVersionInfo[]
|
gameVersions: GameVersionInfo[]
|
||||||
@@ -30,6 +35,9 @@ interface SetupStepProps {
|
|||||||
antiCheatName: string | null
|
antiCheatName: string | null
|
||||||
antiCheatStatus: "none" | "supported" | "unsupported" | "unknown"
|
antiCheatStatus: "none" | "supported" | "unsupported" | "unknown"
|
||||||
}[]
|
}[]
|
||||||
|
steamdbVersion: SteamDBVersion | null
|
||||||
|
steamdbLoading: boolean
|
||||||
|
onRefreshSteamDB: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export function SetupStep({
|
export function SetupStep({
|
||||||
@@ -48,8 +56,12 @@ export function SetupStep({
|
|||||||
antiCheat,
|
antiCheat,
|
||||||
onAntiCheatChange,
|
onAntiCheatChange,
|
||||||
platformSupport,
|
platformSupport,
|
||||||
|
steamdbVersion,
|
||||||
|
steamdbLoading,
|
||||||
|
onRefreshSteamDB,
|
||||||
}: SetupStepProps) {
|
}: SetupStepProps) {
|
||||||
const isNewVersion = selectedVersionId === "__new__"
|
const isNewVersion = selectedVersionId === "__new__"
|
||||||
|
const isSteamDBVersion = selectedVersionId === "__steamdb__"
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-8">
|
<div className="space-y-8">
|
||||||
@@ -80,6 +92,20 @@ export function SetupStep({
|
|||||||
onChange={(e) => onVersionChange(e.target.value)}
|
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"
|
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) => (
|
{gameVersions.map((v) => (
|
||||||
<option key={v.id} value={v.id}>
|
<option key={v.id} value={v.id}>
|
||||||
{v.versionString
|
{v.versionString
|
||||||
@@ -94,6 +120,17 @@ export function SetupStep({
|
|||||||
+ New version...
|
+ New version...
|
||||||
</option>
|
</option>
|
||||||
</select>
|
</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>
|
</div>
|
||||||
|
|
||||||
{isNewVersion && (
|
{isNewVersion && (
|
||||||
@@ -114,6 +151,28 @@ export function SetupStep({
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</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>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user