feat: enhance SpacesGrid to display snapshot data and improve space rendering

This commit is contained in:
2025-09-04 14:00:20 -03:00
parent 83a2992c0d
commit e0068776a4
3 changed files with 77 additions and 69 deletions

View File

@@ -147,7 +147,11 @@ export function SpacesGrid() {
{/* Spaces Grid */} {/* Spaces Grid */}
<div className="grid grid-cols-1 gap-6 md:grid-cols-2 lg:grid-cols-3"> <div className="grid grid-cols-1 gap-6 md:grid-cols-2 lg:grid-cols-3">
{filteredSpaces.map((space) => ( {filteredSpaces.map((space) => {
const snapshot = space.snapshotText
? JSON.parse(space.snapshotText).document
: undefined;
return (
<Card <Card
className="group cursor-pointer border-border/50 transition-all duration-200 hover:border-border hover:shadow-lg" className="group cursor-pointer border-border/50 transition-all duration-200 hover:border-border hover:shadow-lg"
key={space.id} key={space.id}
@@ -205,21 +209,18 @@ export function SpacesGrid() {
onMount={(editor) => { onMount={(editor) => {
editor.updateInstanceState({ isReadonly: true }); editor.updateInstanceState({ isReadonly: true });
}} }}
snapshot={ snapshot={snapshot}
space.snapshotText
? JSON.parse(space.snapshotText).document
: undefined
}
/> />
</div> </div>
</CardContent> </CardContent>
<CardFooter className="flex items-center justify-between pt-0 text-muted-foreground text-sm"> <CardFooter className="flex items-center justify-between pt-0 text-muted-foreground text-sm">
<span>{space.itemCount} items</span> <span>{snapshot?.itemCount} items</span>
<span>Edited {space.lastEdited}</span> <span>Edited {space.lastEdited}</span>
</CardFooter> </CardFooter>
</Card> </Card>
))} );
})}
</div> </div>
{/* Empty State (when no spaces exist) */} {/* Empty State (when no spaces exist) */}

View File

@@ -100,6 +100,8 @@ export async function upsertSpaceSnapshot(
spaceId, spaceId,
userId: uid, userId: uid,
snapshot: JSON.stringify(payload), snapshot: JSON.stringify(payload),
title: existing?.title,
color: existing?.color,
} as const; } as const;
if (existing) { if (existing) {

View File

@@ -9,6 +9,7 @@ import {
} from "tldraw"; } from "tldraw";
import { z } from "zod"; import { z } from "zod";
import "tldraw/tldraw.css"; import "tldraw/tldraw.css";
import Loader from "@/components/loader";
import { import {
getLatestSpaceSnapshot, getLatestSpaceSnapshot,
type RemoteSnapshot, type RemoteSnapshot,
@@ -78,6 +79,10 @@ function SpaceRoute() {
}; };
}, [id, session, store]); }, [id, session, store]);
if (!(id && session)) {
return <Loader />;
}
return ( return (
<div className="mx-4 mt-4" style={{ position: "relative", inset: 0 }}> <div className="mx-4 mt-4" style={{ position: "relative", inset: 0 }}>
<Tldraw <Tldraw