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