From 3ac68b8b59f150e08731a62026ce3ac825655614 Mon Sep 17 00:00:00 2001 From: Daniel Hader Date: Thu, 4 Jun 2026 18:29:34 -0500 Subject: viewing submissions logic --- static/submission.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 static/submission.js (limited to 'static/submission.js') diff --git a/static/submission.js b/static/submission.js new file mode 100644 index 0000000..bbe4075 --- /dev/null +++ b/static/submission.js @@ -0,0 +1,35 @@ +async function get_problem() { + const url_params = new URLSearchParams(window.location.search); + const problem_id = parseInt(url_params.get("problem_id")); + const response = await fetch(`/problem/${problem_id}`) + return await response.json(); +} + +async function get_submission() { + const url_params = new URLSearchParams(window.location.search); + const submission_id = parseInt(url_params.get("submission_id")); + const response = await fetch(`/submission/${submission_id}`) + return await response.json(); +} + +async function init() { + const problem = await get_problem(); + const submission = await get_submission(); + + const problem_div = document.getElementById("submission-problem"); + + const title = document.createElement("h2"); + title.innerHTML = `Problem: ${problem.title}`; + problem_div.appendChild(title); + + const description = document.createElement("p"); + description.innerHTML = problem.description; + problem_div.appendChild(description); + + document.getElementById("submission-author").innerHTML = `by ${submission.username}`; + document.getElementById("submission-size").innerHTML = `${new Blob([submission.code]).size} bytes`; + document.getElementById("submission-details").innerHTML = submission.details; + document.getElementById("submission-code").innerHTML = submission.code; + + hljs.highlightAll(); +} -- cgit v1.2.3