mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-08 20:42:43 +00:00
refactor(shell): return the switched-off module instead of a flag
The flag helper sat between the module gate's doc comment and the component, so the comment read as its own. It is now switchedOffModule(), which returns the owning module when it is off and has a doc comment of its own above the gate's; the gate narrows on its result directly instead of looking the module up twice.
This commit is contained in:
1 parent
c133b4ac74
commit
11b6119482
2 files changed
+19
-15
No files matched your search
@@ -28,8 +28,8 @@ import { OfflineBanner } from "./offline-banner";
|
||||
import { SharedRecordBanner } from "./shared-record-banner";
|
||||
import { SharedRecordUnavailable } from "./shared-record-unavailable";
|
||||
import {
|
||||
isModulePageOff,
|
||||
ModulePageGate,
|
||||
switchedOffModule,
|
||||
} from "@/components/layout/module-page-gate";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { isOnboardingPathname } from "@/lib/onboarding/wizard-steps";
|
||||
@@ -158,7 +158,7 @@ export function AuthShell({
|
||||
const fullBleed =
|
||||
pathname === COACH_FULL_BLEED_PATH &&
|
||||
!outsideSharedRecord &&
|
||||
!isModulePageOff(pathname, user?.modules);
|
||||
switchedOffModule(pathname, user?.modules) === undefined;
|
||||
// The whole setup flow, not only its front door: every screen lives under
|
||||
// `/onboarding/<step>` (v1.39 C2), and an exact match here put the
|
||||
// questions inside the full app chrome, sidebar and all.
|
||||
|
||||
@@ -56,6 +56,21 @@ export function moduleOwningPath(pathname: string): ModuleKey | undefined {
|
||||
return destination ? navDestinationModule(destination) : undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* The module that owns `pathname` when it is switched off, otherwise
|
||||
* undefined. The shell reads it too: a switched-off page renders the
|
||||
* notice in the ordinary padded frame.
|
||||
*/
|
||||
export function switchedOffModule(
|
||||
pathname: string,
|
||||
modules: Partial<Record<ModuleKey, boolean>> | null | undefined,
|
||||
): ModuleKey | undefined {
|
||||
const moduleKey = moduleOwningPath(pathname);
|
||||
return moduleKey !== undefined && modules?.[moduleKey] === false
|
||||
? moduleKey
|
||||
: undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* A page of a module that is switched off answers with an inline notice that
|
||||
* names the reason, in one place for every module page: top-level pages
|
||||
@@ -74,24 +89,13 @@ export function moduleOwningPath(pathname: string): ModuleKey | undefined {
|
||||
* only after the account payload resolved, so the map is never read on a
|
||||
* hydration render.
|
||||
*/
|
||||
/** True when the module that owns `pathname` is switched off. */
|
||||
export function isModulePageOff(
|
||||
pathname: string,
|
||||
modules: Partial<Record<ModuleKey, boolean>> | null | undefined,
|
||||
): boolean {
|
||||
const moduleKey = moduleOwningPath(pathname);
|
||||
return moduleKey !== undefined && modules?.[moduleKey] === false;
|
||||
}
|
||||
|
||||
export function ModulePageGate({ children }: { children: ReactNode }) {
|
||||
const pathname = usePathname();
|
||||
const { user } = useAuth();
|
||||
const { t } = useTranslations();
|
||||
|
||||
const moduleKey = moduleOwningPath(pathname);
|
||||
if (moduleKey === undefined || !isModulePageOff(pathname, user?.modules)) {
|
||||
return <>{children}</>;
|
||||
}
|
||||
const moduleKey = switchedOffModule(pathname, user?.modules);
|
||||
if (moduleKey === undefined) return <>{children}</>;
|
||||
|
||||
const destination = NAV_DESTINATIONS.find((d) =>
|
||||
isNavDestinationActive(d.href, pathname),
|
||||
|
||||
Reference in new issue
Block a user