mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-18 16:12:11 +00:00
feat(modules): hide nav entries and Insights pills for disabled modules
Generalise the per-destination cycle gate into a requiresModule marker on each nav destination and read it from the account's resolved module map (the modules field on GET /api/auth/me). Fold the bespoke cycle boolean into requiresModule: "cycle" so there is one gating mechanism; cycle and coach are delegated keys already reflected in the map, so reading them here is not a re-derivation. Tag mood, cycle, labs, coach and achievements with their module keys; core destinations (measurements, medications, vorsorge, insights, the dashboard) carry none and always render. The sidebar, the mobile More hub, and the Insights tab strip all filter on the same map. Insights pills: a metric pill belonging to a toggleable module (mood, sleep, glucose, workouts) hides when its module is disabled, on top of the existing data + saved-layout gates; the Recovery pill gates on the recovery module. Overview and core-metric pills always show. Every gate fails open — a missing key or an absent map keeps the entry, matching the gate's default-on contract, so a stale /me payload never blanks the nav.
This commit is contained in:
1 parent
76d24dd684
commit
5682055fe2
14 files changed
+396
-62
No files matched your search
@@ -9,6 +9,7 @@ import { retryOnceOnTransientError } from "@/lib/queries/retry-transient";
|
||||
import { useTranslations } from "@/lib/i18n/context";
|
||||
import type { TimeFormatPreference } from "@/lib/format-locale";
|
||||
import { isTimeFormatPreference, storeTimeFormat } from "@/lib/time-format";
|
||||
import type { ModuleKey } from "@/lib/modules/registry";
|
||||
|
||||
export interface AuthUser {
|
||||
id: string;
|
||||
@@ -80,6 +81,18 @@ export interface AuthUser {
|
||||
* stale /me payload (older server image without the field) in `fetchMe`.
|
||||
*/
|
||||
cycleTrackingEnabled: boolean;
|
||||
/**
|
||||
* v1.18.0 — the resolved per-user module enable/disable map. Each
|
||||
* toggleable module key (mood, sleep, glucose, workouts, recovery, labs,
|
||||
* achievements, coach, insights, doctorReport, cycle) is `true` when the
|
||||
* module is enabled for this account, `false` when disabled. `cycle` and
|
||||
* `coach` are delegated server-side (gender + opt-in / operator flag +
|
||||
* opt-out) and already reflected here, so nav + Insights pill gates read
|
||||
* this map rather than re-deriving. Coerced to `{}` against a stale /me
|
||||
* payload (older server image without the field) so every gate fails open
|
||||
* — a missing map never blanks the nav.
|
||||
*/
|
||||
modules: Partial<Record<ModuleKey, boolean>>;
|
||||
}
|
||||
|
||||
async function fetchMe(): Promise<AuthUser> {
|
||||
@@ -117,6 +130,11 @@ async function fetchMe(): Promise<AuthUser> {
|
||||
// v1.15.0 — coerce against a stale /me payload so the cycle nav entry
|
||||
// stays hidden by default when the field is absent.
|
||||
cycleTrackingEnabled: data.cycleTrackingEnabled === true,
|
||||
// v1.18.0 — coerce against a stale /me payload (older server image
|
||||
// without the module map) to an empty map so every module gate fails
|
||||
// open: a missing key reads as enabled and the nav stays intact.
|
||||
modules:
|
||||
data.modules && typeof data.modules === "object" ? data.modules : {},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user