Files
loki/scripts/preview/knowledge-map.preview.tsx
Cato 964777b7ac Make Memory explain projects, next actions and the research behind them (#1740)
* feat: connect project purpose, next actions and research in Memory

* test: resolve superseding essays through the real dynamic route
2026-11-30 05:51:51 +01:00

46 lines
1.7 KiB
TypeScript

import * as React from "react";
import { createRoot } from "react-dom/client";
import { SessionProvider } from "next-auth/react";
import { AppShell } from "@/components/shell/AppShell";
import { PageLayout } from "@/components/ui/page-layout";
import { KnowledgeMap } from "@/components/memory/KnowledgeMap";
import { MAP_FIXTURE, BUSY_MAP } from "./knowledge-map.fixture";
// Public synthetic fixture, through the real shell. No account/network writes.
window.fetch = async (input) => {
const url = String(input);
const body = url.includes("/api/auth/pin")
? { configured: false, unlocked: true }
: url.includes("/api/alerts")
? { alerts: [] }
: url.includes("/api/user-projects")
? []
: url.includes("/api/sessions/snapshot")
? { sessions: [], projects: [], working: [] }
: null;
return new Response(JSON.stringify(body), { headers: { "content-type": "application/json" } });
};
const params = new URLSearchParams(window.location.search);
params.set("previewPath", "/memory");
history.replaceState(null, "", "?" + params);
const fixture = params.has("busy") ? BUSY_MAP : MAP_FIXTURE;
const session = {
user: {
id: "preview",
name: "Example builder",
email: "preview@example.test",
emailVerified: true,
},
expires: "2099-01-01",
};
createRoot(document.getElementById("root")!).render(
<SessionProvider session={session} refetchOnWindowFocus={false}>
<AppShell viewerId="preview" initialSidebarCollapsed={false}>
<PageLayout title="Memory" maxWidth="max-w-7xl">
<KnowledgeMap
map={params.has("empty") ? { ...MAP_FIXTURE, nodes: [], edges: [] } : fixture}
/>
</PageLayout>
</AppShell>
</SessionProvider>,
);