From e0068776a479e058e0767e48e87c2de9ed93e3ff Mon Sep 17 00:00:00 2001 From: Francisco Pessano Date: Thu, 4 Sep 2025 14:00:20 -0300 Subject: [PATCH] feat: enhance SpacesGrid to display snapshot data and improve space rendering --- apps/web/src/components/spaces-grid.tsx | 139 ++++++++++++------------ apps/web/src/lib/appwrite-db.ts | 2 + apps/web/src/routes/space.tsx | 5 + 3 files changed, 77 insertions(+), 69 deletions(-) diff --git a/apps/web/src/components/spaces-grid.tsx b/apps/web/src/components/spaces-grid.tsx index 80adf05..4524eee 100644 --- a/apps/web/src/components/spaces-grid.tsx +++ b/apps/web/src/components/spaces-grid.tsx @@ -147,79 +147,80 @@ export function SpacesGrid() { {/* Spaces Grid */}
- {filteredSpaces.map((space) => ( - { - window.location.href = `/space?id=${space.id}`; - }} - > - -
-
-
-

- {space.name} -

+ {filteredSpaces.map((space) => { + const snapshot = space.snapshotText + ? JSON.parse(space.snapshotText).document + : undefined; + return ( + { + window.location.href = `/space?id=${space.id}`; + }} + > + +
+
+
+

+ {space.name} +

+
+
- -
-
+ - -
- +
+ { - editor.updateInstanceState({ isReadonly: true }); - }} - snapshot={ - space.snapshotText - ? JSON.parse(space.snapshotText).document - : undefined - } - /> -
- + }} + className="min-h-52" + hideUi + onMount={(editor) => { + editor.updateInstanceState({ isReadonly: true }); + }} + snapshot={snapshot} + /> +
+
- - {space.itemCount} items - Edited {space.lastEdited} - -
- ))} + + {snapshot?.itemCount} items + Edited {space.lastEdited} + + + ); + })}
{/* Empty State (when no spaces exist) */} diff --git a/apps/web/src/lib/appwrite-db.ts b/apps/web/src/lib/appwrite-db.ts index 9920db0..60b1c74 100644 --- a/apps/web/src/lib/appwrite-db.ts +++ b/apps/web/src/lib/appwrite-db.ts @@ -100,6 +100,8 @@ export async function upsertSpaceSnapshot( spaceId, userId: uid, snapshot: JSON.stringify(payload), + title: existing?.title, + color: existing?.color, } as const; if (existing) { diff --git a/apps/web/src/routes/space.tsx b/apps/web/src/routes/space.tsx index a8b1f81..f219256 100644 --- a/apps/web/src/routes/space.tsx +++ b/apps/web/src/routes/space.tsx @@ -9,6 +9,7 @@ import { } from "tldraw"; import { z } from "zod"; import "tldraw/tldraw.css"; +import Loader from "@/components/loader"; import { getLatestSpaceSnapshot, type RemoteSnapshot, @@ -78,6 +79,10 @@ function SpaceRoute() { }; }, [id, session, store]); + if (!(id && session)) { + return ; + } + return (