From aa4509ede843999f96e1bbfc725aea8a082242dc Mon Sep 17 00:00:00 2001 From: Adrian Bonpin Date: Sun, 10 May 2026 04:59:48 +0800 Subject: [PATCH] feat: wire screenshot upload into wizard inline submit flow, remove post-submit interstitial (Tasks 2.2-2.4) --- components/wizard/game-entry-wizard.tsx | 115 ++++++------------------ components/wizard/steps/review-step.tsx | 8 +- 2 files changed, 32 insertions(+), 91 deletions(-) diff --git a/components/wizard/game-entry-wizard.tsx b/components/wizard/game-entry-wizard.tsx index 8397d75..a0f7063 100644 --- a/components/wizard/game-entry-wizard.tsx +++ b/components/wizard/game-entry-wizard.tsx @@ -45,7 +45,6 @@ export function GameEntryWizard({ gameId, gameVersions, defaultVersionId, editEn const [isSubmitting, setIsSubmitting] = useState(false) const [error, setError] = useState(null) const [success, setSuccess] = useState(false) - const [createdEntryId, setCreatedEntryId] = useState(null) const [screenshotFiles, setScreenshotFiles] = useState([]) const [screenshotUploading, setScreenshotUploading] = useState(false) const [screenshotError, setScreenshotError] = useState(null) @@ -299,14 +298,31 @@ export function GameEntryWizard({ gameId, gameVersions, defaultVersionId, editEn } const data = await res.json() - if (!editEntry && data.id) { - setCreatedEntryId(data.id) - } else { - setSuccess(true) - setTimeout(() => { - router.push(`/game/${gameId}`) - }, 2000) + + // Inline screenshot upload for new entries + if (!editEntry && data.id && screenshotFiles.length > 0) { + setScreenshotUploading(true) + try { + const formData = new FormData() + screenshotFiles.forEach((file) => formData.append("screenshots", file)) + const uploadRes = await fetch(`/api/performance/${data.id}/screenshots`, { + method: "POST", + body: formData, + }) + if (!uploadRes.ok) { + console.warn("Screenshot upload failed:", await uploadRes.text()) + } + } catch (err) { + console.warn("Screenshot upload error:", err) + } finally { + setScreenshotUploading(false) + } } + + setSuccess(true) + setTimeout(() => { + router.push(`/game/${gameId}`) + }, 2000) } catch (err) { setError(err instanceof Error ? err.message : "An error occurred") } finally { @@ -332,86 +348,7 @@ export function GameEntryWizard({ gameId, gameVersions, defaultVersionId, editEn ) } - if (createdEntryId) { - return ( - -
- - - -
-

Entry Submitted!

-

Your benchmark has been saved.

-
-

Add Screenshots (Optional)

-

Upload up to 2 screenshots of your in-game settings or FPS overlay.

- { - const files = Array.from(e.target.files || []).slice(0, 2) - setScreenshotFiles(files) - }} - className="block w-full text-sm text-text/70 file:mr-2 file:py-1.5 file:px-3 file:rounded file:border-0 file:text-xs file:font-medium file:bg-primary/10 file:text-primary hover:file:bg-primary/20 cursor-pointer" - /> - {screenshotFiles.length > 0 && ( -
- {screenshotFiles.map((file, i) => ( -
{file.name}
- ))} -
- )} -
- - -
- {screenshotError &&

{screenshotError}

} -
-
- ) - } return (
@@ -478,6 +415,10 @@ export function GameEntryWizard({ gameId, gameVersions, defaultVersionId, editEn onSubmit={handleSubmit} isSubmitting={isSubmitting} error={error} + screenshotFiles={screenshotFiles} + onScreenshotFilesChange={setScreenshotFiles} + screenshotUploading={screenshotUploading} + screenshotError={screenshotError} /> )} diff --git a/components/wizard/steps/review-step.tsx b/components/wizard/steps/review-step.tsx index 2ae03ab..2bce167 100644 --- a/components/wizard/steps/review-step.tsx +++ b/components/wizard/steps/review-step.tsx @@ -30,10 +30,10 @@ interface ReviewStepProps { onSubmit: () => void isSubmitting: boolean error: string | null - screenshotFiles?: File[] - onScreenshotFilesChange?: (files: File[]) => void - screenshotUploading?: boolean - screenshotError?: string | null + screenshotFiles: File[] + onScreenshotFilesChange: (files: File[]) => void + screenshotUploading: boolean + screenshotError: string | null } function SectionHeader({ icon: Icon, label }: { icon: React.ElementType; label: string }) {