Skip to content

Commit b91f10c

Browse files
committed
Add bidding table component
1 parent 169cd00 commit b91f10c

File tree

5 files changed

+62
-7
lines changed

5 files changed

+62
-7
lines changed

lib/moves/bid.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { SPECIAL_BIDS } from '../SpecialBids.js';
22

33
export const bid = function (G, ctx, bid) {
4+
console.log("bid", bid);
45
let contract = Object.assign({}, G.contract);
56
switch (bid.bid) {
67
case SPECIAL_BIDS.PASS:

userApp/imports/ui/components/Bidding/Bidding.js userApp/imports/ui/components/Bidding/BiddingBox.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { Button, Card, Image, Grid } from "semantic-ui-react";
22
import React, { useState } from "react";
33
import { getAllowedBids } from "/imports/lib/bidding.js";
4-
import { positionKey } from "/imports/lib/positions.js";
54
import _ from "lodash";
65
import { SUIT_SYMBOLS } from "/imports/lib/Suits";
76
import { SPECIAL_BIDS } from "/imports/lib/SpecialBids.js";
87

9-
export const Bidding = ({ G, ctx, makeBid, position }) => {
8+
export const BiddingBox = ({ G, ctx, makeBid, position }) => {
109
const bids = getAllowedBids({ bidding: G.bidding, position });
1110
const [selectedLevel, setSelectedLevel] = useState(null);
1211
const levels = _.chain(bids)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import React, { useState } from "react";
2+
import { Table, Card } from 'semantic-ui-react'
3+
import { SUIT_SYMBOLS } from "/imports/lib/Suits";
4+
import { _ } from 'lodash';
5+
import { POSITIONS } from '/imports/lib/positions.js';
6+
7+
export const BiddingTable = function ({ bidding, dealer }) {
8+
bidding.push({ position: dealer, bid: '?' });
9+
const rows = bidding.reduce((result, bid) => {
10+
const currentRow = _.last(result);
11+
if (currentRow.length === 4) {
12+
return [...result, [bid]]
13+
} else {
14+
currentRow.push(bid);
15+
return result;
16+
}
17+
}, [[]]);
18+
19+
const firstBidPosition = _.first(bidding).position;
20+
let header = _.keys(POSITIONS);
21+
let first = _.first(header);
22+
23+
while (first !== firstBidPosition) {
24+
header.unshift(header.pop());
25+
first = _.first(header);
26+
};
27+
return < Card >
28+
<Table fixed>
29+
<Table.Header>
30+
<Table.Row>
31+
{header.map(h => {
32+
return <Table.HeaderCell key={`header_${h}`}>{h}</Table.HeaderCell>
33+
})}
34+
</Table.Row>
35+
</Table.Header>
36+
<Table.Body>
37+
{rows.map((row, row_index) => {
38+
return <Table.Row key={`bidding_row_${row_index}`}>
39+
{row.map((bid, bid_index) => {
40+
return <Table.Cell key={`bid_cell_${bid_index}`}> <Bid bid={bid}> </Bid></Table.Cell>
41+
})}
42+
</Table.Row>
43+
})}
44+
</Table.Body>
45+
</Table>
46+
</Card >
47+
};
48+
49+
export const Bid = function ({ bid }) {
50+
return typeof (bid.suit) !== 'undefined' ? <div> {bid.level}{SUIT_SYMBOLS[bid.suit]}</div> : <div>{bid.bid}</div>;
51+
}
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
export * from "./Bidding.js";
1+
export * from "./BiddingBox.js";
2+
export * from "./BiddingTable.js";

userApp/imports/ui/components/Table/Table.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { BridgeDealFactory, TicTacToe } from "/imports/lib/bridge.js";
33
import { Local } from "boardgame.io/multiplayer";
44
import { useTracker } from "meteor/react-meteor-data";
55
import { Hand } from "../Hand";
6-
import { Bidding } from "../Bidding";
6+
import { BiddingBox, BiddingTable } from "../Bidding";
77
import React from "react";
88
import {
99
playerIdToPosition,
@@ -21,6 +21,7 @@ import { BOARD_STATES } from '/imports/constants/BoardStates.js';
2121
const BridgeTable = function ({ G, ctx, playerID, moves, events }) {
2222

2323
const playerPosition = playerIdToPosition(playerID);
24+
//for tests
2425
const isCurrenPlayerBidding =
2526
ctx.phase === PHASE_BIDDING && playerID === ctx.currentPlayer;
2627

@@ -52,7 +53,9 @@ const BridgeTable = function ({ G, ctx, playerID, moves, events }) {
5253
cardsHidden={true}
5354
/>
5455
</div>
55-
<div className="column"></div>
56+
<div className="column">
57+
<BiddingTable bidding={[...G.bidding]} dealer={G.dealer} />
58+
</div>
5659
<div className="column">
5760
<Hand
5861
ctx={ctx}
@@ -69,14 +72,14 @@ const BridgeTable = function ({ G, ctx, playerID, moves, events }) {
6972
<div className="column">
7073
<div>
7174
{isCurrenPlayerBidding ? (
72-
<Bidding
75+
<BiddingBox
7376
position={playerPosition}
7477
G={G}
7578
makeBid={function (bid) {
7679
moves.bid(bid);
7780
}}
7881
ctx={ctx}
79-
></Bidding>
82+
></BiddingBox>
8083
) : (
8184
""
8285
)}

0 commit comments

Comments
 (0)