From cff5f10baa3db6d7aad702874ed15f9bfe875cce Mon Sep 17 00:00:00 2001 From: Mohab Yaser Date: Tue, 14 Nov 2023 17:28:04 +0200 Subject: [PATCH] Fixing adding the same handle more than once, the case when there is not enough problems found, and some ui issues --- index.html | 4 +- main.js | 91 +++++++++++++++++++++++++++++++---- main.py | 136 ----------------------------------------------------- style.css | 61 +++++++++++++----------- 4 files changed, 117 insertions(+), 175 deletions(-) delete mode 100644 main.py diff --git a/index.html b/index.html index 9652a09..4983aff 100644 --- a/index.html +++ b/index.html @@ -6,7 +6,9 @@ Codeforces Problem Selector - + + +
diff --git a/main.js b/main.js index 0da3da0..f94441b 100644 --- a/main.js +++ b/main.js @@ -64,6 +64,33 @@ function dummy_data() { btns[21].style.backgroundColor = green; btns[23].style.backgroundColor = green; btns[26].style.backgroundColor = green; + + let problem_container = ` +
+ + + + + Go to problem + +
`; + + document.getElementsByClassName('problems-container')[0].innerHTML += problem_container; + document.getElementsByClassName('problems-container')[0].innerHTML += problem_container; + document.getElementsByClassName('problems-container')[0].innerHTML += problem_container; + document.getElementsByClassName('problems-container')[0].innerHTML += problem_container; + document.getElementsByClassName('problems-container')[0].innerHTML += problem_container; + document.getElementsByClassName('problems-container')[0].innerHTML += problem_container; + document.getElementsByClassName('problems-container')[0].innerHTML += problem_container; + document.getElementsByClassName('problems-container')[0].innerHTML += problem_container; + document.getElementsByClassName('problems-container')[0].innerHTML += problem_container; + document.getElementsByClassName('problems-container')[0].innerHTML += problem_container; } window.addEventListener("load", () => { @@ -128,6 +155,16 @@ function add_handle(handle) { } } +function already_entered(handle) { + let already_entered_handles = document.getElementsByClassName("accepted-handle tooltip"); + for (let i = 0; i < already_entered_handles.length; i++) { + if (already_entered_handles[i].innerText == handle) + return true; + } + + return false; +} + document .getElementsByClassName("add-handle-btn")[0] .addEventListener("click", async() => { @@ -140,13 +177,19 @@ document text: "Please Enter a handle!", }); else { - const handle_state = await (valid_handle(handle)); - if (!handle_state) { + const valid = await (valid_handle(handle)); + if (!valid) { Swal.fire({ icon: "error", title: "Oops...", text: "Please Enter a valid handle!", }); + } else if (already_entered(handle)) { + Swal.fire({ + icon: "error", + title: "Oops...", + text: "You have already entered this handle before", + }); } else add_handle(handle); } @@ -185,6 +228,9 @@ function validate_input() { } function valid_problem(problem, min, max, problems_out_of_scope, chosen_tags) { + if (!problems_out_of_scope.has(problem['name'])) + return false; + problems_out_of_scope.forEach((element) => { if (element === problem['name']) return false; @@ -254,10 +300,11 @@ async function get_problems() { let problemset = await http_request('https://codeforces.com/api/problemset.problems'); let available_problems = []; - let [from, to] = document.getElementsByClassName("another-class"); + let [from, to, problems_cnt] = document.getElementsByClassName("another-class"); from = +from.value; to = +to.value; + problems_cnt = +problems_cnt.value; let min = Math.max(800, from); let max = Math.min(3500, to); @@ -269,7 +316,15 @@ async function get_problems() { available_problems = shuffle(available_problems); - let problems_cnt = +(document.getElementsByClassName("another-class")[2].value); + if (available_problems.length < problems_cnt) { + Swal.fire({ + icon: "error", + title: "Oops...", + text: "There are not sufficient problems on the site with these criteria", + }); + + return false; + } let final_problems = available_problems.slice(0, problems_cnt); @@ -279,14 +334,12 @@ async function get_problems() { function view_problems(problems) { let showed_tags = []; let showed_ratings = []; + let showed_codes = []; for (let i = 0; i < problems.length; i++) { let problem_container = `