From d584ee2c03c638a52a03e95aae2a5f4b3b423ca6 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Fri, 27 Dec 2024 18:08:09 -0800 Subject: [PATCH] web: submit page navigates to newly created submission --- web/src/app/submit/page.tsx | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/web/src/app/submit/page.tsx b/web/src/app/submit/page.tsx index e098741..9125add 100644 --- a/web/src/app/submit/page.tsx +++ b/web/src/app/submit/page.tsx @@ -17,6 +17,9 @@ interface SubmissionPayload { AssetVersion: number; SubmissionType: number; } +interface IdResponse { + ID: number; +} export default function SubmissionInfoPage() { const [game, setGame] = useState(1); @@ -24,10 +27,10 @@ export default function SubmissionInfoPage() { const handleSubmit = async (event: React.FormEvent) => { event.preventDefault(); - + const form = event.currentTarget; const formData = new FormData(form); - + const payload: SubmissionPayload = { DisplayName: (formData.get("display-name") as string) ?? "unknown", // TEMPORARY! TODO: Change Creator: (formData.get("creator") as string) ?? "unknown", // TEMPORARY! TODO: Change @@ -39,7 +42,7 @@ export default function SubmissionInfoPage() { console.log(payload) console.log(JSON.stringify(payload)) - + try { // Send the POST request const response = await fetch("/api/submissions", { @@ -47,16 +50,18 @@ export default function SubmissionInfoPage() { headers: { "Content-Type": "application/json" }, body: JSON.stringify(payload), }); - + // Allow any HTTP status - const responseText = await response.text(); - - console.log("Response Text:", responseText); + const id_response:IdResponse = await response.json(); + + // navigate to newly created submission + window.location.assign(`/submissions/${id_response.ID}`) + } catch (error) { console.error("Error submitting data:", error); } }; - + return (
@@ -90,4 +95,4 @@ export default function SubmissionInfoPage() {
) -} \ No newline at end of file +}