mirror of
http://nostr-git-proxy.forgejo.svc.cluster.local/git/45387ca441053e230b2126802005eb03767ab59d84555e8bac86b6e7def14e27/myadhd
synced 2026-09-23 20:23:10 +00:00
fix(sprint4): actually implement missing JS wiring for pie clock & interval ground
This commit is contained in:
parent
c654e85c8d
commit
b9f6e21841
1 changed files with 65 additions and 4 deletions
|
|
@ -299,10 +299,43 @@
|
|||
store('timer_state', { total: timer.total, left: timer.left, phase: timer.phase });
|
||||
}
|
||||
|
||||
window.groundingIv = null;
|
||||
window.setGroundingInterval = function() {
|
||||
if (window.groundingIv) { clearInterval(window.groundingIv); window.groundingIv = null; }
|
||||
var activeBtn = $('.grounding-chime.active');
|
||||
if (!activeBtn) return;
|
||||
var mins = parseInt(activeBtn.dataset.interval, 10);
|
||||
if (mins > 0 && timer.running) {
|
||||
window.groundingIv = setInterval(function() {
|
||||
if (window.playGroundingPing) window.playGroundingPing();
|
||||
}, mins * 60 * 1000);
|
||||
}
|
||||
};
|
||||
|
||||
function timerPaint() {
|
||||
var m = Math.floor(timer.left / 60), s = timer.left % 60;
|
||||
$('#timer-time').textContent = (m < 10 ? '0' : '') + m + ':' + (s < 10 ? '0' : '') + s;
|
||||
$('#ring-fg').style.strokeDashoffset = CIRC * (1 - timer.left / timer.total);
|
||||
|
||||
var portion = timer.total > 0 ? (timer.left / timer.total) : 0;
|
||||
var piePath = $('#ring-pie-path');
|
||||
var pieSvg = $('#ring-pie-svg');
|
||||
if (piePath && pieSvg) {
|
||||
if (portion <= 0) {
|
||||
piePath.setAttribute("d", "M110,110 Z");
|
||||
} else if (portion >= 1) {
|
||||
piePath.setAttribute("d", "M110,110 L110,10 A100,100 0 1,1 109.99,10 Z");
|
||||
} else {
|
||||
var angle = portion * 360;
|
||||
var rad = (angle * Math.PI) / 180;
|
||||
var x = 110 + 100 * Math.sin(rad);
|
||||
var y = 110 - 100 * Math.cos(rad);
|
||||
var largeArc = angle > 180 ? 1 : 0;
|
||||
piePath.setAttribute("d", "M110,110 L110,10 A100,100 0 " + largeArc + ",1 " + x + "," + y + " Z");
|
||||
}
|
||||
pieSvg.classList.toggle('alert-amber', timer.left < 120 && timer.running);
|
||||
}
|
||||
|
||||
// Ring color matches phase
|
||||
var ringFg = $('#ring-fg');
|
||||
if (timer.phase === 'break') { ringFg.classList.add('break-ring'); }
|
||||
|
|
@ -323,7 +356,7 @@
|
|||
}
|
||||
|
||||
function timerStop() { clearInterval(timer.iv); timer.iv = null; timer.running = false;
|
||||
if (window.groundingIv) clearInterval(groundingIv); timerPersist(); }
|
||||
if (window.groundingIv) clearInterval(window.groundingIv); timerPersist(); }
|
||||
|
||||
function timerComplete() {
|
||||
timerStop(); beep();
|
||||
|
|
@ -356,11 +389,31 @@
|
|||
timerPaint();
|
||||
}
|
||||
|
||||
// Pie Mode Toggle
|
||||
var modeToggleBtn = $('#timer-mode-toggle');
|
||||
if (modeToggleBtn) {
|
||||
modeToggleBtn.addEventListener('click', function() {
|
||||
var pieSvg = $('#ring-pie-svg');
|
||||
var ringSvg = $('.timer-wrap > svg.ring:not(.pie-mode)');
|
||||
var isPie = pieSvg.style.display !== 'none';
|
||||
if (isPie) {
|
||||
pieSvg.style.display = 'none';
|
||||
ringSvg.style.display = '';
|
||||
this.innerHTML = '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="margin-right:8px; vertical-align:text-bottom;"><circle cx="12" cy="12" r="10"></circle><path d="M12 2v10l5.5 5.5"></path></svg> switch to visual pie mode';
|
||||
} else {
|
||||
pieSvg.style.display = '';
|
||||
ringSvg.style.display = 'none';
|
||||
this.innerHTML = '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="margin-right:8px; vertical-align:text-bottom;"><circle cx="12" cy="12" r="10"></circle><polyline points="12 6 12 12 16 14"></polyline></svg> switch to ring mode';
|
||||
}
|
||||
timerPaint();
|
||||
});
|
||||
}
|
||||
|
||||
$('#timer-start').addEventListener('click', function () {
|
||||
if (window.setGroundingInterval) setGroundingInterval();
|
||||
if (window.setGroundingInterval) window.setGroundingInterval();
|
||||
if (timer.running) { timerStop(); $('#timer-start').textContent = 'resume'; timerPaint(); return; }
|
||||
timer.running = true;
|
||||
if (window.setGroundingInterval) setGroundingInterval();
|
||||
if (window.setGroundingInterval) window.setGroundingInterval();
|
||||
$('#timer-start').textContent = 'pause';
|
||||
timer.iv = setInterval(function () {
|
||||
timer.left--;
|
||||
|
|
@ -368,7 +421,7 @@
|
|||
if (timer.left <= 0) {
|
||||
timerComplete();
|
||||
return;
|
||||
if (window.groundingIv) clearInterval(groundingIv);
|
||||
if (window.groundingIv) clearInterval(window.groundingIv);
|
||||
}
|
||||
timerPaint();
|
||||
}, 1000);
|
||||
|
|
@ -392,6 +445,14 @@
|
|||
});
|
||||
});
|
||||
|
||||
$$('.grounding-chime').forEach(function(btn) {
|
||||
btn.addEventListener('click', function() {
|
||||
$$('.grounding-chime').forEach(function(b) { b.classList.remove('active'); });
|
||||
btn.classList.add('active');
|
||||
if (window.setGroundingInterval) window.setGroundingInterval();
|
||||
});
|
||||
});
|
||||
|
||||
// Timer completion overlay actions
|
||||
$('#timer-take-break').addEventListener('click', function () {
|
||||
$('#timer-complete').hidden = true;
|
||||
|
|
|
|||
Loading…
Reference in a new issue