22
33import { useWebSocket } from "@/hooks/useWebSocket" ;
44import { Game } from "@/draw/Game" ;
5- import { BgFill , canvasBgDark , canvasBgLight , Shape , StrokeEdge , StrokeFill , StrokeWidth , ToolType } from "@/types/canvas" ;
5+ import { BgFill , canvasBgLight , Shape , StrokeEdge , StrokeFill , StrokeStyle , StrokeWidth , ToolType } from "@/types/canvas" ;
66import { useCallback , useEffect , useRef , useState } from "react" ;
77import { Scale } from "../Scale" ;
88import { MobileNavbar } from "../mobile-navbar" ;
@@ -14,6 +14,7 @@ import { useMediaQuery } from "@/hooks/useMediaQuery";
1414import Toolbar from "../Toolbar" ;
1515import ScreenLoading from "../ScreenLoading" ;
1616import CollaborationStart from "../CollaborationStartBtn" ;
17+ import { cn } from "@/lib/utils" ;
1718
1819export function CanvasSheet ( { roomName, roomId, userId, userName } : { roomName : string ; roomId : string ; userId : string ; userName : string ; } ) {
1920 const { theme } = useTheme ( )
@@ -25,16 +26,18 @@ export function CanvasSheet({ roomName, roomId, userId, userName }: { roomName:
2526 const [ strokeWidth , setStrokeWidth ] = useState < StrokeWidth > ( 1 ) ;
2627 const [ bgFill , setBgFill ] = useState < BgFill > ( "#00000000" ) ;
2728 const [ strokeEdge , setStrokeEdge ] = useState < StrokeEdge > ( "round" ) ;
29+ const [ strokeStyle , setStrokeStyle ] = useState < StrokeStyle > ( "solid" ) ;
2830 const [ grabbing , setGrabbing ] = useState ( false ) ;
2931 const [ existingShapes , setExistingShapes ] = useState < Shape [ ] > ( [ ] ) ;
3032 const paramsRef = useRef ( { roomId, roomName, userId, userName } ) ;
3133 const activeToolRef = useRef ( activeTool ) ;
3234 const strokeFillRef = useRef ( strokeFill ) ;
3335 const strokeWidthRef = useRef ( strokeWidth ) ;
3436 const strokeEdgeRef = useRef ( strokeEdge ) ;
37+ const strokeStyleRef = useRef ( strokeStyle ) ;
3538 const bgFillRef = useRef ( bgFill ) ;
3639 const [ sidebarOpen , setSidebarOpen ] = useState ( false ) ;
37- const [ canvasColor , setCanvasColor ] = useState < string > ( theme === 'light' ? canvasBgLight [ 0 ] : canvasBgDark [ 0 ] ) ;
40+ const [ canvasColor , setCanvasColor ] = useState < string > ( canvasBgLight [ 0 ] ) ;
3841 const canvasColorRef = useRef ( canvasColor ) ;
3942
4043 const { isConnected, messages, sendMessage } = useWebSocket (
@@ -47,8 +50,8 @@ export function CanvasSheet({ roomName, roomId, userId, userName }: { roomName:
4750 const { matches, isLoading } = useMediaQuery ( 'md' ) ;
4851
4952 useEffect ( ( ) => {
50- setCanvasColor ( theme === 'light' ? canvasBgLight [ 0 ] : canvasBgDark [ 0 ] ) ;
51- } , [ theme ] ) ;
53+ setCanvasColor ( canvasBgLight [ 0 ] ) ;
54+ } , [ theme ] )
5255
5356 useEffect ( ( ) => {
5457 const handleResize = ( ) => {
@@ -107,6 +110,11 @@ export function CanvasSheet({ roomName, roomId, userId, userName }: { roomName:
107110 game ?. setStrokeEdge ( strokeEdge ) ;
108111 } , [ strokeEdge , game ] ) ;
109112
113+ useEffect ( ( ) => {
114+ strokeStyleRef . current = strokeStyle ;
115+ game ?. setStrokeStyle ( strokeStyle ) ;
116+ } , [ strokeStyle , game ] ) ;
117+
110118 useEffect ( ( ) => {
111119 activeToolRef . current = activeTool ;
112120 game ?. setTool ( activeTool ) ;
@@ -249,7 +257,7 @@ export function CanvasSheet({ roomName, roomId, userId, userName }: { roomName:
249257
250258 return (
251259 < div className = { `collabydraw h-screen overflow-hidden ${ ( activeTool === "grab" && ! sidebarOpen ) ? ( grabbing ? "cursor-grabbing" : "cursor-grab" ) : "cursor-crosshair" } ` } >
252- < div className = "App_Menu App_Menu_Top fixed top-4 right-4 left-4 flex justify-center items-center md:grid md:grid-cols-[1fr_auto_1fr] md:gap-8 md:items-start" >
260+ < div className = "App_Menu App_Menu_Top fixed z-[4] top-4 right-4 left-4 flex justify-center items-center md:grid md:grid-cols-[1fr_auto_1fr] md:gap-8 md:items-start" >
253261 { matches && (
254262 < div className = "Main_Menu_Stack Sidebar_Trigger_Button md:grid md:gap-[calc(.25rem*6)] grid-cols-[auto] grid-flow-row grid-rows auto-rows-min justify-self-start" >
255263 < div className = "relative" >
@@ -275,6 +283,8 @@ export function CanvasSheet({ roomName, roomId, userId, userName }: { roomName:
275283 setBgFill = { setBgFill }
276284 strokeEdge = { strokeEdge }
277285 setStrokeEdge = { setStrokeEdge }
286+ strokeStyle = { strokeStyle }
287+ setStrokeStyle = { setStrokeStyle }
278288 />
279289 </ div >
280290 ) }
@@ -311,7 +321,7 @@ export function CanvasSheet({ roomName, roomId, userId, userName }: { roomName:
311321 roomName = { roomName }
312322 />
313323 ) }
314- < canvas ref = { canvasRef } />
324+ < canvas className = { cn ( "collabydraw collabydraw-canvas" , theme === 'dark' ? 'collabydraw-canvas-dark' : '' ) } ref = { canvasRef } />
315325 </ div >
316326 )
317327}
0 commit comments