Skip to content

Commit 9baaa67

Browse files
fix some bugs
1 parent 9641f48 commit 9baaa67

File tree

7 files changed

+43
-32
lines changed

7 files changed

+43
-32
lines changed
+5-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import '@cypress/react';
2-
import { REELS_NUMBER } from '@/game-configs';
32

43
describe('Slot machine', () => {
54
beforeEach(() => {
65
cy.visit('http://localhost:3000');
7-
cy.get('[data-cy="reels"] [data-cy="reel"]').as('reel');
6+
// cy.get('[data-cy="reels"] [data-cy="reel"]').as('reel');
87
});
98

10-
it('spins the symbols on the slots', () => {
9+
/* it('spins the symbols on the slots', () => {
1110
cy.get('@reel').should('have.length', REELS_NUMBER);
1211
cy.get('[data-cy="reels"] [data-cy="reel"]')
1312
.as('controllers')
@@ -17,11 +16,7 @@ describe('Slot machine', () => {
1716
1817
cy.get('[data-cy="reel"] [data-cy="symbol"]')
1918
.as('symbols')
20-
.then($el => {
21-
cy.get('[data-role="registered-tickets"] [data-role="ticket"]')
22-
/* .should('have.length', 1) */
23-
.eq(0)
24-
.should('have.class', 'symbol-spinning');
25-
});
26-
});
19+
.eq(0)
20+
.should('have.class', 'symbol--spinning');
21+
}); */
2722
});

src/App.tsx

-5
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ const App = () => {
6161
const addToast = (newToast: ToastData): void => setToastData(prevData => [...prevData, newToast]);
6262
const removeToast = (toastIndex: number): void =>
6363
setToastData(prevData => prevData.filter((_, index) => index !== toastIndex));
64-
// const toastListRef = useRef<HTMLDivElement>(null);
6564

6665
const [isLoading, setIsLoading] = useState<boolean>(true);
6766
const onLoadEnd = (): void => setIsLoading(false);
@@ -116,13 +115,9 @@ const App = () => {
116115
exit: styles['toast-exit'],
117116
exitActive: styles['toast-exit-active'],
118117
}}
119-
/* nodeRef={toastListRef} */
120118
>
121119
<Toast
122120
message={data.message}
123-
/* ref={el => {
124-
toastListRef?.current && (toastListRef.current[index] = el);
125-
}} */
126121
style={{ top: `${TOAST_OFFSET * index + 2}rem` }}
127122
type={data.type}
128123
onToastDismiss={() => removeToast(index)}

src/assets/svg/JavascriptSvg/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ interface SymbolSvgProps {
44
animate?: boolean;
55
}
66

7-
const JavascriptSvg: React.FC<SymbolSvgProps> = ({ animate = true }) => {
7+
const JavascriptSvg: React.FC<SymbolSvgProps> = ({ animate }) => {
88
return (
99
<svg
1010
aria-hidden={true}

src/components/game/Controllers/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ const Controllers: React.FC<ControllersProps> = ({ isSpinning, onSpin }) => {
100100
value={bet}
101101
min={1}
102102
max={credits}
103-
disabled={isSpinning}
103+
disabled={isSpinning || !credits}
104104
buttonsSound={isSoundOn ? coinsSound : null}
105105
onChange={handleCurrentBetChange}
106106
onIncreaseBet={handleBetIncrease}
@@ -109,7 +109,7 @@ const Controllers: React.FC<ControllersProps> = ({ isSpinning, onSpin }) => {
109109
<Button
110110
label={t('controllers.spin')}
111111
aria-label={t('controllers.spin')}
112-
disabled={isSpinning || !!winPayLines.length || !!losePayLines.length}
112+
disabled={isSpinning || !!winPayLines.length || !!losePayLines.length || !credits}
113113
additionalClass={styles['controllers__spin-button']}
114114
buttonSound={isSoundOn ? casinoPressSound : null}
115115
onClick={onSpin}

src/components/game/Reel/index.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ interface ReelProps {
1818

1919
const Reel: React.FC<ReelProps> = ({ symbols, reelIndex, animationDuration }) => {
2020
const areSlotsSpinning = useSelector((state: State) => state.slotMachine.isSpinning);
21-
const [isReelSpinning, setIsReelsSpinning] = useState<boolean>(false);
21+
const [isReelSpinning, setIsReelSpinning] = useState<boolean>(false);
2222
const reelRef = useRef<HTMLDivElement>(null);
2323
const reelSelector: gsap.utils.SelectorFunc = gsap.utils.selector(reelRef);
2424
const [spinAnimation, setSpinAnimation] = useState<gsap.core.Tween | null>(null);
@@ -31,7 +31,7 @@ const Reel: React.FC<ReelProps> = ({ symbols, reelIndex, animationDuration }) =>
3131
useContext<ReelsContextData>(ReelsContext);
3232

3333
const onSpinningAnimationEnd = useCallback(() => {
34-
setIsReelsSpinning(false);
34+
setIsReelSpinning(false);
3535
onReelAnimationEnd(reelIndex);
3636
if (reelIndex === REELS_NUMBER - 1) {
3737
onSpinningEnd();
@@ -42,7 +42,7 @@ const Reel: React.FC<ReelProps> = ({ symbols, reelIndex, animationDuration }) =>
4242
if (!areSlotsSpinning) {
4343
return;
4444
}
45-
setIsReelsSpinning(true);
45+
setIsReelSpinning(true);
4646
spinAnimation?.play();
4747
}, [areSlotsSpinning, spinAnimation]);
4848

src/components/game/ResetGame/index.tsx

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ChangeEvent, useContext, useState } from 'react';
2-
import { useDispatch } from 'react-redux';
2+
import { batch, useDispatch } from 'react-redux';
33
import { useTranslation } from 'react-i18next';
44
import { Button, Checkbox } from '@/components';
55
import { GAME_RESET, RESET_MODAL_DISMISSED } from '@/store/action-types';
@@ -16,9 +16,14 @@ const ResetGame: React.FC = () => {
1616
const handleConfirmDiscard = (): void => {
1717
dispatch({ type: GAME_RESET });
1818
if (doNotShowAgain) {
19-
dispatch({ type: RESET_MODAL_DISMISSED, payload: true });
19+
batch(() => {
20+
dispatch({ type: RESET_MODAL_DISMISSED, payload: true });
21+
dispatch({ type: GAME_RESET });
22+
});
23+
return closeModal();
2024
}
21-
closeModal();
25+
dispatch({ type: GAME_RESET });
26+
return closeModal();
2227
};
2328

2429
const handleDeclineReset = (): void => {
@@ -35,7 +40,7 @@ const ResetGame: React.FC = () => {
3540

3641
return (
3742
<div className={styles.reset}>
38-
<p>{modalProps?.hasNoCredits ? t('reset.resetGame') : t('reset.resetGame')}</p>
43+
<p>{modalProps?.hasNoCredits ? t('reset.resetGameNoCredits') : t('reset.resetGame')}</p>
3944
<div className={styles['reset__buttons']}>
4045
{!modalProps?.hasNoCredits && (
4146
<Button

src/components/game/SlotMachine/index.tsx

+23-7
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ const SlotMachine: React.FC = () => {
102102
[finalSlotScreen]
103103
);
104104

105+
const getTimerForNewSpin = (slotResult: SlotScreenResult): number => {
106+
const noResults = Object.entries(slotResult).every(
107+
([key, value]: [string, SlotScreenResult[keyof SlotScreenResult]]) =>
108+
!value || (Array.isArray(value) && !value.length)
109+
);
110+
111+
return noResults ? 100 : ANIMATE_RESULTS_DURATION;
112+
};
113+
105114
const onSpinningEnd = useCallback(() => {
106115
slotWheelSound.pause();
107116
let slotResult: SlotScreenResult = getScreenResult(finalSlotScreen);
@@ -121,20 +130,27 @@ const SlotMachine: React.FC = () => {
121130
}
122131
const action = { type: SPIN_ENDED, payload: slotResult };
123132
dispatch(action);
133+
const timeToNewSpin: number = getTimerForNewSpin(slotResult);
124134

125-
if (!credits) {
126-
openModal(ModalType.RESET, { hasNoCredits: true });
127-
return;
128-
}
135+
// shuffle reels for next spinning
136+
/* const shuffledReels = getShuffledReels();
137+
setReels(prevReels =>
138+
prevReels.map((reel, index) => [
139+
...reel.slice(0, ROW_NUMBER),
140+
...shuffledReels[index].slice(ROW_NUMBER),
141+
])
142+
); */
129143

130144
setTimeout(() => {
145+
const updatedCredits: number = credits + slotResult.winAmount;
146+
if (!updatedCredits) {
147+
openModal(ModalType.RESET, { hasNoCredits: true });
148+
}
131149
dispatch({ type: NEW_SPIN_PREPARED });
132-
// setFinalSlotScreens([]);
133-
// TODO remove added symbols from array and shuffle the non visible symbols
134150
if (isAutoSpinOn) {
135151
onSpin();
136152
}
137-
}, ANIMATE_RESULTS_DURATION);
153+
}, timeToNewSpin);
138154
}, [
139155
dispatch,
140156
isSoundOn,

0 commit comments

Comments
 (0)