diff --git a/modules/room/components/Canvas.tsx b/modules/room/components/Canvas.tsx index 4f5ec17..4ae8324 100644 --- a/modules/room/components/Canvas.tsx +++ b/modules/room/components/Canvas.tsx @@ -1,17 +1,29 @@ import { CANVAS_SIZE } from "@/common/constants/canvasSize"; + import { useViewportSize } from "@/common/hooks/useViewportSize"; + import { useMotionValue, motion } from "framer-motion"; + import { useRef, useState, useEffect } from "react"; + import { useKeyPressEvent } from "react-use"; + import { useDraw, useSocketDraw } from "../hooks/Canvas.hooks"; + import { socket } from "@/common/lib/socket"; + import Minimap from "./Minimap"; +import room, { useRoom } from "@/common/recoil/room"; +import { drawAllMoves } from "../helpers/Canvas.helpers"; + + const Canvas = () => { + const room= useRoom(); const canvasRef = useRef(null); const smallCanvasRef = useRef(null); - const [ctx, setCtx] = useState(); + const [ctx, setCtx] = useState(); const [dragging, setDragging] = useState(false); const [, setMovedMiniMap] = useState(false); @@ -44,10 +56,11 @@ const Canvas = () => { const { handleDraw, handleEndDrawing, handleStartDrawing, drawing, handleUndo } = useDraw( ctx, - dragging, - copyCanvasToSmall + dragging ); + useSocketDraw(ctx,drawing); + useEffect(() => { const newCtx = canvasRef.current?.getContext("2d"); if (newCtx) setCtx(newCtx); @@ -63,7 +76,18 @@ const Canvas = () => { } }, [dragging]); - useSocketDraw(ctx,drawing, copyCanvasToSmall); + useEffect(()=> { + if(ctx) socket.emit("joined_room"); + },[ctx]); + + useEffect(()=> { + if(ctx){ + drawAllMoves(ctx, room); + copyCanvasToSmall(); + }; + }, [ctx, room]); + + return (