Refresh views when an entry is logged from anywhere in the app - #287
Merged
Conversation
Logging from the bottom-nav FAB never updated the screen underneath. Layout renders its own QuickLogDialog outside the routed page and passed no onLogged callback, so a feeding saved from the main screen didn't show up until a manual reload. Add a DataRefreshProvider exposing a refreshKey/refreshData pair. QuickLogDialog bumps the key itself after a successful save, so every mount point benefits, and the Dashboard plus the entry list, activity and charts pages refetch on that key. The provider also bumps on visibilitychange/focus (throttled) so returning to the installed PWA picks up entries logged on another device. The Dashboard fetch moves into the effect with a cancellation guard so an in-flight load can't overwrite newer data, and now surfaces load errors. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_019DSiaPu62P8nPww2vhF3zf
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
Logging a feeding (or anything else) from the bottom-nav FAB while on the main screen didn't update the dashboard — the new entry only appeared after a manual page reload.
Layoutrenders its ownQuickLogDialogfor the FAB sheet, outside the routed page, and never passed anonLoggedcallback. The dashboard'sreloadAllwas only reachable from the dialog the dashboard itself renders (the tile grid), so the FAB path had no way to tell the page underneath that data had changed.Changes
DataRefreshProvider/useDataRefreshhook (client/src/hooks/useDataRefresh.tsx) exposing arefreshKeycounter and arefreshData()signal, mounted inApp.tsxinsideChildProvider.QuickLogDialogcallsrefreshData()itself after a successful save, so every mount point benefits rather than each caller having to wire up a callback. The existingonLoggedprop still works.refreshKey: Dashboard, Feedings, Diapers, Sleep, Tummy Time, Pumping, Notes, Activity and Charts add it to their load effect dependencies — so the FAB now updates whichever screen is behind it, not just the dashboard.visibilitychange/focus(throttled to 2s, since both fire when returning to a tab), so the installed PWA picks up entries logged on another device instead of showing stale cards after sitting in the background.Testing
client/test/DataRefresh.test.tsx(4 tests) reproduces the bug: aQuickLogDialogrendered as a sibling of the dashboard (mirroringLayout) triggers a refetch on save, doesn't refetch on cancel, refetches onvisibilitychange, and doesn't double-fetch whenvisibilitychangeandfocusboth fire.client/test/Dashboard.test.tsxnow wraps inDataRefreshProviderand asserts refetch counts — the previous assertions passed on the initial mount fetch alone and would not have caught this.npm test -w client— 63 passed (9 files).npm test -w server— 70 passed.npm run build -w clientclean.Generated by Claude Code