Skip to content

Commit

Permalink
Merge pull request #318 from maxmarinich/resize-event
Browse files Browse the repository at this point in the history
fix api reset
  • Loading branch information
maxmarinich authored Apr 6, 2024
2 parents 455a813 + a1b1214 commit cd4b0c0
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/components/pages/sandbox/roulette/Roulette.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import AliceCarousel from '../../../../lib/react-alice-carousel';
import { shuffleArray, genItems, genRandomInt } from './Roulette.utils';
import type { Props, Item } from './Roulette.types';

let timeoutId: null | NodeJS.Timeout = null;

const responsive = {
0: { items: 1 },
640: { items: 3 },
Expand All @@ -33,7 +35,7 @@ function getOffset(itemsOnScreen: number) {

function loadWinner() {
return new Promise<{ id: number }>((resolve) => {
setTimeout(() => resolve({ id: genRandomInt() }), 2_000);
timeoutId = setTimeout(() => resolve({ id: genRandomInt() }), 2_000);
});
}

Expand Down Expand Up @@ -125,9 +127,12 @@ export default function SandboxPage(props: Partial<Props>) {
<button
className="text"
onClick={() => {
if (timeoutId) clearTimeout(timeoutId);
setKey(key + 1);
setWinner(null);
setActive(itemsPadding);
setWinnerId(null);
setSetIsWinnerLoading(false);
setIsWinnerHighlighted(false);
setIsRouletteAnimationProcess(false);
}}
Expand Down

0 comments on commit cd4b0c0

Please sign in to comment.