Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 28 additions & 22 deletions frontend/src/js/controllers/challengeCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,28 +321,34 @@
vm.eachPhase = details[i];
vm.phaseRemainingSubmissionsFlags[details[i].id] = "showClock";
vm.countDownTimer = function () {
vm.remainingTime = vm.eachPhase.limits.remaining_time;
vm.days = Math.floor(vm.remainingTime / 24 / 60 / 60);
vm.hoursLeft = Math.floor((vm.remainingTime) - (vm.days * 86400));
vm.hours = Math.floor(vm.hoursLeft / 3600);
vm.minutesLeft = Math.floor((vm.hoursLeft) - (vm.hours * 3600));
vm.minutes = Math.floor(vm.minutesLeft / 60);
vm.remainingSeconds = Math.floor(vm.remainingTime % 60);
if (vm.remainingSeconds < 10) {
vm.remainingSeconds = "0" + vm.remainingSeconds;
}
vm.phaseRemainingSubmissionsCountdown[details[i].id] = {
"days": vm.days,
"hours": vm.hours,
"minutes": vm.minutes,
"seconds": vm.remainingSeconds
};
if (vm.remainingTime === 0) {
vm.phaseRemainingSubmissionsFlags[details[i].id] = "showSubmissionNumbers";
} else {
vm.remainingSeconds--;
}
};
// Check if time has run out
if (vm.eachPhase.limits.remaining_time <= 0) {
vm.phaseRemainingSubmissionsFlags[details[i].id] = "showSubmissionNumbers";
return;
}

// Calculate time components from remaining_time
var totalSeconds = vm.eachPhase.limits.remaining_time;
vm.days = Math.floor(totalSeconds / 86400);
vm.hoursLeft = totalSeconds % 86400;
vm.hours = Math.floor(vm.hoursLeft / 3600);
vm.minutesLeft = vm.hoursLeft % 3600;
vm.minutes = Math.floor(vm.minutesLeft / 60);
vm.seconds = totalSeconds % 60;

// Format seconds with leading zero if needed
var formattedSeconds = vm.seconds < 10 ? "0" + vm.seconds : vm.seconds;

Copilot AI Feb 23, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This returns a string for < 10 but a number for >= 10, which makes seconds type inconsistent for bindings/formatting. Prefer always producing a string (e.g., via String(vm.seconds).padStart(2, '0')) so the UI doesn't have to handle mixed types.

Suggested change
var formattedSeconds = vm.seconds < 10 ? "0" + vm.seconds : vm.seconds;
var formattedSeconds = String(vm.seconds).padStart(2, '0');

Copilot uses AI. Check for mistakes.

vm.phaseRemainingSubmissionsCountdown[details[i].id] = {
"days": vm.days,
"hours": vm.hours,
"minutes": vm.minutes,
"seconds": formattedSeconds
};

// Decrement the source value (remaining_time)
vm.eachPhase.limits.remaining_time--;
Comment on lines +349 to +350

Copilot AI Feb 23, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can still drive remaining_time negative (e.g., if it starts at 0 or becomes 0 between ticks), which risks reintroducing negative countdown values elsewhere and makes the model inconsistent. Clamp the decrement so it never drops below 0 (e.g., set to Math.max(0, remaining_time - 1)), or only decrement when remaining_time > 0.

Suggested change
// Decrement the source value (remaining_time)
vm.eachPhase.limits.remaining_time--;
// Decrement the source value (remaining_time) without going below zero
vm.eachPhase.limits.remaining_time = Math.max(0, vm.eachPhase.limits.remaining_time - 1);

Copilot uses AI. Check for mistakes.
};
Comment on lines +324 to +351

Copilot AI Feb 23, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diff removes the vm.countDownTimer = function () { assignment line but keeps the closing }; at line 351. As-is, this block will either be a syntax error (unmatched };) or will execute immediately instead of defining vm.countDownTimer, breaking setInterval(... $apply(vm.countDownTimer) ...). Add back the function wrapper so vm.countDownTimer is actually a function and the braces/semicolons match.

Suggested change
// Check if time has run out
if (vm.eachPhase.limits.remaining_time <= 0) {
vm.phaseRemainingSubmissionsFlags[details[i].id] = "showSubmissionNumbers";
return;
}
// Calculate time components from remaining_time
var totalSeconds = vm.eachPhase.limits.remaining_time;
vm.days = Math.floor(totalSeconds / 86400);
vm.hoursLeft = totalSeconds % 86400;
vm.hours = Math.floor(vm.hoursLeft / 3600);
vm.minutesLeft = vm.hoursLeft % 3600;
vm.minutes = Math.floor(vm.minutesLeft / 60);
vm.seconds = totalSeconds % 60;
// Format seconds with leading zero if needed
var formattedSeconds = vm.seconds < 10 ? "0" + vm.seconds : vm.seconds;
vm.phaseRemainingSubmissionsCountdown[details[i].id] = {
"days": vm.days,
"hours": vm.hours,
"minutes": vm.minutes,
"seconds": formattedSeconds
};
// Decrement the source value (remaining_time)
vm.eachPhase.limits.remaining_time--;
};
vm.countDownTimer = function () {
// Check if time has run out
if (vm.eachPhase.limits.remaining_time <= 0) {
vm.phaseRemainingSubmissionsFlags[details[i].id] = "showSubmissionNumbers";
return;
}
// Calculate time components from remaining_time
var totalSeconds = vm.eachPhase.limits.remaining_time;
vm.days = Math.floor(totalSeconds / 86400);
vm.hoursLeft = totalSeconds % 86400;
vm.hours = Math.floor(vm.hoursLeft / 3600);
vm.minutesLeft = vm.hoursLeft % 3600;
vm.minutes = Math.floor(vm.minutesLeft / 60);
vm.seconds = totalSeconds % 60;
// Format seconds with leading zero if needed
var formattedSeconds = vm.seconds < 10 ? "0" + vm.seconds : vm.seconds;
vm.phaseRemainingSubmissionsCountdown[details[i].id] = {
"days": vm.days,
"hours": vm.hours,
"minutes": vm.minutes,
"seconds": formattedSeconds
};
// Decrement the source value (remaining_time)
vm.eachPhase.limits.remaining_time--;
};

Copilot uses AI. Check for mistakes.
setInterval(function () {
$rootScope.$apply(vm.countDownTimer);
}, 1000);
Comment on lines 352 to 354

Copilot AI Feb 23, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When time runs out, the code switches the flag and returns, but the interval continues to fire every second and forces a digest via $apply. Consider storing the interval handle and clearing it once remaining_time <= 0 to avoid unnecessary work.

Copilot uses AI. Check for mistakes.
Expand Down
Loading