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