Skip to content

Commit 6a37932

Browse files
committed
format app.jsx
1 parent cd88832 commit 6a37932

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

client/src/App.jsx

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ import { useRecoilValue, useRecoilState } from "recoil";
1313
import { eraserState, cursorPosition } from "./atoms";
1414

1515
function App() {
16-
17-
const [showMenu, setShowMenu ] = useState(false);
16+
const [showMenu, setShowMenu] = useState(false);
1817
const eraserMode = useRecoilValue(eraserState);
1918
const [position, setPosition] = useRecoilState(cursorPosition);
2019
const [ctx, setCtx] = useState(null);
@@ -23,14 +22,14 @@ function App() {
2322
const [isDrawing, setIsDrawing] = useState(false);
2423
const [penColor, setPenColor] = useState("#000000");
2524

26-
function toggleMenu(){
25+
function toggleMenu() {
2726
setShowMenu(!showMenu);
2827
}
2928

3029
const canvasRef = useRef(null);
3130
const sidebarRef = useRef(null);
3231
let lineWidth;
33-
32+
3433
function drawLine(sx, sy, ex, ey, penColor, lineWidth) {
3534
ctx.moveTo(sx, sy);
3635
ctx.lineTo(ex, ey);
@@ -39,10 +38,10 @@ function App() {
3938
ctx.strokeStyle = penColor;
4039
ctx.stroke();
4140
}
42-
41+
4342
useEffect(() => {
4443
const canvas = canvasRef.current;
45-
if(canvas){
44+
if (canvas) {
4645
const context = canvas.getContext("2d");
4746
canvas.width = canvas.getBoundingClientRect().width;
4847
canvas.height = canvas.getBoundingClientRect().height;
@@ -51,7 +50,7 @@ function App() {
5150
}, [canvasRef.current]);
5251

5352
useEffect(() => {
54-
if(!ctx) return;
53+
if (!ctx) return;
5554
const canvas = canvasRef.current;
5655
function handleMousemove(e) {
5756
// if eraseMode is set the position of the eraser cursor
@@ -66,7 +65,6 @@ function App() {
6665
socket.emit("draw", { startX, startY, endX, endY, penColor, lineWidth });
6766
setStartX(endX);
6867
setStartY(endY);
69-
7068
}
7169

7270
function handleMousedown(e) {
@@ -105,43 +103,42 @@ function App() {
105103
data.lineWidth
106104
);
107105
});
108-
106+
109107
socket.on("clear", () => {
110108
clearRect();
111109
});
112-
113-
return () => {
114-
socket.off("draw");
115-
socket.off("clear");
116-
}
110+
111+
return () => {
112+
socket.off("draw");
113+
socket.off("clear");
114+
};
117115
}, [socket, ctx]);
118116

119117
function clearRect() {
120-
if(ctx){
118+
if (ctx) {
121119
ctx.clearRect(0, 0, canvasRef.current.width, canvasRef.current.height);
122120
}
123121
}
124122

125-
function clearOnClick(){
123+
function clearOnClick() {
126124
clearRect();
127-
socket.emit('clear')
125+
socket.emit("clear");
128126
}
129127

130128
function addStroke(e) {
131129
if (e.target.id === "penColor") {
132130
const newColor = e.target.value;
133131
setPenColor(newColor);
134-
if(ctx){
132+
if (ctx) {
135133
ctx.strokeStyle = newColor;
136134
}
137-
138135
}
139136
}
140137

141138
function addLineWidth(e) {
142139
if (e.target.id === "lineWidth") {
143140
lineWidth = e.target.value;
144-
if(ctx){
141+
if (ctx) {
145142
ctx.lineWidth = lineWidth;
146143
}
147144
}
@@ -164,5 +161,4 @@ function App() {
164161
);
165162
}
166163

167-
export default App;
168-
164+
export default App;

0 commit comments

Comments
 (0)