Skip to content

Commit

Permalink
add background component
Browse files Browse the repository at this point in the history
  • Loading branch information
deveshidwivedi committed Jun 27, 2024
1 parent 79ebf25 commit 0f416e8
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
9 changes: 6 additions & 3 deletions modules/room/components/Room.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@ import MouseRenderer from "./MouseRenderer";
import { ToolBar } from "./toolbar/ToolBar";
import NameInput from "./NameInput";
import UsersList from "./UsersList";
import { useRef } from "react";



const Room = () => {
const room = useRoom();
if(!room.id) return <NameInput />

const undoRef= useRef<HTMLButtonElement>(null);
if(!room.id) return <NameInput />;

return (
<RoomContextProvider>
<div className="relative h-full w-full overflow-hidden">
<UsersList />
<ToolBar />
<Canvas />
<ToolBar undoRef={undoRef}/>
<Canvas undoRef={undoRef}/>
<MousePosition />
<MouseRenderer />
</div>
Expand Down
45 changes: 45 additions & 0 deletions modules/room/components/board/Background.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { useEffect, useRef } from "react";
import { useBoardPosition } from "../../hooks/useBoardPosition";
import {motion} from "framer-motion";
import { CANVAS_SIZE } from "@/common/constants/canvasSize";

const Background = () => {
const {x,y} = useBoardPosition();
const ref= useRef<HTMLCanvasElement>(null);

useEffect(()=> {
const ctx= ref.current?.getContext("2d");

if(ctx){
ctx.fillStyle="#fff";
ctx.fillRect(0,0,CANVAS_SIZE.width, CANVAS_SIZE.height);
ctx.lineWidth=1;
ctx.strokeStyle="#ccc";


for(let i=0;i<CANVAS_SIZE.height;i+=25){
ctx.beginPath();
ctx.moveTo(0,i);
ctx.lineTo(CANVAS_SIZE.width,i);
ctx.stroke();
}
for(let i=0;i<CANVAS_SIZE.width;i+=25){
ctx.beginPath();
ctx.moveTo(i,0);
ctx.lineTo(i, CANVAS_SIZE.height);
ctx.stroke();
}
}
},[]);
return (
<motion.canvas
ref={ref}
width={CANVAS_SIZE.width}
height={CANVAS_SIZE.height}
className="absolute top-0 bg-zinc-100"
style={{x,y}}
/>
);
};

export default Background;

0 comments on commit 0f416e8

Please sign in to comment.