mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-14 22:50:51 +00:00
fix(glucose): show targets in the new unit right after a unit change
After switching between mg/dL and mmol/L, the target panels on the glucose page kept the old unit for up to ten minutes. Their unit comes from the cached targets payload, and the save only refreshed the account payload. The select now invalidates the targets query, and the route evicts the profile-derived server caches when the unit changes, the same way the thresholds and source-priority writes do.
This commit is contained in:
1 parent
0c07764097
commit
08e6229142
4 files changed
+26
-7
No files matched your search
@@ -134,6 +134,19 @@ describe("Settings — GlucoseUnitSelect", () => {
|
||||
expect(componentSource).toMatch(/queryKey: queryKeys\.authMe\(\)/);
|
||||
});
|
||||
|
||||
// The targets panel takes its unit from the targets payload, not from the
|
||||
// account, so a save that only refreshed `/me` left it on the old unit
|
||||
// until the server cache turned over (up to ten minutes). Both ends have
|
||||
// to let go of the old payload.
|
||||
it("refreshes the targets payload on both ends", () => {
|
||||
expect(componentSource).toMatch(/queryKey: queryKeys\.insightsTargets\(\)/);
|
||||
const route = readFileSync(
|
||||
join(process.cwd(), "src/app/api/auth/me/glucose-unit/route.ts"),
|
||||
"utf8",
|
||||
);
|
||||
expect(route).toMatch(/!== next\) \{\s*invalidateUserProfile\(user\.id\);/);
|
||||
});
|
||||
|
||||
it("is actually mounted on the settings page", () => {
|
||||
// A control nobody can reach is the same defect as no control.
|
||||
const accountSection = readFileSync(
|
||||
|
||||
@@ -31,7 +31,8 @@ import { resolveGlucoseUnit, type GlucoseUnit } from "@/lib/glucose";
|
||||
* Persistence mirrors the unit-system select: a change PATCHes
|
||||
* `/api/auth/me/glucose-unit` immediately and invalidates `queryKeys.authMe()`,
|
||||
* so the dashboard tiles and the glucose insight page re-render on the next
|
||||
* /me refetch.
|
||||
* /me refetch, and `queryKeys.insightsTargets()`, whose payload states the
|
||||
* target ranges in the unit it was built with.
|
||||
*/
|
||||
export function GlucoseUnitSelect({
|
||||
isAuthenticated,
|
||||
@@ -66,6 +67,7 @@ export function GlucoseUnitSelect({
|
||||
onSuccess: () => {
|
||||
toastWrittenOutcome("success", t("settings.dashboard.glucoseUnit.saved"));
|
||||
queryClient.invalidateQueries({ queryKey: queryKeys.authMe() });
|
||||
queryClient.invalidateQueries({ queryKey: queryKeys.insightsTargets() });
|
||||
setOptimistic(null);
|
||||
},
|
||||
onError: (err) => {
|
||||
|
||||
Reference in new issue
Block a user