summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--static/main.js2
-rw-r--r--static/submit.html2
-rw-r--r--static/submit.js28
3 files changed, 24 insertions, 8 deletions
diff --git a/static/main.js b/static/main.js
index ae997f3..73a4c60 100644
--- a/static/main.js
+++ b/static/main.js
@@ -37,7 +37,7 @@ function create_problem_element(problem, submissions) {
problem_div.appendChild(sub_title);
const submission_link = document.createElement("a");
- submission_link.href = "submit.html?problem=10";
+ submission_link.href = `submit.html?problem_id=${problem.id}`;
submission_link.innerHTML = "submit solution"
problem_div.appendChild(submission_link);
diff --git a/static/submit.html b/static/submit.html
index 79c4f82..393b2e2 100644
--- a/static/submit.html
+++ b/static/submit.html
@@ -43,7 +43,7 @@
<label for="submission-code">Code</label><br>
<textarea id="submission-code" rows="16" cols="87"></textarea>
<br><br>
- <button id="submission-button">Submit</button>
+ <button id="submission-button" onclick="submit()">Submit</button>
<br><br>
</div>
diff --git a/static/submit.js b/static/submit.js
index 81e3aa6..03dfd69 100644
--- a/static/submit.js
+++ b/static/submit.js
@@ -1,12 +1,28 @@
-function submit() {
+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 = {
- user_id: 1,
- problem_id: 2,
- language: "c++",
- details: "blah blah",
- code: "blah blah",
+ problem_id: 2, // TODO validate language and problem id in server
+ language: language,
+ details: details,
+ code: code,
};
+
+ const response = await fetch("/submission", {
+ method: "post",
+ headers: { "Content-Type": "application/json" },
+ credentials: "include",
+ body: JSON.stringify(submission)
+ });
+
+ console.log(response);
+
+ const result = await response.json();
+
+ console.log(result);
}
function init() {