diff --git a/server/community-store.ts b/server/community-store.ts index 9107b43..69fdf5c 100644 --- a/server/community-store.ts +++ b/server/community-store.ts @@ -884,6 +884,23 @@ export function clearShapes(slug: string): void { if (doc) { const newDoc = Automerge.change(doc, "Clear all shapes", (d) => { d.shapes = {}; + // Reset seeded flag so demo reset can re-seed + (d.meta as any).shapesSeeded = false; + }); + communities.set(slug, newDoc); + saveCommunity(slug); + } +} + +/** + * Mark a community as having been seeded with shapes. + * Prevents re-seeding after users delete all content. + */ +export function markShapesSeeded(slug: string): void { + const doc = communities.get(slug); + if (doc) { + const newDoc = Automerge.change(doc, "Mark shapes seeded", (d) => { + (d.meta as any).shapesSeeded = true; }); communities.set(slug, newDoc); saveCommunity(slug); diff --git a/server/seed-campaign.ts b/server/seed-campaign.ts index 4cda7dd..06c58db 100644 --- a/server/seed-campaign.ts +++ b/server/seed-campaign.ts @@ -19,6 +19,7 @@ import { createCommunity, getDocumentData, loadCommunity, + markShapesSeeded, } from "./community-store"; // ── Layout constants ──────────────────────────────────────────── @@ -481,15 +482,17 @@ export async function ensureCampaignDemo(): Promise { // Check if already seeded const data = getDocumentData(slug); const shapeCount = data ? Object.keys(data.shapes || {}).length : 0; + const alreadySeeded = (data?.meta as any)?.shapesSeeded === true; - if (shapeCount === 0) { + if (shapeCount === 0 && !alreadySeeded) { addShapes(slug, CAMPAIGN_SHAPES); + markShapesSeeded(slug); console.log( `[Campaign] Seeded ${CAMPAIGN_SHAPES.length} shapes into campaign-demo`, ); } else { console.log( - `[Campaign] campaign-demo already has ${shapeCount} shapes`, + `[Campaign] campaign-demo already has ${shapeCount} shapes (seeded=${alreadySeeded})`, ); } } diff --git a/server/seed-demo.ts b/server/seed-demo.ts index 3aa528a..e7f55f5 100644 --- a/server/seed-demo.ts +++ b/server/seed-demo.ts @@ -13,6 +13,7 @@ import { createCommunity, getDocumentData, loadCommunity, + markShapesSeeded, } from "./community-store"; // ── Alpine Explorer 2026 — Demo Scenario ────────────────────────── @@ -781,14 +782,16 @@ export async function ensureDemoCommunity(): Promise { await loadCommunity("demo"); } - // Check if already seeded (has shapes) + // Check if already seeded (has shapes or was previously seeded then cleared) const data = getDocumentData("demo"); const shapeCount = data ? Object.keys(data.shapes || {}).length : 0; + const alreadySeeded = (data?.meta as any)?.shapesSeeded === true; - if (shapeCount === 0) { + if (shapeCount === 0 && !alreadySeeded) { addShapes("demo", DEMO_SHAPES); + markShapesSeeded("demo"); console.log(`[Demo] Seeded ${DEMO_SHAPES.length} shapes into demo community`); } else { - console.log(`[Demo] Demo community already has ${shapeCount} shapes`); + console.log(`[Demo] Demo community already has ${shapeCount} shapes (seeded=${alreadySeeded})`); } } diff --git a/server/seed-template.ts b/server/seed-template.ts index 3ea8f1a..4ebb657 100644 --- a/server/seed-template.ts +++ b/server/seed-template.ts @@ -14,6 +14,7 @@ import { getDocumentData, listCommunities, loadCommunity, + markShapesSeeded, } from "./community-store"; // ── Template Shapes ───────────────────────────────────────────────── @@ -418,12 +419,14 @@ export function seedTemplateShapes(slug: string): boolean { const data = getDocumentData(slug); const shapeCount = data ? Object.keys(data.shapes || {}).length : 0; + const alreadySeeded = (data?.meta as any)?.shapesSeeded === true; - if (shapeCount > 0) { + if (shapeCount > 0 || alreadySeeded) { return false; } addShapes(slug, TEMPLATE_SHAPES); + markShapesSeeded(slug); console.log(`[Template] Seeded ${TEMPLATE_SHAPES.length} template shapes into "${slug}"`); return true; }