-
-
Notifications
You must be signed in to change notification settings - Fork 19
Implement whiteboard management #3137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
56425e7
feat: add new whiteboard page and maintain localstorage snapsnot mana…
khangronky 5a14899
feat: implement new whiteboard prototype page with search and sorting…
khangronky 7335216
feat: add whiteboards table and related RLS policies, implement snaps…
khangronky 6e51aef
feat: add functionality to load whiteboard snapshot and thumbnail fro…
khangronky 6fe2e17
refactor(whiteboards): Move save toolbar to a separate component
khangronky 9295caf
feat(whiteboards): add create and edit whiteboard dialogs with form h…
khangronky 2c61a37
fix(toolbar): update success toast message to reflect whiteboard save
khangronky 7205bbc
Merge remote-tracking branch 'origin/main' into feat/whiteboards
khangronky 6accf37
fix(types): remove duplicate fields from Database type definitions in…
khangronky 8f5216d
fix: Fix any issues raised by PR review bots
khangronky 1dd40f1
refactor(whiteboards): rename whiteboards table to workspace_whiteboa…
vhpx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
apps/db/supabase/migrations/20250620034755_create_whiteboards.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
create table "public"."whiteboards" ( | ||
"id" uuid not null default gen_random_uuid(), | ||
"title" text not null, | ||
"description" text, | ||
"snapshot" jsonb, | ||
"ws_id" uuid not null, | ||
"created_at" timestamp with time zone not null default now(), | ||
"thumbnail_url" text, | ||
"updated_at" timestamp with time zone not null default now(), | ||
"creator_id" uuid not null | ||
); | ||
|
||
alter table "public"."whiteboards" enable row level security; | ||
|
||
CREATE UNIQUE INDEX whiteboards_pkey ON public.whiteboards USING btree (id); | ||
|
||
alter table "public"."whiteboards" add constraint "whiteboards_pkey" PRIMARY KEY using index "whiteboards_pkey"; | ||
|
||
alter table "public"."whiteboards" add constraint "whiteboards_creator_id_fkey" FOREIGN KEY (creator_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE not valid; | ||
|
||
alter table "public"."whiteboards" validate constraint "whiteboards_creator_id_fkey"; | ||
|
||
alter table "public"."whiteboards" add constraint "whiteboards_ws_id_fkey" FOREIGN KEY (ws_id) REFERENCES workspaces(id) ON UPDATE CASCADE ON DELETE CASCADE not valid; | ||
|
||
alter table "public"."whiteboards" validate constraint "whiteboards_ws_id_fkey"; | ||
|
||
grant delete on table "public"."whiteboards" to "anon"; | ||
|
||
grant insert on table "public"."whiteboards" to "anon"; | ||
|
||
grant references on table "public"."whiteboards" to "anon"; | ||
|
||
grant select on table "public"."whiteboards" to "anon"; | ||
|
||
grant trigger on table "public"."whiteboards" to "anon"; | ||
|
||
grant truncate on table "public"."whiteboards" to "anon"; | ||
|
||
grant update on table "public"."whiteboards" to "anon"; | ||
|
||
grant delete on table "public"."whiteboards" to "authenticated"; | ||
|
||
grant insert on table "public"."whiteboards" to "authenticated"; | ||
|
||
grant references on table "public"."whiteboards" to "authenticated"; | ||
|
||
grant select on table "public"."whiteboards" to "authenticated"; | ||
|
||
grant trigger on table "public"."whiteboards" to "authenticated"; | ||
|
||
grant truncate on table "public"."whiteboards" to "authenticated"; | ||
|
||
grant update on table "public"."whiteboards" to "authenticated"; | ||
|
||
grant delete on table "public"."whiteboards" to "service_role"; | ||
|
||
grant insert on table "public"."whiteboards" to "service_role"; | ||
|
||
grant references on table "public"."whiteboards" to "service_role"; | ||
|
||
grant select on table "public"."whiteboards" to "service_role"; | ||
|
||
grant trigger on table "public"."whiteboards" to "service_role"; | ||
|
||
grant truncate on table "public"."whiteboards" to "service_role"; | ||
|
||
grant update on table "public"."whiteboards" to "service_role"; | ||
|
||
|
20 changes: 20 additions & 0 deletions
20
apps/db/supabase/migrations/20250620034855_add_whiteboards_rls.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
-- Add an index to improve join performance | ||
CREATE INDEX IF NOT EXISTS idx_whiteboards_ws_id ON whiteboards(ws_id); | ||
CREATE INDEX IF NOT EXISTS idx_whiteboards_creator_id ON whiteboards(creator_id); | ||
|
||
CREATE INDEX idx_whiteboards_snapshot_gin ON public.whiteboards USING GIN (snapshot); | ||
|
||
CREATE POLICY "Workspace members can read and write whiteboards" ON public.whiteboards | ||
FOR ALL TO authenticated | ||
USING ( | ||
ws_id IN ( | ||
SELECT ws_id FROM public.workspace_members | ||
WHERE user_id = auth.uid() | ||
) | ||
) | ||
WITH CHECK ( | ||
ws_id IN ( | ||
SELECT ws_id FROM public.workspace_members | ||
WHERE user_id = auth.uid() | ||
) | ||
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
apps/web/src/app/[locale]/(dashboard)/[wsId]/whiteboards/[boardId]/loading.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export default function Loading() { | ||
return ( | ||
<div className="flex h-full w-full flex-col gap-4 p-4"> | ||
<div className="h-10 w-48 animate-pulse rounded-lg bg-foreground/5" /> | ||
<div className="h-full w-full animate-pulse rounded-lg bg-foreground/5" /> | ||
</div> | ||
); | ||
} |
35 changes: 35 additions & 0 deletions
35
apps/web/src/app/[locale]/(dashboard)/[wsId]/whiteboards/[boardId]/page.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { CustomTldraw } from './custom-tldraw'; | ||
import { createClient } from '@tuturuuu/supabase/next/server'; | ||
import { notFound } from 'next/navigation'; | ||
import { TLStoreSnapshot } from 'tldraw'; | ||
|
||
export default async function TLDrawPage({ | ||
params, | ||
}: { | ||
params: Promise<{ boardId: string }>; | ||
}) { | ||
const { boardId } = await params; | ||
|
||
const supabase = await createClient(); | ||
|
||
const { data: whiteboard } = await supabase | ||
.from('whiteboards') | ||
.select('*') | ||
.eq('id', boardId) | ||
.single(); | ||
|
||
if (!whiteboard) return notFound(); | ||
khangronky marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return ( | ||
<div className="absolute inset-0"> | ||
<CustomTldraw | ||
boardId={boardId} | ||
initialData={ | ||
whiteboard.snapshot | ||
? (JSON.parse(whiteboard.snapshot as string) as TLStoreSnapshot) | ||
: undefined | ||
} | ||
khangronky marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/> | ||
</div> | ||
); | ||
} |
100 changes: 100 additions & 0 deletions
100
apps/web/src/app/[locale]/(dashboard)/[wsId]/whiteboards/[boardId]/toolbar.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { createClient } from '@tuturuuu/supabase/next/client'; | ||
import { Button } from '@tuturuuu/ui/button'; | ||
import { useToast } from '@tuturuuu/ui/hooks/use-toast'; | ||
import { ArrowLeftIcon } from '@tuturuuu/ui/icons'; | ||
import Link from 'next/link'; | ||
import { useCallback } from 'react'; | ||
import { useEditor } from 'tldraw'; | ||
|
||
export default function Toolbar({ boardId }: { boardId: string }) { | ||
const supabase = createClient(); | ||
|
||
const editor = useEditor(); | ||
const { toast } = useToast(); | ||
|
||
const generateThumbnail = async () => { | ||
const shapeIds = editor.getCurrentPageShapeIds(); | ||
if (shapeIds.size === 0) { | ||
throw new Error('No shapes on canvas'); | ||
} | ||
|
||
const { blob } = await editor.toImage([...shapeIds], { | ||
format: 'png', | ||
background: true, | ||
scale: 0.3, | ||
padding: 16, | ||
}); | ||
|
||
return blob; | ||
}; | ||
|
||
const generateFileName = (name: string) => { | ||
const now = new Date(); | ||
const year = now.getFullYear(); | ||
const month = String(now.getMonth() + 1).padStart(2, '0'); | ||
const day = String(now.getDate()).padStart(2, '0'); | ||
const hours = String(now.getHours()).padStart(2, '0'); | ||
const minutes = String(now.getMinutes()).padStart(2, '0'); | ||
const seconds = String(now.getSeconds()).padStart(2, '0'); | ||
|
||
return `${year}${month}${day}-${hours}-${minutes}-${seconds}-${name}`; | ||
}; | ||
|
||
const save = useCallback(async () => { | ||
try { | ||
const thumbnailBlob = await generateThumbnail(); | ||
const thumbnailFileName = generateFileName(`${boardId}.png`); | ||
const thumbnailFile = new File([thumbnailBlob], thumbnailFileName, { | ||
type: 'image/png', | ||
}); | ||
khangronky marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const { error: thumbnailError } = await supabase.storage | ||
.from('whiteboards-thumbnails') | ||
.upload(thumbnailFileName, thumbnailFile); | ||
|
||
if (thumbnailError) throw thumbnailError; | ||
|
||
const { data: thumbnailUrl } = supabase.storage | ||
.from('whiteboards-thumbnails') | ||
.getPublicUrl(thumbnailFileName); | ||
|
||
const snapshot = editor.getSnapshot(); | ||
|
||
await supabase | ||
.from('whiteboards') | ||
.update({ | ||
snapshot: JSON.stringify(snapshot), | ||
thumbnail_url: thumbnailUrl.publicUrl, | ||
updated_at: new Date().toISOString(), | ||
}) | ||
.eq('id', boardId); | ||
|
||
khangronky marked this conversation as resolved.
Show resolved
Hide resolved
|
||
toast({ | ||
title: 'Saved successfully!', | ||
description: 'Your whiteboard has been saved.', | ||
variant: 'default', | ||
}); | ||
} catch (error: any) { | ||
console.error(error); | ||
toast({ | ||
title: 'Error saving', | ||
description: 'Failed to save whiteboard', | ||
variant: 'destructive', | ||
}); | ||
} | ||
}, [editor]); | ||
khangronky marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return ( | ||
<div className="pointer-events-auto flex gap-4 p-4"> | ||
<Link href={`/whiteboards`}> | ||
khangronky marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<Button variant="ghost"> | ||
<ArrowLeftIcon className="h-4 w-4" /> | ||
Back | ||
</Button> | ||
</Link> | ||
<Button variant="default" onClick={save}> | ||
Save Snapshot | ||
</Button> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.