Changeset 3a783f2 for components
- Timestamp:
- 07/05/22 16:36:24 (2 years ago)
- Branches:
- main
- Children:
- 189cd8f
- Parents:
- b13f93b
- Location:
- components
- Files:
-
- 3 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
components/poker/PokerHeader.jsx
rb13f93b r3a783f2 23 23 const styleState = useSelector(state => state.style); 24 24 25 useEffect(() => async function(){25 useEffect(() => { 26 26 // display loading screen 27 27 dispatch(setStyle({ … … 30 30 })); 31 31 32 let interval = setInterval(() => { 33 axios.get(`/api/poker?action=update_state&session_id=${localStorage.CAESSINO_SESSION_ID}`).then(res => { 34 if (res.data?.success) { 35 dispatch(setPokerGame(res.data?.pokerGame)) 36 } 37 }); 38 }, 3000); 32 let interval; 39 33 40 34 axios.get(`/api/poker?action=get_player_info_on_enter&session_id=${localStorage.CAESSINO_SESSION_ID}`).then(res => { … … 51 45 displayLoadingScreen: false, 52 46 })) 47 48 interval = setInterval(() => { 49 axios.get(`/api/poker?action=update_state&session_id=${localStorage.CAESSINO_SESSION_ID}`).then(newRes => { 50 if (newRes.data?.success) { 51 dispatch(setPokerGame(newRes.data?.pokerGame)) 52 53 if (newRes.data?.pokerGame?.player?.credits !== playerState.player.credits && newRes.data?.pokerGame?.player?.credits > 0) { 54 dispatch(setPlayer({ 55 ...playerState.player, 56 credits: newRes.data?.pokerGame?.player?.credits, 57 })) 58 } 59 } 60 }); 61 }, 2000); 53 62 } 54 63 else { … … 66 75 } 67 76 }); 68 69 return () => clearInterval(interval); 70 }, [playerState.pokerGame.player.table]) 77 }, []) 78 79 function leaveTable() { 80 axios.get(`/api/poker?action=leave_table&session_id=${localStorage.CAESSINO_SESSION_ID}`); 81 } 71 82 72 83 return ( 73 84 <header className="header"> 74 <Link href="/" passHref> 75 <h2> 76 <AiOutlineArrowLeft /> 77 </h2> 78 </Link> 85 <div style={{display: 'flex', alignItems: 'center'}}> 86 <Link href="/" passHref> 87 <h2> 88 <AiOutlineArrowLeft /> 89 </h2> 90 </Link> 91 { playerState.pokerGame.player.table.length > 0 && <button style={{marginBottom: '4px', marginLeft: '32px', fontSize: '16px'}} className="tertiaryButton" onClick={() => leaveTable()}>Leave Table</button> } 92 </div> 79 93 <nav> 80 94 <ul> -
components/poker/PokerSections.jsx
rb13f93b r3a783f2 9 9 10 10 import { useSelector, useDispatch } from 'react-redux' 11 import Pot from './sections/Pot' 12 import RaiseModal from './sections/RaiseModal' 11 13 12 14 const PokerSections = () => { … … 24 26 <CardsInTheMiddle/> 25 27 28 <Pot/> 29 26 30 <PlayButtons/> 31 32 <RaiseModal/> 27 33 </> 28 34 ) -
components/poker/sections/Messages.jsx
rb13f93b r3a783f2 17 17 turnMessage = `It\'s ${playerState.pokerGame.table.players[playerState.pokerGame.table.turnIdx].displayName}\'s turn.`; 18 18 19 if (p layerState.pokerGame.table.lastBet> 0) {20 callMessage = `${playerState.pokerGame.table.players[playerState.pokerGame.table.turnIdx].displayName} must at least call $${ playerState.pokerGame.table.lastBet}`;19 if (parseInt(playerState.pokerGame.table.lastBet) > 0) { 20 callMessage = `${playerState.pokerGame.table.players[playerState.pokerGame.table.turnIdx].displayName} must at least call $${Math.min(playerState.player.credits, playerState.pokerGame.table.lastBet)}`; 21 21 } 22 22 } … … 24 24 return ( 25 25 <div className="pokerMessagesContainer"> 26 { playerState.pokerGame.table.started && <p>Round {playerState.pokerGame.table.round}/5{roundMessage}</p> } 26 { playerState.pokerGame.table.started && playerState.pokerGame.table.ended && playerState.pokerGame.table.winners.length === 1 && <p>Game over - {playerState.pokerGame.table.winners[0]?.displayName} won ${playerState.pokerGame.table.winners[0]?.wonAmount} with a {playerState.pokerGame.table.winners[0]?.hand?.hand} combination! Congratulations.</p> } 27 { playerState.pokerGame.table.started && playerState.pokerGame.table.ended && playerState.pokerGame.table.winners.length > 1 && <p>Game over - {playerState.pokerGame.table.winners.map(e=>e.displayName).join(", ")} drew!</p> } 28 { playerState.pokerGame.table.started && playerState.pokerGame.table.ended && <p>New game will start soon.</p> } 29 30 { playerState.pokerGame.table.started && !playerState.pokerGame.table.ended && <p>Round {playerState.pokerGame.table.round}/4{roundMessage}</p> } 27 31 { !playerState.pokerGame.table.started && <p>Waiting for coordinator {playerState.pokerGame.table.creator} to start the game.</p> } 28 { playerState.pokerGame.table.started && <p>{turnMessage}</p> }29 { playerState.pokerGame.table.started && <p>{callMessage}</p> }32 { playerState.pokerGame.table.started && !playerState.pokerGame.table.ended && <p>{turnMessage}</p> } 33 { playerState.pokerGame.table.started && !playerState.pokerGame.table.ended && <p>{callMessage}</p> } 30 34 </div> 31 35 ) -
components/poker/sections/PlayButtons.jsx
rb13f93b r3a783f2 4 4 5 5 import axios from 'axios'; 6 import { setPoker Game } from '../../../redux/reducers/playerSlice';6 import { setPoker } from '../../../redux/reducers/styleSlice'; 7 7 8 8 const PlayButtons = () => { … … 10 10 11 11 const playerState = useSelector(state => state.player); 12 const styleState = useSelector(state => state.style); 12 13 13 14 function sitDown() { … … 20 21 21 22 const checkClass = playerState.pokerGame.table.lastBet === 0 ? 'secondaryButton' : 'tertiaryButton'; 22 const callClass = 'secondaryButton'23 const callClass = playerState.pokerGame.table.lastBet > 0 ? 'secondaryButton' : 'tertiaryButton' 23 24 const raiseClass = playerState.pokerGame.table.round >= 2 ? 'secondaryButton' : 'tertiaryButton'; 24 25 const foldClass = 'secondaryButton'; … … 33 34 34 35 function raise() { 35 axios.get(`/api/poker?action=game_action&session_id=${localStorage.CAESSINO_SESSION_ID}&specificAction=raise&betAmount=0`); 36 dispatch(setPoker({ 37 ...styleState.poker, 38 displays: { 39 ...styleState.poker.displays, 40 raiseModal: true, 41 }, 42 })) 36 43 } 37 44 … … 40 47 } 41 48 42 if (playerState.pokerGame.table.started && playerState.pokerGame.player.isSatDown ) {49 if (playerState.pokerGame.table.started && playerState.pokerGame.player.isSatDown && parseInt(playerState.pokerGame.table.round) < 5) { 43 50 return ( 44 51 <div className="pokerPlayButtonsContainer"> -
components/roulette/Sections.jsx
rb13f93b r3a783f2 1 1 import React from 'react' 2 import Ball from './Ball'; 2 3 3 4 import BetModal from './BetModal'; … … 19 20 <img id="rouletteWheelImg" src="/images/roulette-wheel.png" alt="Roulette wheel" style={{transform: 'translate(-50%, -50%)'}}/> 20 21 22 <Ball/> 23 21 24 <PlayersDisplay/> 22 25
Note:
See TracChangeset
for help on using the changeset viewer.