Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions client/src/components/game/GameStateInfo.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useContext } from 'react';
import React, { useState, useEffect, useContext } from 'react';
import styled from 'styled-components';
import contentContext from '../../context/content/contentContext';
import ChipsAmountPill from './ChipsAmountPill';
Expand All @@ -17,16 +17,29 @@ const Wrapper = styled.div`
export const GameStateInfo = ({ currentTable }) => {
const { getLocalizedString } = useContext(contentContext);

const [roundName, setRound] = useState('');

useEffect(() => {
if (!currentTable.board) {
setRound('Pre-Flop')
} else if (currentTable.board.length === 0) {
setRound('Pre-Flop')
} else if (currentTable.board.length === 3) {
setRound('Flop')
} else if (currentTable.board.length === 4) {
setRound('Turn')
} else if (currentTable.board.length === 5) {
setRound('River')
}
}, [currentTable]);

return (
<Wrapper>
{currentTable.players.length <= 1 || currentTable.handOver ? (
<InfoPill>{getLocalizedString('game_state-info_wait')}</InfoPill>
) : (
<InfoPill>
{currentTable.board.length === 0 && 'Pre-Flop'}
{currentTable.board.length === 3 && 'Flop'}
{currentTable.board.length === 4 && 'Turn'}
{currentTable.board.length === 5 && 'River'}
{roundName}
{currentTable.wentToShowdown && 'Showdown'}
</InfoPill>
)}
Expand All @@ -38,7 +51,7 @@ export const GameStateInfo = ({ currentTable }) => {
/>
)}

{currentTable.sidePots > 0 &&
{currentTable.sidePots &&
currentTable.sidePots.map((sidePot) => (
<ChipsAmountPill
chipsAmount={sidePot.amount}
Expand Down
118 changes: 44 additions & 74 deletions client/src/components/game/Seat.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useContext, useEffect } from 'react';
import React, { useContext, useState, useEffect } from 'react';
import Button from '../buttons/Button';
import modalContext from '../../context/modal/modalContext';
import globalContext from '../../context/global/globalContext';
Expand Down Expand Up @@ -32,6 +32,46 @@ export const Seat = ({ currentTable, seatNumber, isPlayerSeated, sitDown }) => {
const maxBuyin = currentTable.limit;
const minBuyIn = currentTable.minBet * 2 * 10;

const buyinSubmit = (e, isRebuy) => {
e.preventDefault();
const amount = +document.getElementById('amount').value;
if (amount &&
amount >= minBuyIn &&
amount <= chipsAmount &&
amount <= maxBuyin
) {
if (!isRebuy) {
sitDown(currentTable.id, seatNumber, parseInt(amount));
} else {
rebuy(currentTable.id, seatNumber, parseInt(amount));
}
closeModal();
}
};

const buyinView = (isRebuy = false) => (
<Form onSubmit={(e) => (buyinSubmit(e, isRebuy))}>
<FormGroup>
<Input
id="amount"
type="number"
min={minBuyIn}
max={chipsAmount <= maxBuyin ? chipsAmount : maxBuyin}
defaultValue={minBuyIn}
/>
</FormGroup>
<ButtonGroup>
<Button primary type="submit" fullWidth>
{!isRebuy ? (
getLocalizedString('game_buyin-modal_confirm')
) : (
getLocalizedString('game_rebuy-modal_confirm')
)}
</Button>
</ButtonGroup>
</Form>
);

useEffect(() => {
if (
currentTable &&
Expand All @@ -45,40 +85,7 @@ export const Seat = ({ currentTable, seatNumber, isPlayerSeated, sitDown }) => {
standUp();
} else {
openModal(
() => (
<Form
onSubmit={(e) => {
e.preventDefault();

const amount = +document.getElementById('amount').value;

if (
amount &&
amount >= minBuyIn &&
amount <= chipsAmount &&
amount <= maxBuyin
) {
rebuy(currentTable.id, seatNumber, parseInt(amount));
closeModal();
}
}}
>
<FormGroup>
<Input
id="amount"
type="number"
min={minBuyIn}
max={chipsAmount <= maxBuyin ? chipsAmount : maxBuyin}
defaultValue={minBuyIn}
/>
</FormGroup>
<ButtonGroup>
<Button primary type="submit" fullWidth>
{getLocalizedString('game_rebuy-modal_confirm')}
</Button>
</ButtonGroup>
</Form>
),
() => (buyinView(true)),
getLocalizedString('game_rebuy-modal_header'),
getLocalizedString('game_rebuy-modal_cancel'),
() => {
Expand All @@ -104,44 +111,7 @@ export const Seat = ({ currentTable, seatNumber, isPlayerSeated, sitDown }) => {
small
onClick={() => {
openModal(
() => (
<Form
onSubmit={(e) => {
e.preventDefault();

const amount = +document.getElementById('amount').value;

if (
amount &&
amount >= minBuyIn &&
amount <= chipsAmount &&
amount <= maxBuyin
) {
sitDown(
currentTable.id,
seatNumber,
parseInt(amount),
);
closeModal();
}
}}
>
<FormGroup>
<Input
id="amount"
type="number"
min={minBuyIn}
max={chipsAmount <= maxBuyin ? chipsAmount : maxBuyin}
defaultValue={minBuyIn}
/>
</FormGroup>
<ButtonGroup>
<Button primary type="submit" fullWidth>
{getLocalizedString('game_buyin-modal_confirm')}
</Button>
</ButtonGroup>
</Form>
),
() => (buyinView(false)),
getLocalizedString('game_buyin-modal_header'),
getLocalizedString('game_buyin-modal_cancel'),
);
Expand All @@ -167,7 +137,7 @@ export const Seat = ({ currentTable, seatNumber, isPlayerSeated, sitDown }) => {
<PositionedUISlot top="-6.25rem" left="-75px" origin="top center">
<NameTag>
<ColoredText primary textAlign="center">
{seat.player.name}
{seat.player?.name}
<br />
{seat.stack && (
<ColoredText secondary>
Expand Down
2 changes: 1 addition & 1 deletion client/src/pages/Play.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const Play = ({ history }) => {
getLocalizedString('game_lost-connection-modal_btn-txt'),
() => history.push('/'),
);
socket && joinTable(1);
socket && joinTable('1');
return () => leaveTable();
// eslint-disable-next-line
}, [socket]);
Expand Down
4 changes: 2 additions & 2 deletions server/public/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ function Game({ setConnected }) {

socket.emit(FETCH_LOBBY_INFO, user);

socket.emit(JOIN_TABLE, 1);
socket.emit(JOIN_TABLE, '1');

return () => {
cleanUp();
Expand Down Expand Up @@ -166,7 +166,7 @@ function Game({ setConnected }) {
};

const joinTable = () => {
socket.emit(JOIN_TABLE, 1);
socket.emit(JOIN_TABLE, '1');
};

const fold = () => {
Expand Down
2 changes: 1 addition & 1 deletion server/socket/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const {
const config = require('../config');

const tables = {
1: new Table(1, 'Table 1', 10000),
'1': new Table('1', 'Table 1', 10000),
};
const players = {};

Expand Down