Skip to content

Commit d8a56d6

Browse files
committed
[FEAT]: 기능 업데이트
1 parent ba9438a commit d8a56d6

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

client/src/App.js

+48
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,40 @@ function App() {
2020
const [scale, setScale] = useState(
2121
Math.min(window.innerWidth / 1400, window.innerHeight / 900)
2222
);
23+
const [counterValue, setCounterValue] = useState(0);
2324

2425
useEffect(() => {
26+
fetchCounterValue();
2527
egg();
2628
}, []);
2729

30+
const fetchCounterValue = async () => {
31+
try {
32+
const response = await fetch("/counter");
33+
if (!response.ok) {
34+
throw new Error("Failed to fetch counter value");
35+
}
36+
const data = await response.json();
37+
setCounterValue(data.value);
38+
} catch (error) {
39+
console.error("Failed to fetch counter value:", error);
40+
}
41+
};
42+
43+
const increaseCounter = async (amount) => {
44+
try {
45+
const response = await fetch(`/counter?amount=${amount}`, {
46+
method: "POST",
47+
});
48+
if (!response.ok) {
49+
throw new Error("Failed to increase counter value");
50+
}
51+
setCounterValue((prevValue) => prevValue + amount);
52+
} catch (error) {
53+
console.error("Failed to increase counter value:", error);
54+
}
55+
};
56+
2857
const handleResize = () => {
2958
setScale(Math.min(window.innerWidth / 1400, window.innerHeight / 900));
3059
};
@@ -46,6 +75,25 @@ function App() {
4675

4776
return (
4877
<Provider store={store}>
78+
<div
79+
style={{
80+
margin: "0",
81+
fontSize: "20px",
82+
position: "absolute",
83+
left: "calc(100vw/2 - 150px)",
84+
top: "calc(100vh/2 - 100px)",
85+
display: "flex",
86+
justifyContent: "space-around",
87+
alignItems: "center",
88+
height: "70px",
89+
width: "300px",
90+
backgroundColor: "#f0f0f0",
91+
borderRadius: "10px",
92+
}}
93+
>
94+
<h1 style={{ position: "static" }}>Counter Value: {counterValue}</h1>
95+
<button onClick={() => increaseCounter(1)}>Increase by 1</button>
96+
</div>
4997
<div className="scale-wrapper" style={{ transform: `scale(${scale})` }}>
5098
<Draggable onDrag={(e, data) => trackPos(data)}>
5199
<div className="form no-drag">

client/src/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ root.render(
2828
`}</pre>
2929

3030
{/* <button onClick={localStore.insertDummy}style={{margin:"0", fontSize: "20px", position: "absolute", left: "calc(100vw/2)", top: "calc(100vh/2)"}}>makeDummy!</button> */}
31+
3132
<App />
3233
</div>
3334
);

0 commit comments

Comments
 (0)