Make +- snappier.

This commit is contained in:
2026-06-09 09:32:19 +02:00
parent 0c6e94ef9f
commit 438836913a

View File

@ -219,15 +219,26 @@ HTML = """\
} }
} }
async function adjustBudget(device, delta) { function adjustBudget(device, delta) {
try { // Update UI immediately (optimistic update)
await fetch('https://noom.cc/off/budget', { const items = document.querySelectorAll('.status-item');
method: 'POST', const devMap = {tv: 0, gabi: 1, gaja: 2};
headers: {'Content-Type': 'application/json'}, const idx = devMap[device];
body: JSON.stringify({device, delta}) if (idx !== undefined && items[idx]) {
}); const budgetEl = items[idx].querySelector('.budget');
} catch(e) {} const current = parseInt(budgetEl.textContent.match(/\\d+/)?.[0] || '0');
refreshStatus(); const maxBudget = {max_budget};
const newBudget = Math.max(0, Math.min(maxBudget, current + Math.round(delta / 60)));
const status = budgetEl.textContent.split(' · ')[0];
budgetEl.textContent = `${status} · ${newBudget} min left`;
}
// Send to server in background (fire-and-forget)
fetch('https://noom.cc/off/budget', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({device, delta})
}).catch(() => {});
} }
refreshStatus(); refreshStatus();
@ -237,6 +248,9 @@ HTML = """\
</html> </html>
""" """
# Inject config values into HTML template
HTML = HTML.replace("{max_budget}", str(int(config.BUDGET_S / 60)))
if __name__ == "__main__": if __name__ == "__main__":
from devices import start_timer from devices import start_timer
port = int(__import__("os").environ.get("PORT", "10000")) port = int(__import__("os").environ.get("PORT", "10000"))