feat(demo): header countdown switches to reset timer when questions exhausted
Dev — Build & local smoke test / build-smoke (pull_request) Failing after 8s

When a user hits the 10-question limit, the header countdown flips from
'0 questions left' to a live 'resets in HH:MM:SS' ticker counting to
midnight UTC. Clears automatically when the session resets.
This commit is contained in:
2026-05-07 02:49:11 -05:00
parent e6d10fc3d5
commit 5f35ddde39
+42
View File
@@ -76,17 +76,59 @@ fn main() -> Void {
saveSession(session);
}
var msgCount = session.count || 0;
var _headerResetInterval = null;
function _nextMidnightUTC() {
var now = new Date();
var midnight = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate() + 1));
return Math.floor(midnight.getTime() / 1000);
}
function _startHeaderResetTimer() {
var el = document.getElementById('neuron-demo-countdown');
if (!el) return;
if (_headerResetInterval) return; // already ticking
var resetAt = _nextMidnightUTC();
function _tick() {
var secsLeft = Math.max(0, resetAt - Math.floor(Date.now() / 1000));
var hh = Math.floor(secsLeft / 3600);
var mm = Math.floor((secsLeft % 3600) / 60);
var ss = secsLeft % 60;
var pad = function(n) { return n < 10 ? '0' + n : '' + n; };
var ts = hh + ':' + pad(mm) + ':' + pad(ss);
var el2 = document.getElementById('neuron-demo-countdown');
if (!el2) { clearInterval(_headerResetInterval); _headerResetInterval = null; return; }
el2.textContent = 'resets in ' + ts;
el2.style.color = 'rgba(255,255,255,0.65)';
el2.style.fontWeight = '600';
if (secsLeft <= 0) {
clearInterval(_headerResetInterval);
_headerResetInterval = null;
el2.textContent = '10 questions left';
el2.style.color = '#ffffff';
el2.style.fontWeight = '700';
}
}
_tick();
_headerResetInterval = setInterval(_tick, 1000);
}
function updateCountdown() {
var el = document.getElementById('neuron-demo-countdown');
if (!el) return;
var remaining = MAX - msgCount;
if (remaining <= 0) {
_startHeaderResetTimer();
} else {
if (_headerResetInterval) { clearInterval(_headerResetInterval); _headerResetInterval = null; }
el.textContent = remaining + ' question' + (remaining === 1 ? '' : 's') + ' left';
el.style.color = '#ffffff';
el.style.fontWeight = '700';
}
}
window.neuronDemoReset = function() {
if (_headerResetInterval) { clearInterval(_headerResetInterval); _headerResetInterval = null; }
clearSession();
session = { messages: [], count: 0, context: '' };
msgCount = 0;