Skip to content

Commit

Permalink
make the check submission button functional (arminpatel#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
theoden42 authored Aug 26, 2023
1 parent 84666e1 commit fc298e1
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions src/pages/Contest.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ const Contest = () => {
const durHours = Number(data.duration.slice(0, 2));
const durMins = Number(data.duration.slice(3, 5));
const endtime =
Date.parse(data.start_date_time) + 360000 * durHours + 60000 * durMins;
Date.parse(data.start_date_time) + 3600000 * durHours + 60000 * durMins;
const time = endtime - Date.now();

setDays(Math.floor(time / (1000 * 60 * 60 * 24)));
setHours(Math.floor((time / (1000 * 60 * 60)) % 24));
setMinutes(Math.floor((time / 1000 / 60) % 60));
Expand All @@ -35,7 +36,6 @@ const Contest = () => {

useEffect(() => {
const interval = setInterval(() => getTime(), 1000);

return () => clearInterval(interval);
});

Expand All @@ -44,11 +44,26 @@ const Contest = () => {

if (data) {
problemsCount = data.problems.length;
data.problems.forEach(({ isSolved }) => {
if (isSolved) solvedCount++;
data.problems.forEach(({ is_solved }) => {
if (is_solved) solvedCount++;
});
}

const submitProblem = async (problem_id) => {
try {
await axios.post("/api/submissions/", { problem_id: problem_id });
window.location.reload();
} catch (err) {
if (
err.code == "ERR_BAD_REQUEST" &&
err.request.response == '["problem is not solved"]'
) {
alert("You have not solved the Problem yet");
return;
}
}
};

if (Date.now() - Date.parse(data.start_date_time) < 0)
return (
<ContestCountdown
Expand All @@ -71,12 +86,12 @@ const Contest = () => {
</tr>
</thead>
<tbody>
{data.problems.map(({ name, link, isSolved }, ind) => {
{data.problems.map(({ id, name, link, is_solved }, ind) => {
return (
<tr
key={link}
key={id}
className={
isSolved ? "bg-green-600 text-white" : "bg-base-300"
is_solved ? "bg-green-600 text-white" : "bg-base-300"
}
>
<td>{ind + 1}</td>
Expand All @@ -86,10 +101,16 @@ const Contest = () => {
</a>
</td>
<td>
{isSolved ? (
{is_solved ? (
<div className="btn text-2xl"></div>
) : (
<div className="btn text-2xl"> 🔍 </div>
<button
className="btn text-2xl"
onClick={() => submitProblem(id)}
>
{" "}
🔍{" "}
</button>
)}
</td>
</tr>
Expand Down

0 comments on commit fc298e1

Please sign in to comment.