source: components/GamesHistory.jsx@ faff334

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

Ability for admin to watch live games and for user to see games history

  • Property mode set to 100644
File size: 5.9 KB
Line 
1import React from 'react'
2
3import { useSelector, useDispatch } from 'react-redux'
4
5import { setStyle } from '../redux/reducers/styleSlice';
6import FreeflowCard from './FreeflowCard';
7import Calculations from './admin/Calculations';
8
9const GamesHistory = () => {
10 const dispatch = useDispatch();
11
12 const styleState = useSelector(state => state.style);
13
14 function hideGamesHistoryScreen() {
15 dispatch(setStyle({
16 ...styleState.style,
17 displayGamesHistoryScreen: false,
18 }))
19 }
20
21 if (styleState.style.displayGamesHistoryScreen) {
22 return (
23 <div className="fullscreen top-to-bottom-centered gamesHistoryScreen">
24 <div>
25 <p className="link" onClick={() => hideGamesHistoryScreen()}>⬅ Go Back</p>
26
27 <h3>These are all the games you&apos;ve played.</h3>
28
29 <div className="liveGamesMegaContainer">
30 <div className="liveBlackjackGames liveGamesContainer">
31 <h3>Blackjack Games:</h3>
32 { styleState.style.gamesHistory.blackjack?.rooms?.map((room, roomIdx) => (
33 <div key={room.id + roomIdx} className="liveBlackjackGame">
34 <div>
35 <div>
36 { room?.playerCards?.map((card, i) => (
37 <FreeflowCard key={`playercard${i}`} card={card}/>
38 ))}
39 <h5><Calculations action="calculateHandValue" cards={room.playerCards}/></h5>
40 </div>
41 <p>Player {room.displayName} (${parseInt(room.initialBet) + parseInt(room.sideBet)})</p>
42 </div>
43 <div>
44 <div>
45 <h6><span>Outcome:</span><br/>{room.outcome}</h6>
46 <h6><span>Side Bet Outcome:</span><br/>{room.sideBetOutcome}</h6>
47 </div>
48 </div>
49 <div>
50 <div>
51 <h5><Calculations action="calculateHandValue" cards={room.dealerCards}/></h5>
52 { room?.dealerCards?.map((card, i) => (
53 <FreeflowCard key={`dealercard${i}`} card={card}/>
54 ))}
55 </div>
56 <p>Dealer {room.dealerName}</p>
57 </div>
58 </div>
59 )) }
60 </div>
61
62 <div className="liveRouletteGame liveGamesContainer">
63 <h3>Roulette Games:</h3>
64 { styleState.style.gamesHistory.roulette?.games?.map((game, gameIdx) => (
65 <div key={`roulettegame${gameIdx}`}>
66 <h6>
67 <span>Ball on number: </span>{game?.magicNumber}&nbsp;&nbsp;&nbsp;&nbsp;
68 <span>Winning bets: </span>{game?.winningBets?.join(", ")}
69 </h6>
70 <h6 style={{marginTop: '2rem'}}><span>Players:</span></h6>
71 { game?.players?.map((player, i) => (
72 <div key={player.session_id} className="playerInLiveRouletteGame">
73 <div>
74 <h6><span>Player {i+1} -&gt;</span></h6>
75 </div>
76 <div>
77 <h6><span>{player.name} (${player.betAmount})</span></h6>
78 </div>
79 <div>
80 <h6><span>Betted on: </span>{player.whichBets.join(", ")}</h6>
81 </div>
82 <div>
83 <h6><span>Outcome: {player.outcome}</span></h6>
84 </div>
85 </div>
86 )) }
87 </div>
88 )) }
89 </div>
90
91 <div className="livePokerGames liveGamesContainer">
92 <h3>Poker Games:</h3>
93 { styleState.style.gamesHistory.poker?.tables?.map(table => (
94 <div key={table.id} className="livePokerGame">
95 <h6>
96 <span>Pot: </span>{table?.pot}&nbsp;&nbsp;&nbsp;&nbsp;
97 <span>Winners: </span>{table?.winners?.map(e=>e.displayName)?.join(", ")}
98 </h6>
99 <div className="cardsOnTable" style={{marginTop: '2rem'}}>
100 { table?.cards?.map((card, i) => (
101 <FreeflowCard key={`tablecard${i}`} card={card}/>
102 ))}
103 </div>
104 <h6 style={{marginTop: '2rem'}}><span>Players:</span></h6>
105 {table.players?.map(player => (
106 <div key={player.id} className="playerInLivePokerGame">
107 <div>
108 <h6><span>Player {player.displayName} (${player.betAmount})</span></h6>
109 </div>
110 <div className="cards">
111 { player?.cards?.map((card, i) => (
112 <FreeflowCard key={`playercard${i}`} card={card}/>
113 ))}
114 </div>
115 <div>
116 <h6><span>Hand: </span><Calculations action="getBestHandDetails" cards={player.cards} cards2={table.cards}/></h6>
117 </div>
118 </div>
119 ))}
120 </div>
121 )) }
122 </div>
123 </div>
124 </div>
125 </div>
126 )}
127 else {
128 return <></>
129 }
130}
131
132export default GamesHistory
Note: See TracBrowser for help on using the repository browser.