Skip to content

Commit

Permalink
Fix Whiteboard responsiveness
Browse files Browse the repository at this point in the history
  • Loading branch information
joh-ann committed Jan 10, 2024
1 parent 3952ce1 commit 2e2dc88
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/components/WhiteBoard/WhiteBoard.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,37 @@ function WhiteBoard() {
context = ctx;
remoteContext = canvas.getContext("2d");

ctx.fillStyle = `${appColor === "light" ? "white" : "#636363"}`;
context.strokeStyle = `${appColor === "light" ? "black" : "white"}`;
ctx.fillRect(0, 0, canvas.width, canvas.height);
function updateCanvasSize() {
const parent = canvas.parentElement;

// Set maximum width and height for the canvas
const maxWidth = 1200;
const maxHeight = 600;

// Calculate new width and height based on the parent size
const newWidth = Math.min(parent.clientWidth, maxWidth);
const newHeight = Math.min(parent.clientHeight, maxHeight);

// Set canvas size
canvas.width = newWidth;
canvas.height = newHeight;

ctx.fillStyle = `${appColor === "light" ? "white" : "#636363"}`;
context.strokeStyle = `${appColor === "light" ? "black" : "white"}`;
ctx.fillRect(0, 0, canvas.width, canvas.height);
}

updateCanvasSize();

window.addEventListener("resize", updateCanvasSize);
canvas.addEventListener("mousedown", startDrawing);
canvas.addEventListener("mouseup", stopDrawing);
canvas.addEventListener("mousemove", draw);

socket.addEventListener("message", received);

return () => {
window.addEventListener("resize", updateCanvasSize);
canvas.removeEventListener("mousedown", startDrawing);
canvas.removeEventListener("mouseup", stopDrawing);
canvas.removeEventListener("mousemove", draw);
Expand Down

0 comments on commit 2e2dc88

Please sign in to comment.