26 lines
726 B
TypeScript
26 lines
726 B
TypeScript
import type { Block } from "@/features/editor/state/editorStore";
|
|
|
|
interface PublicProjectSnapshot {
|
|
slug: string;
|
|
title: string;
|
|
contentJson: Block[];
|
|
}
|
|
|
|
function getStore(): Map<string, PublicProjectSnapshot> {
|
|
const g = globalThis as any;
|
|
if (!g.__PB_PUBLIC_PROJECTS) {
|
|
g.__PB_PUBLIC_PROJECTS = new Map<string, PublicProjectSnapshot>();
|
|
}
|
|
return g.__PB_PUBLIC_PROJECTS as Map<string, PublicProjectSnapshot>;
|
|
}
|
|
|
|
export function cachePublicProject(snapshot: PublicProjectSnapshot): void {
|
|
const store = getStore();
|
|
store.set(snapshot.slug, snapshot);
|
|
}
|
|
|
|
export function getCachedPublicProject(slug: string): PublicProjectSnapshot | null {
|
|
const store = getStore();
|
|
return store.get(slug) ?? null;
|
|
}
|