@@ -9,6 +9,7 @@ import { useState, useEffect } from "react";
9
9
import { Provider } from "react-redux" ;
10
10
import store from "./redux/store" ;
11
11
import Draggable from "react-draggable" ;
12
+ import _debounce from "lodash/debounce" ;
12
13
13
14
function App ( ) {
14
15
const [ section , setSection ] = useState ( "1" ) ;
@@ -17,6 +18,7 @@ function App() {
17
18
const [ position , setPosition ] = useState ( { x : 0 , y : 0 } ) ;
18
19
const [ daynight , setdaynight ] = useState ( 1 ) ;
19
20
const [ finishTrigger , setFinishTrigger ] = useState ( - 1 ) ;
21
+ const [ amountIncrease , setAmountIncrease ] = useState ( 0 ) ; // 클릭 수
20
22
const [ scale , setScale ] = useState (
21
23
Math . min ( window . innerWidth / 1400 , window . innerHeight / 900 )
22
24
) ;
@@ -39,21 +41,23 @@ function App() {
39
41
console . error ( "Failed to fetch counter value:" , error ) ;
40
42
}
41
43
} ;
42
-
43
- const increaseCounter = async ( amount ) => {
44
+ const increaseCounter = async ( ) => {
44
45
try {
45
- const response = await fetch ( `/counter?amount=${ amount } ` , {
46
+ const response = await fetch ( `/counter?amount=${ amountIncrease } ` , {
46
47
method : "POST" ,
47
48
} ) ;
48
49
if ( ! response . ok ) {
49
50
throw new Error ( "Failed to increase counter value" ) ;
50
51
}
51
- setCounterValue ( ( prevValue ) => prevValue + amount ) ;
52
+ setCounterValue ( ( prevValue ) => prevValue + amountIncrease ) ;
53
+ setAmountIncrease ( 0 ) ;
52
54
} catch ( error ) {
53
55
console . error ( "Failed to increase counter value:" , error ) ;
54
56
}
55
57
} ;
56
58
59
+ const increaseCounterDebounced = _debounce ( increaseCounter , 1000 ) ; // 1000ms 디바운스 지연
60
+
57
61
const handleResize = ( ) => {
58
62
setScale ( Math . min ( window . innerWidth / 1400 , window . innerHeight / 900 ) ) ;
59
63
} ;
@@ -70,7 +74,7 @@ function App() {
70
74
} ;
71
75
72
76
function easteregg ( ) {
73
- alert ( "안녕하세요! " ) ;
77
+ alert ( "Remove the window " ) ;
74
78
}
75
79
76
80
return (
@@ -85,14 +89,32 @@ function App() {
85
89
display : "flex" ,
86
90
justifyContent : "space-around" ,
87
91
alignItems : "center" ,
88
- height : "70px " ,
92
+ height : "100px " ,
89
93
width : "300px" ,
90
- backgroundColor : "#f0f0f0 " ,
94
+ backgroundColor : "var(--topbar-background-color) " ,
91
95
borderRadius : "10px" ,
96
+ transition : "background-color 0.3s" ,
97
+ flexDirection : "column" ,
92
98
} }
93
99
>
94
- < h1 style = { { position : "static" } } > Counter Value: { counterValue } </ h1 >
95
- < button onClick = { ( ) => increaseCounter ( 1 ) } > Increase by 1</ button >
100
+ < h1 style = { { position : "static" } } >
101
+ Number of clicks: { counterValue . toLocaleString ( "ko-KR" ) }
102
+ </ h1 >
103
+ < button
104
+ onClick = { ( ) => {
105
+ setAmountIncrease ( ( prevAmount ) => prevAmount + 1 ) ;
106
+ increaseCounterDebounced ( ) ;
107
+ } }
108
+ className = "sidebarsection-list"
109
+ style = { {
110
+ width : "120px" ,
111
+ height : "40px" ,
112
+ border : "0.8px solid darkgray" ,
113
+ borderRadius : "10px" ,
114
+ } }
115
+ >
116
+ Can you press it?
117
+ </ button >
96
118
</ div >
97
119
< div className = "scale-wrapper" style = { { transform : `scale(${ scale } )` } } >
98
120
< Draggable onDrag = { ( e , data ) => trackPos ( data ) } >
0 commit comments