1 | import React from 'react'
|
---|
2 |
|
---|
3 | import { useSelector, useDispatch } from 'react-redux'
|
---|
4 |
|
---|
5 | import axios from 'axios';
|
---|
6 | import { setPoker } from '../../../redux/reducers/styleSlice';
|
---|
7 |
|
---|
8 | const PlayButtons = () => {
|
---|
9 | const dispatch = useDispatch();
|
---|
10 |
|
---|
11 | const playerState = useSelector(state => state.player);
|
---|
12 | const styleState = useSelector(state => state.style);
|
---|
13 |
|
---|
14 | function sitDown() {
|
---|
15 | axios.get(`/api/poker?action=sit_down&session_id=${localStorage.CAESSINO_SESSION_ID}&tableId=${playerState.pokerGame.player.table}`);
|
---|
16 | }
|
---|
17 |
|
---|
18 | function startGame() {
|
---|
19 | axios.get(`/api/poker?action=start_game&session_id=${localStorage.CAESSINO_SESSION_ID}`);
|
---|
20 | }
|
---|
21 |
|
---|
22 | const checkClass = playerState.pokerGame.table.lastBet === 0 ? 'secondaryButton' : 'tertiaryButton';
|
---|
23 | const callClass = playerState.pokerGame.table.lastBet > 0 ? 'secondaryButton' : 'tertiaryButton'
|
---|
24 | const raiseClass = playerState.pokerGame.table.round >= 2 ? 'secondaryButton' : 'tertiaryButton';
|
---|
25 | const foldClass = 'secondaryButton';
|
---|
26 |
|
---|
27 | function check() {
|
---|
28 | axios.get(`/api/poker?action=game_action&session_id=${localStorage.CAESSINO_SESSION_ID}&specificAction=check&betAmount=0`);
|
---|
29 | }
|
---|
30 |
|
---|
31 | function call() {
|
---|
32 | axios.get(`/api/poker?action=game_action&session_id=${localStorage.CAESSINO_SESSION_ID}&specificAction=call&betAmount=0`);
|
---|
33 | }
|
---|
34 |
|
---|
35 | function raise() {
|
---|
36 | dispatch(setPoker({
|
---|
37 | ...styleState.poker,
|
---|
38 | displays: {
|
---|
39 | ...styleState.poker.displays,
|
---|
40 | raiseModal: true,
|
---|
41 | },
|
---|
42 | }))
|
---|
43 | }
|
---|
44 |
|
---|
45 | function fold() {
|
---|
46 | axios.get(`/api/poker?action=game_action&session_id=${localStorage.CAESSINO_SESSION_ID}&specificAction=fold&betAmount=0`);
|
---|
47 | }
|
---|
48 |
|
---|
49 | if (playerState.pokerGame.table.started && playerState.pokerGame.player.isSatDown && parseInt(playerState.pokerGame.table.round) < 5) {
|
---|
50 | return (
|
---|
51 | <div className="pokerPlayButtonsContainer">
|
---|
52 | <button className={checkClass} onClick={() => check()}>Check</button>
|
---|
53 | <button className={callClass} onClick={() => call()}>Call</button>
|
---|
54 | <button className={raiseClass} onClick={() => raise()}>Raise</button>
|
---|
55 | <button className={foldClass} onClick={() => fold()}>Fold</button>
|
---|
56 | </div>
|
---|
57 | )
|
---|
58 | }
|
---|
59 | else {
|
---|
60 | return (
|
---|
61 | <div className="pokerPlayButtonsContainer">
|
---|
62 | {!playerState.pokerGame.table.started && !playerState.pokerGame.table.ended && playerState.pokerGame.player.isCoordinator && playerState.pokerGame.player.isSatDown && <button className="secondaryButton" onClick={() => startGame()}>Start game</button>}
|
---|
63 | {!playerState.pokerGame.table.started && !playerState.pokerGame.player.isSatDown && <button className="secondaryButton" onClick={() => sitDown()}>Take a seat</button>}
|
---|
64 | </div>
|
---|
65 | )
|
---|
66 | }
|
---|
67 | }
|
---|
68 |
|
---|
69 | export default PlayButtons |
---|