mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-11 05:42:19 +00:00
/topics shows a tile per topic the record holds data for, and names the empty topics and the module-hidden ones once each. /topics/<topic> shows the topic today, its signals side by side over 7, 30, 90 days or a year against their usual range, how they move together, their trends, its blocks, the single-metric pages behind it and what it is missing. Every topic links into the metric pages, which stay as they are, and each page ends on a neutral note that this is a preview. Settings > System > Preview features is listed again and switches the area on for the person reading. While it is on, the sidebar carries a Topics entry with a Beta badge directly below Insights and the phone's More sheet leads with a Topics tile; the bottom bar does not change. The pages leave for Insights when the switch is off. The charts load through the shared chart runtime. The sidebar rows move into their own module and the More sheet tile into its own component, so neither shell file grows; the lab trend wording is shared between the marker page and the metabolism topic. Copy in all nine locales.
32 lines
1.2 KiB
TypeScript
32 lines
1.2 KiB
TypeScript
"use client";
|
|
|
|
import { useEffect, type ReactNode } from "react";
|
|
import { useRouter } from "next/navigation";
|
|
|
|
import { PageAuthGate } from "@/components/ui/page-auth-gate";
|
|
import { useAuth } from "@/hooks/use-auth";
|
|
|
|
/**
|
|
* The Topics area exists only for a person who switched the preview on.
|
|
*
|
|
* Until the account payload answers, the page shows the shell's loading
|
|
* state; signed out, it goes to sign-in like every page; with the preview off
|
|
* (an old bookmark, a link from someone else) it leaves for Insights, where
|
|
* the person's pages are. The routes refuse on their own (404
|
|
* `topics.preview_off`), so this is the friendly end, not the guard.
|
|
*/
|
|
export function TopicsPreviewGate({ children }: { children: ReactNode }) {
|
|
const { user, isLoading, isAuthenticated } = useAuth();
|
|
const router = useRouter();
|
|
const enabled = user?.previewFeatures?.topics === true;
|
|
|
|
useEffect(() => {
|
|
if (isLoading) return;
|
|
if (!isAuthenticated) router.replace("/auth/login");
|
|
else if (!enabled) router.replace("/insights");
|
|
}, [isLoading, isAuthenticated, enabled, router]);
|
|
|
|
if (isLoading || !isAuthenticated || !enabled) return <PageAuthGate />;
|
|
return <>{children}</>;
|
|
}
|