source: components/roulette/Timer.jsx@ 1df3fde

main
Last change on this file since 1df3fde was d0ef259, checked in by anastasovv <simon@…>, 2 years ago

Roulette rethought with 1 second update calls

  • Property mode set to 100644
File size: 1.8 KB
Line 
1import React from 'react'
2
3import { useEffect } from 'react';
4import { useDispatch, useSelector } from 'react-redux'
5import { setPlayer, setRouletteGame } from '../../redux/reducers/playerSlice';
6
7import axios from 'axios';
8import { setRoulette, setStyle } from '../../redux/reducers/styleSlice';
9
10const Timer = () => {
11 const dispatch = useDispatch();
12
13 const playerState = useSelector(state => state.player);
14 const styleState = useSelector(state => state.style);
15
16 function getTimer() {
17 const timer = playerState.rouletteGame.game.timeToStart;
18
19 const timeString = (timer < 0 || timer > playerState.rouletteGame.game.COUNTDOWN_FROM - 2) ? '00:00' : '0' + parseInt(timer/60) + ':' + (timer%60 < 10 ? '0' : '') + (timer%60);
20
21 return timeString;
22 }
23
24 return (
25 <div className="rouletteTimer">
26 {playerState.rouletteGame.game.timeToStart > 0 && playerState.rouletteGame.game.timeToStart <= playerState.rouletteGame.game.COUNTDOWN_FROM - 2 && <span style={{fontSize: '1rem'}}>Wheel will spin in:</span>}
27
28 <span>{getTimer()}</span>
29
30 {playerState.rouletteGame.game.timeToStart > 10 && playerState.rouletteGame.game.timeToStart <= playerState.rouletteGame.game.COUNTDOWN_FROM - 2 && <span style={{fontSize: '1rem'}}>Make your bets.</span>}
31
32 {playerState.rouletteGame.game.timeToStart <= 10 && <span style={{fontSize: '1rem'}}>Betting time is over.</span>}
33
34 {playerState.rouletteGame.game.timeToStart > playerState.rouletteGame.game.COUNTDOWN_FROM && <span style={{fontSize: '1rem'}}>Time to see who won :)</span>}
35 {playerState.rouletteGame.game.timeToStart > playerState.rouletteGame.game.COUNTDOWN_FROM && <span style={{fontSize: '.7rem'}}>(And prepare, you can bet again soon.)</span>}
36 </div>
37 )
38}
39
40export default Timer
Note: See TracBrowser for help on using the repository browser.