Skip to content

Keep History figures with their selected period - #66

Merged
frahlg merged 1 commit into
mainfrom
fix/history-period-freshness
Sep 7, 2026
Merged

Keep History figures with their selected period#66
frahlg merged 1 commit into
mainfrom
fix/history-period-freshness

Conversation

@frahlg

@frahlg frahlg commented Sep 7, 2026

Copy link
Copy Markdown
Member

Switching History from 7 days to Today used to keep the week's totals and bars under the Today heading until a new answer arrived, even after a failed read. A period change now clears those figures immediately and invalidates the previous period's pending reply. A refresh of the same period keeps its figures, and the existing retry restores a failed read.

Validation: npm run verify passes, including 1,027 tests (one skipped), type checks and the production build. Regression tests caught the old total under Today and late success/failure replies before the fix. They cover loading, failure, automatic recovery, same-period refresh and a previously empty period.

Browser check on be619aadce13e807cd4b9c026aaa7d34835ffb2e: a separate local SimBox fixture returned HTTP 503 only for /api/energy/daily. Switching from 341 kWh over seven days to Today removed the old figures and bars and showed the loading and retry messages. After two failed reads, the normal retry filled Today with 37 kWh and removed the error without a reload. Viewed at 1280×720 and 390×844; the mobile cards and message fit without horizontal overflow. These checks use simulated data.


Note

Medium Risk
Changes async race handling and empty/loaded UX for energy history; wrong token logic could drop valid data or flash empty states, but scope is limited to the History energy store and existing retry paths.

Overview
Fixes History showing the previous range’s totals and chart under a new period label (e.g. week kWh under Today) while a fetch was in flight or after errors.

EnergyStore.select now no-ops on the same range; otherwise it bumps the request token, clears days, resets loaded/loading/error, and only then switches range. load still uses tokens so late success/failure replies for an old range never repopulate the UI. Failed refreshes for the current period still keep that period’s figures and show “not up to date”; fetching on tap stays with askWhenLive.

Adds store tests (empty prior period, stale replies) and Energy integration tests (no mislabeling during load/retry, same-period refresh on visibility). Patch changeset for ftw-webapp.

Reviewed by Cursor Bugbot for commit be619aa. Bugbot is set up for automated code reviews on this repo. Configure here.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
ftw-webapp be619aa Commit Preview URL

Branch Preview URL
Sep 07 2026, 06:36 PM

@frahlg
frahlg marked this pull request as ready for review September 7, 2026 18:41
@cursor

cursor Bot commented Sep 7, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_1181de53-2082-474c-a1b3-61a69d555271)

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 7, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-07T18:43:46.375882Z be619aa Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@frahlg
frahlg merged commit c193ed3 into main Sep 7, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant