Skip to content

Commit eb6c547

Browse files
authored
Merge pull request #36 from apsinghdev/Feat/implement-SaveAs-feature
Feat/implement save as feature
2 parents ca53c15 + d9b389f commit eb6c547

File tree

7 files changed

+253
-15
lines changed

7 files changed

+253
-15
lines changed

client/package-lock.json

Lines changed: 200 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"preview": "vite preview"
1111
},
1212
"dependencies": {
13+
"jspdf": "^2.5.1",
1314
"react": "^18.2.0",
1415
"react-dom": "^18.2.0",
1516
"react-icons": "^5.2.0",

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) {

0 commit comments

Comments
 (0)