diff options
| author | Daniel Hader <[email protected]> | 2026-06-03 22:32:09 -0500 |
|---|---|---|
| committer | Daniel Hader <[email protected]> | 2026-06-03 22:32:09 -0500 |
| commit | 328d0cd912dfa5dbda53a09ecdfeaeb93504b560 (patch) | |
| tree | 5dbe78ebbe4c9df5b8bbcf4530a7f912dbb1b7a6 /static/submit.js | |
| parent | 51fac3f3b6f73b649ba8109b37d8ff311b905cd4 (diff) | |
submission logic and fetching submissions
Diffstat (limited to 'static/submit.js')
| -rw-r--r-- | static/submit.js | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/static/submit.js b/static/submit.js index 9708e0c..936518b 100644 --- a/static/submit.js +++ b/static/submit.js @@ -1,11 +1,16 @@ +function problem_id() { + const url_params = new URLSearchParams(window.location.search); + return parseInt(url_params.get("problem_id")); +} + async function submit() { const language = document.getElementById("submission-language").value; const details = document.getElementById("submission-details").value; const code = document.getElementById("submission-code").value; const submission = { - problem_id: 2, // TODO validate language and problem id in server + problem_id: problem_id(), // TODO validate language and problem id in server language: language, details: details, code: code, @@ -18,18 +23,17 @@ async function submit() { body: JSON.stringify(submission) }); - console.log(response); - - const result = await response.json(); - - console.log(result); + if (response.ok) { + const result = await response.json(); + window.location.href = "index.html"; + } else { + document.getElementById("error-message").innerHTML = "error submitting solution, try again"; + document.getElementById("error").hidden = false; + } } async function init() { - const url_params = new URLSearchParams(window.location.search); - const problem_id = url_params.get("problem_id"); - - const response = await fetch(`/problem/${problem_id}`); + const response = await fetch(`/problem/${problem_id()}`); const problem = await response.json(); const problem_div = document.getElementById("submission-problem"); |
