Skip to content

Commit 14b794b

Browse files
committed
add canvas state
1 parent d1f9e4a commit 14b794b

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

client/src/App.jsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Canvas from "./components/Canvas";
1010
import Menu from "./components/Menu";
1111
import EraserCursor from "./components/EraserCursor";
1212
import { useRecoilValue, useRecoilState } from "recoil";
13-
import { eraserState, cursorPosition, canvasColors } from "./atoms";
13+
import { eraserState, cursorPosition, canvasColors, canvasState } from "./atoms";
1414

1515
function App() {
1616
const [showMenu, setShowMenu] = useState(false);
@@ -22,6 +22,7 @@ function App() {
2222
const [isDrawing, setIsDrawing] = useState(false);
2323
const [penColor, setPenColor] = useState("#000000");
2424
const canvasColor = useRecoilValue(canvasColors);
25+
const [currentCanvas, setCanvas] = useRecoilState(canvasState);
2526

2627
function toggleMenu() {
2728
setShowMenu(!showMenu);
@@ -41,7 +42,8 @@ function App() {
4142
}
4243

4344
useEffect(() => {
44-
const canvas = canvasRef.current;
45+
setCanvas(canvasRef.current);
46+
const canvas = currentCanvas;
4547
if (canvas) {
4648
const context = canvas.getContext("2d");
4749
canvas.width = canvas.getBoundingClientRect().width;
@@ -52,7 +54,8 @@ function App() {
5254

5355
useEffect(() => {
5456
if (!ctx) return;
55-
const canvas = canvasRef.current;
57+
setCanvas(canvasRef.current);
58+
const canvas = currentCanvas;
5659
function handleMousemove(e) {
5760
// if eraseMode is set the position of the eraser cursor
5861
if (eraserMode) {

client/src/atoms.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,9 @@ export const cursorPosition = atom({
1313
export const canvasColors = atom({
1414
key: "canvasColor",
1515
default: "#D2B55B",
16-
});
16+
});
17+
18+
export const canvasState = atom({
19+
key: 'canvasState',
20+
default: ''
21+
})

client/src/components/Menu.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@ import Socials from "./Socials";
33
import SponsorBtn from "./SponsorBtn";
44

55
function Menu(){
6+
7+
function clickHandlerPdf(){
8+
9+
}
10+
611
return (
712
<div className="w-52 h-71 rounded-xl bg-gradient-to-r from-slate-900 to-slate-700 absolute left-52 top-8 rounded-lg shadow-xl">
813
<MenuItem feat="Start Collaboration"></MenuItem>
914
<MenuItem feat="Start Chat"></MenuItem>
10-
<MenuItem feat="Save as pdf"></MenuItem>
15+
<MenuItem feat="Save as pdf" onClick={clickHandlerPdf}></MenuItem>
1116
<MenuItem feat="Save as png"></MenuItem>
1217
<SponsorBtn></SponsorBtn>
1318
<Socials></Socials>

0 commit comments

Comments
 (0)