summaryrefslogtreecommitdiff
path: root/static/submit.js
diff options
context:
space:
mode:
Diffstat (limited to 'static/submit.js')
-rw-r--r--static/submit.js24
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");