Skip to content

Commit fffa665

Browse files
committed
format code
1 parent 0e7cc23 commit fffa665

File tree

1 file changed

+36
-21
lines changed

1 file changed

+36
-21
lines changed

client/src/App.jsx

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { useEffect, useRef } from "react";
22
import "./App.css";
3-
import {io} from 'socket.io-client';
3+
import { io } from "socket.io-client";
44

5-
const socket = io('http://localhost:8000');
5+
const socket = io("http://localhost:8000");
66

77
function App() {
88
const canvasRef = useRef(null);
99
const sidebarRef = useRef(null);
10-
let color = '#000000'
10+
let color = "#000000";
1111
let ctx;
1212
let canvas;
1313
let lineWidth;
@@ -18,7 +18,6 @@ function App() {
1818
let startX = 0;
1919
let startY = 0;
2020
ctx = canvas.getContext("2d");
21-
2221

2322
canvas.width = canvas.getBoundingClientRect().width;
2423
canvas.height = canvas.getBoundingClientRect().height;
@@ -37,16 +36,25 @@ function App() {
3736
const endX = e.clientX - canvas.getBoundingClientRect().left;
3837
const endY = e.clientY - canvas.getBoundingClientRect().top;
3938
drawLine(startX, startY, endX, endY);
40-
socket.emit('draw', {startX, startY, endX, endY, color, lineWidth})
39+
socket.emit("draw", { startX, startY, endX, endY, color, lineWidth });
4140
startX = endX;
4241
startY = endY;
4342
}
4443

45-
socket.on('draw', (data)=>{
46-
drawLine(data.startX, data.startY, data.endX, data.endY, data.color, data.lineWidth);
47-
})
48-
49-
socket.on('clear', ()=>{clearRect()})
44+
socket.on("draw", (data) => {
45+
drawLine(
46+
data.startX,
47+
data.startY,
48+
data.endX,
49+
data.endY,
50+
data.color,
51+
data.lineWidth
52+
);
53+
});
54+
55+
socket.on("clear", () => {
56+
clearRect();
57+
});
5058

5159
function handleMousedown(e) {
5260
isDrawing = true;
@@ -69,24 +77,23 @@ function App() {
6977
canvas.removeEventListener("mousemove", handleMousemove);
7078
canvas.removeEventListener("mousedown", handleMousedown);
7179
canvas.removeEventListener("mouseup", handleMouseup);
72-
socket.off('draw');
73-
socket.off('clear');
74-
80+
socket.off("draw");
81+
socket.off("clear");
7582
};
7683
}, []);
7784

78-
function clearRect(){
79-
ctx.clearRect(0, 0, canvas.width, canvas.height);
85+
function clearRect() {
86+
ctx.clearRect(0, 0, canvas.width, canvas.height);
8087
}
8188

82-
function addStroke(e){
83-
if(e.target.id === "stroke"){
89+
function addStroke(e) {
90+
if (e.target.id === "stroke") {
8491
color = e.target.value;
8592
ctx.strokeStyle = color;
8693
}
8794
}
8895

89-
function addLineWidth(e){
96+
function addLineWidth(e) {
9097
if (e.target.id === "lineWidth") {
9198
lineWidth = e.target.value;
9299
ctx.lineWidth = lineWidth;
@@ -99,7 +106,13 @@ function App() {
99106
<h1 id="drawRTC">drawRTC</h1>
100107
<div className="input-container" id="colorpicker">
101108
<label htmlFor="stroke">Stroke</label>
102-
<input id="stroke" name="stroke" type="color" defaultValue={color} onInput={addStroke}/>
109+
<input
110+
id="stroke"
111+
name="stroke"
112+
type="color"
113+
defaultValue={color}
114+
onInput={addStroke}
115+
/>
103116
</div>
104117
<div className="input-container" id="linewidth">
105118
<label htmlFor="lineWidth">Line Width</label>
@@ -108,10 +121,12 @@ function App() {
108121
name="lineWidth"
109122
type="number"
110123
defaultValue="3"
111-
onInput={addLineWidth}
124+
onInput={addLineWidth}
112125
/>
113126
</div>
114-
<button id="clear" onClick={()=>socket.emit('clear')}>Clear</button>
127+
<button id="clear" onClick={() => socket.emit("clear")}>
128+
Clear
129+
</button>
115130
</div>
116131
<div className="canvas-container">
117132
<canvas className="canvas" ref={canvasRef}></canvas>

0 commit comments

Comments
 (0)