fix(pihole): live pause countdown on blocking badge - #213
Merged
Conversation
The 'Blockierung steuern' pause buttons sent POST /pihole/blocking (200 ok) but nothing changed on screen: the badge only rendered blocking.state and ignored blocking.timer, and the endpoint answers before the async resync, so the client read back the stale pre-toggle state. Render the timer as a live countdown (e.g. 'Off · 0:29'): a shared updateBlocking() turns blocking.timer into a local deadline, a 1s ticker counts it down and reloads when it expires, and the toggle updates the badge optimistically (SSE 'pihole' then delivers ground truth) instead of racing an immediate load().
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On the
/piholepage, clicking a "Blockierung steuern" pause button (Pause 30s/5m/30m) does nothing visible. The request itself is fine —POST /api/v1/pihole/blockingreturns{"ok":true}(200) — but:blocking.state(On/Off/Partial) and throw awayblocking.timer, so a paused state never shows the intended countdown.{ok:true}before the async server resync runs, so the client's immediateload()reads back the stale pre-toggle state → the badge doesn't move.Fix (frontend only — the timer data already exists server-side)
updateBlocking({state,timer})+paintBlockingBadge(), used by both theme renderers.blocking.timer→ local deadline; a 1s ticker counts it down (Off · 0:29) and callsload()when it expires (Pi-hole auto-re-enables via its own timer).piholeSSE event then delivers ground truth — no immediateload()racing the resync.Test
tests/pihole_pause_countdown_ui.test.js— asserts the countdown wiring (updateBlocking, ticker, optimistic toggle) and the zero-padded m:ss formula.🤖 Generated with Claude Code