source: components/poker/sections/PlayButtons.jsx@ 433e0c5

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

Fixes to poker functionality

  • Property mode set to 100644
File size: 2.7 KB
Line 
1import React from 'react'
2
3import { useSelector, useDispatch } from 'react-redux'
4
5import axios from 'axios';
6import { setPoker } from '../../../redux/reducers/styleSlice';
7
8const 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
69export default PlayButtons
Note: See TracBrowser for help on using the repository browser.