diff --git a/web/src/app/submit/_submit.tsx b/web/src/app/submit/_submit.tsx new file mode 100644 index 0000000..f3a0db6 --- /dev/null +++ b/web/src/app/submit/_submit.tsx @@ -0,0 +1,67 @@ +interface FormNumbers { + readonly GameID: number, + readonly AssetID: number, + readonly AssetVersion: number +} + +interface FormStrings { + readonly DisplayName: string, + readonly Creator: string, +} + +function SubmitAPI(json: string) { + console.log(json) +} + +function SafeNumbers(form: FormNumbers): Promise { + const form_number_values = [form.GameID, form.AssetID, form.AssetVersion] + + return new Promise((resolve, reject) => { + form_number_values.forEach(v => { + if (!Number.isSafeInteger(v)) { + reject(`Form Value: ${v} was not a valid number`) + } + }) + resolve(form) + }) +} + +function SafeStrings(form: FormStrings): Promise { + const form_string_values = [form.DisplayName, form.Creator] + + return new Promise((resolve, reject) => { + form_string_values.forEach(v => { + if (v.length>=128) { + reject(`Form value: ${v} is beyond the max 128 string limit`) + } + }) + resolve(form) + }) +} + +export default function Submit() { + const form_numbers: FormNumbers = { + GameID: Number((document.getElementById("game-id") as HTMLInputElement).value), + AssetID: Number((document.getElementById("asset-id") as HTMLInputElement).value), + AssetVersion: Number((document.getElementById("asset-version") as HTMLInputElement).value), + } + const form_strings: FormStrings = { + DisplayName: (document.getElementById("display-name") as HTMLInputElement).value, + Creator: (document.getElementById("creator") as HTMLInputElement).value + } + + const valid_numbers = SafeNumbers(form_numbers) + const valid_strings = SafeStrings(form_strings) + + valid_strings.then(form_strings => { + valid_numbers.then(form_numbers => { + SubmitAPI(JSON.stringify({ + DisplayName: form_strings.DisplayName, + Creator: form_strings.Creator, + GameID: form_numbers.GameID, + AssetID: form_numbers.AssetID, + AssetVersion: form_numbers.AssetVersion + })) + }).catch(e => console.log(e)) + }).catch(e => console.log(e)) +} \ No newline at end of file diff --git a/web/src/app/submit/page.tsx b/web/src/app/submit/page.tsx index f8c6154..15a7e5a 100644 --- a/web/src/app/submit/page.tsx +++ b/web/src/app/submit/page.tsx @@ -3,23 +3,19 @@ import { FormControl, FormLabel, RadioGroup, FormControlLabel, Button, TextField } from "@mui/material" import SendIcon from '@mui/icons-material/Send'; import Webpage from "@/app/_components/webpage" +import Submit from "./_submit"; import Radio from '@mui/material/Radio'; import "./(styles)/page.scss" -const enum Map { - New, - Fix, -} - function TargetAsset() { - return ( + return Target: - } label="New"/> - } label="Fix"/> + } label="New" id="asset-new"/> + } label="Fix" id="asset-Fix"/> - ) + } export default function SubmissionInfoPage() { @@ -32,14 +28,14 @@ export default function SubmissionInfoPage() {
- - - - + + + + -