summaryrefslogtreecommitdiff
path: root/static
diff options
context:
space:
mode:
Diffstat (limited to 'static')
-rw-r--r--static/login.js2
-rw-r--r--static/main.js91
-rw-r--r--static/submit.html5
-rw-r--r--static/submit.js24
4 files changed, 72 insertions, 50 deletions
diff --git a/static/login.js b/static/login.js
index 42b3242..1dd61b7 100644
--- a/static/login.js
+++ b/static/login.js
@@ -13,8 +13,6 @@ function init() {
new FormData(form).forEach((value, key) => body[key] = value);
try {
- console.log();
-
const res = await fetch("/login", {
method: "POST",
headers: { "Content-Type": "application/json" },
diff --git a/static/main.js b/static/main.js
index 73a4c60..9132829 100644
--- a/static/main.js
+++ b/static/main.js
@@ -44,54 +44,66 @@ function create_problem_element(problem, submissions) {
const sub_div = document.createElement("div");
sub_div.className = "submission-div";
problem_div.appendChild(sub_div);
+
+ if (submissions.length === 0) {
+ const no_sub_message = document.createElement("span");
+ no_sub_message.innerHTML = "no submissions for this problem yet";
+ sub_div.appendChild(no_sub_message);
+ } else {
+ const sub_table = document.createElement("table");
+ sub_table.className = "submission-table";
+ sub_div.appendChild(sub_table);
- const sub_table = document.createElement("table");
- sub_table.className = "submission-table";
- sub_div.appendChild(sub_table);
-
- const header_row = document.createElement("tr");
- sub_table.appendChild(header_row);
-
- const header_user = document.createElement("th");
- header_user.innerHTML = "User";
- header_row.appendChild(header_user);
- const header_lang = document.createElement("th");
- header_lang.innerHTML = "Language";
- header_row.appendChild(header_lang);
- const header_size = document.createElement("th");
- header_size.innerHTML = "Size";
- header_row.appendChild(header_size);
- const header_subm = document.createElement("th");
- header_subm.innerHTML = "Submission";
- header_row.appendChild(header_subm);
+ const header_row = document.createElement("tr");
+ sub_table.appendChild(header_row);
- for (const submission of submissions) {
- const sub_row = document.createElement("tr");
- sub_table.appendChild(sub_row);
+ const header_user = document.createElement("th");
+ header_user.innerHTML = "User";
+ header_row.appendChild(header_user);
+ const header_lang = document.createElement("th");
+ header_lang.innerHTML = "Language";
+ header_row.appendChild(header_lang);
+ const header_size = document.createElement("th");
+ header_size.innerHTML = "Size";
+ header_row.appendChild(header_size);
+ const header_subm = document.createElement("th");
+ header_subm.innerHTML = "Submission";
+ header_row.appendChild(header_subm);
+
+ for (const submission of submissions) {
+ const sub_row = document.createElement("tr");
+ sub_table.appendChild(sub_row);
- const sub_user = document.createElement("td");
- sub_user.innerHTML = "Username";
- sub_row.appendChild(sub_user);
+ const sub_user = document.createElement("td");
+ sub_user.innerHTML = "Username";
+ sub_row.appendChild(sub_user);
- const sub_lang = document.createElement("td");
- sub_lang.innerHTML = "Language";
- sub_row.appendChild(sub_lang);
+ const sub_lang = document.createElement("td");
+ sub_lang.innerHTML = "Language";
+ sub_row.appendChild(sub_lang);
- const sub_size = document.createElement("td");
- sub_size.innerHTML = "Size";
- sub_row.appendChild(sub_size);
+ const sub_size = document.createElement("td");
+ sub_size.innerHTML = "Size";
+ sub_row.appendChild(sub_size);
- const sub_subm = document.createElement("td");
- const sub_anch = document.createElement("a");
- sub_anch.href = "submission.html?id=5";
- sub_anch.innerText = "view submission";
- sub_subm.appendChild(sub_anch);
- sub_row.appendChild(sub_subm);
+ const sub_subm = document.createElement("td");
+ const sub_anch = document.createElement("a");
+ sub_anch.href = "submission.html?id=5";
+ sub_anch.innerText = "view submission";
+ sub_subm.appendChild(sub_anch);
+ sub_row.appendChild(sub_subm);
+ }
}
return problem_div
}
+async function fetch_submissions(problem_id) {
+ const response = await fetch(`/submission/${problem_id}`)
+ const result = await response.json();
+ return result;
+}
+
async function fetch_problems() {
const response = await fetch("/problem");
if (!response.ok) {
@@ -106,7 +118,10 @@ async function fetch_problems() {
}
for (const problem of result) {
- const problem_div = create_problem_element(problem, [1, 2, 3])
+
+ const submissions = await fetch_submissions(problem.id);
+
+ const problem_div = create_problem_element(problem, submissions)
problems_div.appendChild(problem_div);
}
}
diff --git a/static/submit.html b/static/submit.html
index 9cab87b..151fba5 100644
--- a/static/submit.html
+++ b/static/submit.html
@@ -16,6 +16,10 @@
<a href="index.html">Home</a>
<h1>C&amp;! Code Golf Leaderboard</h1>
<div id="submission-problem"></div>
+ <div id="error" hidden>
+ <span id="error-message" style="color: red"></span>
+ <br><br>
+ </div>
<h2>Submit Solution</h2>
<div id="submission-div">
<label for="submission-language">Language</label><br>
@@ -34,6 +38,7 @@
<option value="ruby">Ruby</option>
<option value="rust">Rust</option>
<option value="typescript">TypeScript</option>
+ <option value="zig">Zig</option>
<option value="other">Other (specify below)</option>
</select>
<br><br>
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");