@@ -9,7 +9,7 @@ import { useMediaQuery } from "@/hooks/useMediaQuery";
99import { CanvasEngine } from "@/canvas-engine/CanvasEngine" ;
1010import { RoomParticipants } from "@repo/common/types" ;
1111import { getRoomParamsFromHash } from "@/utils/roomParams" ;
12- import { BgFill , canvasBgLight , FillStyle , FontFamily , FontSize , Mode , RoughStyle , StrokeEdge , StrokeFill , StrokeStyle , StrokeWidth , TextAlign , ToolType } from "@/types/canvas" ;
12+ import { BgFill , canvasBgLight , FillStyle , FontFamily , FontSize , LOCALSTORAGE_CANVAS_KEY , Mode , RoughStyle , StrokeEdge , StrokeFill , StrokeStyle , StrokeWidth , TextAlign , ToolType } from "@/types/canvas" ;
1313import { MobileCommandBar } from "../MobileCommandBar" ;
1414import ScreenLoading from "../ScreenLoading" ;
1515import AppMenuButton from "../AppMenuButton" ;
@@ -19,8 +19,9 @@ import ToolSelector from "../ToolSelector";
1919import CollaborationToolbar from "../CollaborationToolbar" ;
2020import ZoomControl from "../ZoomControl" ;
2121import CollabydrawTextEditorContainer from "../Collabydraw-TextEditorContainer" ;
22+ import { HomeWelcome , MainMenuWelcome , ToolMenuWelcome } from "../welcome-screen" ;
2223
23- export default function CanvasRoot ( ) {
24+ export default function CanvasBoard ( ) {
2425 const { data : session , status } = useSession ( ) ;
2526 const pathname = usePathname ( ) ;
2627 const searchParams = useSearchParams ( ) ;
@@ -50,7 +51,8 @@ export default function CanvasRoot() {
5051 textAlign : 'left' as TextAlign ,
5152 grabbing : false ,
5253 sidebarOpen : false ,
53- canvasColor : canvasBgLight [ 0 ]
54+ canvasColor : canvasBgLight [ 0 ] ,
55+ isCanvasEmpty : true
5456 } ) ;
5557 const userRef = useRef ( {
5658 roomId : null as string | null ,
@@ -115,6 +117,16 @@ export default function CanvasRoot() {
115117 setCanvasEngineState ( prev => ( { ...prev , canvasColor : canvasBgLight [ 0 ] } ) ) ;
116118 } , [ theme ] )
117119
120+ useEffect ( ( ) => {
121+ const storedShapes = localStorage . getItem ( LOCALSTORAGE_CANVAS_KEY ) ;
122+ const isEmpty = ! storedShapes || JSON . parse ( storedShapes ) . length === 0 ;
123+
124+ setCanvasEngineState ( prev => ( {
125+ ...prev ,
126+ isCanvasEmpty : isEmpty
127+ } ) ) ;
128+ } , [ ] ) ;
129+
118130 useEffect ( ( ) => {
119131 const { engine, scale } = canvasEngineState ;
120132 if ( engine ) {
@@ -270,6 +282,11 @@ export default function CanvasRoot() {
270282 onClearCanvas = { clearCanvas }
271283 />
272284 ) }
285+
286+ { canvasEngineState . activeTool === "grab" && canvasEngineState . isCanvasEmpty && (
287+ < MainMenuWelcome />
288+ ) }
289+
273290 </ div >
274291
275292 < StyleConfigurator
@@ -335,6 +352,12 @@ export default function CanvasRoot() {
335352 ) }
336353 </ div >
337354
355+ { canvasEngineState . activeTool === "grab" && canvasEngineState . isCanvasEmpty && ! isLoading && (
356+ < div className = "relative" >
357+ < ToolMenuWelcome />
358+ </ div >
359+ ) }
360+
338361 { matches && (
339362 < ZoomControl
340363 scale = { canvasEngineState . scale }
@@ -387,6 +410,15 @@ export default function CanvasRoot() {
387410 />
388411
389412 ) }
413+
414+ { ! isLoading && canvasEngineState . activeTool === "grab" && canvasEngineState . isCanvasEmpty && (
415+ < HomeWelcome />
416+ ) }
417+
418+ { isLoading && (
419+ < ScreenLoading />
420+ ) }
421+
390422 < canvas className = { cn ( "collabydraw collabydraw-canvas" , theme === 'dark' ? 'collabydraw-canvas-dark' : '' ) } ref = { canvasRef } />
391423 </ div >
392424 )
0 commit comments