source: components/roulette/RouletteHeader.jsx@ 189cd8f

main
Last change on this file since 189cd8f was ace7865, checked in by anastasovv <simon@…>, 2 years ago

Finished Roulette

  • Property mode set to 100644
File size: 2.8 KB
Line 
1import React from 'react'
2
3import Link from 'next/link'
4
5import { useRouter } from 'next/router'
6
7import { AiOutlineArrowLeft } from 'react-icons/ai'
8
9import { useEffect } from 'react'
10import { useDispatch, useSelector } from 'react-redux'
11
12import { setRouletteGame, setPlayer } from '../../redux/reducers/playerSlice'
13import { setRoulette, setStyle } from '../../redux/reducers/styleSlice'
14
15import axios from 'axios';
16
17const RouletteHeader = () => {
18 const dispatch = useDispatch();
19
20 const router = useRouter();
21
22 const playerState = useSelector(state => state.player);
23 const styleState = useSelector(state => state.style);
24
25 useEffect(() => {
26 // display loading screen
27 dispatch(setStyle({
28 ...styleState.style,
29 displayLoadingScreen: true,
30 }));
31
32 axios.get(`/api/roulette?action=get_player_info_on_enter&session_id=${localStorage.CAESSINO_SESSION_ID}`).then(res => {
33 if (res.data?.success) {
34 dispatch(setPlayer({
35 ...playerState.player,
36 displayName: res.data?.displayName,
37 session_id: res.data?.session_id,
38 credits: res.data?.credits,
39 }));
40
41 dispatch(setRouletteGame(res.data?.game));
42
43 dispatch(setRoulette({
44 ...styleState.roulette,
45 inputControls: {
46 ...styleState.roulette.inputControls,
47 bet: {
48 ...styleState.roulette.inputControls.bet,
49 chosenCredits: parseInt(res.data?.credits/2),
50 }
51 },
52 showCoin: false,
53 }));
54
55 dispatch(setStyle({
56 ...styleState.style,
57 displayLoadingScreen: false,
58 }))
59 }
60 else {
61 dispatch(setStyle({
62 ...styleState.style,
63 notification: {
64 show: true,
65 text: 'Please login in order to play roulette.',
66 status: 'error',
67 },
68 displayLoadingScreen: false,
69 }))
70
71 router.push('/');
72 }
73 });
74 }, []);
75
76 return (
77 <header className="header">
78 <Link href="/" passHref>
79 <h2>
80 <AiOutlineArrowLeft />
81 </h2>
82 </Link>
83 <nav>
84 <ul>
85 <li>Hi, {playerState?.player?.displayName}</li>
86 <li>Balance: ${playerState?.player?.credits}</li>
87 </ul>
88 </nav>
89 </header>
90 )
91}
92
93export default RouletteHeader
Note: See TracBrowser for help on using the repository browser.