@@ -69,6 +69,7 @@ const Gacha = () => {
6969 const [ itemName , setItemName ] = useState ( null )
7070 const [ theResultsPageOfTheGacha , setTheResultsPageOfTheGacha ] = useState ( false )
7171 const [ coinsTextIfTheyAlreadyWonThatItem , setCoinsTextIfTheyAlreadyWonThatItem ] = useState ( null )
72+ const [ isRolling , setIsRolling ] = useState ( false )
7273
7374 const navigate = useNavigate ( )
7475
@@ -91,6 +92,10 @@ const Gacha = () => {
9192 } , [ URI , userId ] )
9293
9394 const handleRoll = async ( ) => {
95+ if ( isRolling ) return
96+
97+ setIsRolling ( true )
98+
9499 setTheResultsPageOfTheGacha ( false )
95100 setCoinsTextIfTheyAlreadyWonThatItem ( null )
96101
@@ -112,7 +117,6 @@ const Gacha = () => {
112117 setItemWon ( randomItem )
113118 setItemName ( nameOfTheRandomItem )
114119 setStars ( whichStar )
115- console . log ( "item won" , randomItem )
116120
117121 //one star = 50, two stars = 75, three = 100 four == 300
118122 try {
@@ -124,14 +128,10 @@ const Gacha = () => {
124128 } )
125129 setUsersCharacterList ( characterData . data . characterList )
126130 setUsersInventory ( inventoryData . data . inventory )
127- console . log ( characterData . data . characterList )
128- console . log ( inventoryData . data . inventory )
129131 }
130132 catch ( e ) {
131133 console . error ( "failed to fetch the player's inventory" )
132134 }
133-
134- console . log ( "item won" , randomItem )
135135
136136 if ( usersCharacterList . includes ( randomItem ) || usersInventory . includes ( randomItem ) ) {
137137 switch ( whichStar ) {
@@ -154,14 +154,10 @@ const Gacha = () => {
154154 default :
155155 setCoinsTextIfTheyAlreadyWonThatItem ( null )
156156 }
157- console . log ( "users coins because they already had the item" , coinsIfTheyAlreadyWonThatItem )
158157 }
159- console . log ( "item won" , randomItem )
160158
161159 if ( coinsTextIfTheyAlreadyWonThatItem === null && whichStar === fourStar ) {
162- console . log ( "it was a character" , randomItem )
163160 const characterEnumKey = lookUpItemFromTheEnums ( CharacterEnum , randomItem )
164- console . log ( characterEnumKey )
165161 if ( characterEnumKey !== undefined ) {
166162 try {
167163 const response = await axios . put ( `${ URI } users/addCharacter/${ userId } ` , {
@@ -178,9 +174,7 @@ const Gacha = () => {
178174 }
179175 }
180176 else if ( coinsTextIfTheyAlreadyWonThatItem === null && ( whichStar === threeStar || whichStar === twoStar ) ) {
181- console . log ( "it was a item" , randomItem )
182177 let itemEnumKey = lookUpItemFromTheEnums ( HatsEnum , randomItem ) ?? lookUpItemFromTheEnums ( WeaponsEnum , randomItem ) ;
183- console . log ( itemEnumKey )
184178 if ( itemEnumKey !== undefined ) {
185179 try {
186180 const response = await axios . put ( `${ URI } users/addItem/${ userId } ` , {
@@ -197,7 +191,6 @@ const Gacha = () => {
197191 }
198192 }
199193 else if ( whichStar === oneStar ) {
200- console . log ( "it was just coins" , randomItem )
201194 try {
202195 const response = await axios . put ( `${ URI } users/updateCoins/${ userId } ` , {
203196 coins : 50
@@ -212,7 +205,6 @@ const Gacha = () => {
212205 }
213206 }
214207 else {
215- console . log ( "it was just coins" , randomItem )
216208 try {
217209 const response = await axios . put ( `${ URI } users/updateCoins/${ userId } ` , {
218210 coins : 50
@@ -240,6 +232,9 @@ const Gacha = () => {
240232 catch ( e ) {
241233 console . error ( "error buying lootbox" , e )
242234 }
235+ finally {
236+ setTimeout ( ( ) => setIsRolling ( false ) , 2000 )
237+ }
243238 }
244239 }
245240
@@ -295,7 +290,7 @@ const Gacha = () => {
295290 < h1 > <</ h1 >
296291 </ button >
297292 </ div > ) : null }
298- { alertForInsufficientFunds && ( < Alert text = { "Insufficient Funds!" } buttonOneText = { "Ok" } functionButtonOne = { ( ) => { setAlertForInsufficientFunds ( false ) } } /> ) }
293+ { alertForInsufficientFunds && ( < Alert text = { "Insufficient Funds!" } buttonOneText = { "Ok" } functionButtonOne = { ( ) => { setAlertForInsufficientFunds ( false ) } } show = { true } /> ) }
299294 < div className = "stuff-in-gacha" >
300295 { theResultsPageOfTheGacha ? (
301296 < >
@@ -309,7 +304,7 @@ const Gacha = () => {
309304 < h1 > { itemName } { coinsTextIfTheyAlreadyWonThatItem !== null ? `:${ coinsTextIfTheyAlreadyWonThatItem } ` : "" } </ h1 >
310305 </ div >
311306 < div className = "button-for-gacha" >
312- < button onClick = { handleRoll } > Buy Again? : 100 coins</ button >
307+ < button onClick = { handleRoll } disabled = { isRolling } > Buy Again? : 100 coins</ button >
313308 </ div >
314309 </ >
315310 ) : (
@@ -331,7 +326,7 @@ const Gacha = () => {
331326 < h1 > Your coins: { usersCoins } </ h1 >
332327 </ div >
333328 < div className = "button-for-gacha" >
334- < button onClick = { handleRoll } > Buy: 100 coins</ button >
329+ < button onClick = { handleRoll } disabled = { isRolling } > Buy: 100 coins</ button >
335330 </ div >
336331 </ >
337332 ) }
0 commit comments