Skip to content

Commit e8d1c0a

Browse files
authored
Merge pull request #202 from daithihearn/go-migration-2
Go migration 2
2 parents 4405a59 + 4997dd1 commit e8d1c0a

34 files changed

+14110
-249
lines changed

.github/workflows/publish-to-dockerhub.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- uses: actions/checkout@v3
2323
- uses: actions/setup-node@v3
2424
with:
25-
node-version: 16
25+
node-version: 20
2626
- name: Get version in manifest.json
2727
id: manifest-version
2828
uses: notiz-dev/github-action-json-property@release

.github/workflows/unit-tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ jobs:
1616
- name: Set up Node.js
1717
uses: actions/setup-node@v2
1818
with:
19-
node-version: "16.19.x"
19+
node-version: "20.11.x"
2020
- name: Install dependencies
2121
run: yarn install --frozen-lockfile
2222
- name: Test and coverage
23-
run: yarn jest --coverage
23+
run: yarn test:coverage
2424
- name: Sonar Args
2525
id: sonar-args
2626
run: |

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ node_modules/
1010
.settings/
1111
*.bat
1212
yarn-error.log
13-
yarn.lock
1413
prod.env
1514

1615
# testing

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v18.18.0
1+
v20.11.0

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# build
2-
FROM node:18.18 AS builder
2+
FROM node:20.11 AS builder
33

44
WORKDIR /app
55

junit.xml

Lines changed: 209 additions & 0 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "frontend",
3-
"version": "8.0.0",
3+
"version": "8.0.1",
44
"description": "React frontend for the Cards 110",
55
"author": "Daithi Hearn",
66
"license": "MIT",
@@ -13,26 +13,26 @@
1313
"@coreui/react": "4.11.1",
1414
"@emotion/react": "11.11.3",
1515
"@emotion/styled": "11.11.0",
16-
"@mui/icons-material": "5.15.4",
17-
"@mui/material": "5.15.4",
18-
"@mui/x-data-grid": "6.18.7",
16+
"@mui/icons-material": "5.15.6",
17+
"@mui/material": "5.15.6",
18+
"@mui/x-data-grid": "6.19.2",
1919
"@popperjs/core": "2.11.8",
20-
"@reduxjs/toolkit": "2.0.1",
20+
"@reduxjs/toolkit": "2.1.0",
2121
"@tanstack/react-query": "^5.17.19",
2222
"@types/jest": "29.5.11",
23-
"@types/node": "20.10.8",
24-
"@types/react": "18.2.47",
23+
"@types/node": "20.11.10",
24+
"@types/react": "18.2.48",
2525
"@types/react-avatar-editor": "13",
2626
"@types/react-dom": "18.2.18",
2727
"@types/react-router-dom": "5.3.3",
28-
"axios": "1.6.5",
28+
"axios": "1.6.7",
2929
"bootstrap": "5.3.2",
3030
"chart.js": "4.4.1",
31-
"core-js": "3.35.0",
31+
"core-js": "3.35.1",
3232
"crypto-js": "4.2.0",
3333
"font-awesome": "4.7.0",
3434
"heic2any": "0.0.4",
35-
"jwt-decode": "3.1.2",
35+
"jwt-decode": "3",
3636
"moment": "2.30.1",
3737
"notistack": "3.0.1",
3838
"react": "18.2.0",
@@ -41,11 +41,10 @@
4141
"react-chartjs-2": "5",
4242
"react-confetti": "6.1.0",
4343
"react-dom": "18.2.0",
44-
"react-redux": "9.0.4",
45-
"react-router": "6.21.1",
44+
"react-redux": "9.1.0",
45+
"react-router": "6.21.3",
4646
"react-router-config": "5.1.1",
47-
"react-router-dom": "6.21.1",
48-
"react-stomp-hooks": "2.2.1",
47+
"react-router-dom": "6.21.3",
4948
"react-viewer": "3.2.2",
5049
"semantic-ui-css": "2.5.0",
5150
"simple-line-icons": "2.5.5",
@@ -55,8 +54,8 @@
5554
},
5655
"devDependencies": {
5756
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
58-
"@tanstack/eslint-plugin-query": "^5.17.20",
59-
"@types/crypto-js": "4.2.1",
57+
"@tanstack/eslint-plugin-query": "^5.17.22",
58+
"@types/crypto-js": "4.2.2",
6059
"@types/enzyme": "3.10.18",
6160
"@types/enzyme-adapter-react-16": "1.0.9",
6261
"@types/react-beautiful-dnd": "13.1.8",
@@ -66,16 +65,17 @@
6665
"jest-junit": "^16.0.0",
6766
"node-sass-chokidar": "2.0.0",
6867
"npm-run-all": "4.1.5",
69-
"prettier": "3.1.1",
68+
"prettier": "3.2.4",
7069
"react-scripts": "5.0.1",
71-
"ts-jest": "^29.1.1"
70+
"ts-jest": "^29.1.2"
7271
},
7372
"scripts": {
7473
"build-css": "node-sass-chokidar --include-path ./node_modules ./src/scss -o ./src/scss",
7574
"watch-css": "npm run build-css && node-sass-chokidar --include-path ./node_modules ./src/scss -o ./src/scss --watch --recursive",
7675
"start": "react-scripts start",
7776
"build": "react-scripts build",
7877
"test": "react-scripts test --env=jsdom",
78+
"test:coverage": "react-scripts test --env=jsdom --coverage --watchAll=false",
7979
"eject": "react-scripts eject",
8080
"format": "yarn prettier --write src",
8181
"format:check": "yarn prettier --check src"

public/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"short_name": "Cards 110",
33
"name": "Cards 110",
4-
"version": "8.0.0",
4+
"version": "8.0.1",
55
"icons": [
66
{
77
"src": "./assets/favicon.png",

src/caches/GameSlice.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { RootState } from "./caches"
66
import { processOrderedCardsAfterGameUpdate } from "utils/GameUtils"
77
import { Card, EMPTY } from "model/Cards"
88
import { determineEvent } from "utils/EventUtils"
9+
import { Event } from "model/Events"
910

1011
export const initialGameState: GameState = {
1112
revision: -1,
@@ -18,6 +19,7 @@ export const initialGameState: GameState = {
1819
cardsFull: [],
1920
status: GameStatus.NONE,
2021
players: [],
22+
event: Event.Unknown,
2123
}
2224

2325
export const gameSlice = createSlice({
@@ -31,12 +33,9 @@ export const gameSlice = createSlice({
3133
state.cardsFull,
3234
action.payload.cards,
3335
),
36+
event: determineEvent(state, action.payload),
3437
}
3538

36-
const event = determineEvent(state, updatedGame)
37-
38-
console.log("event", event)
39-
4039
return updatedGame
4140
},
4241
selectCard: (state, action: PayloadAction<Card>) => {
@@ -179,3 +178,4 @@ export const getIsInBunker = createSelector(
179178
)
180179

181180
export const getRevision = createSelector(getGame, game => game.revision)
181+
export const getEvent = createSelector(getGame, game => game.event)

src/components/Game/Actions/Buying.tsx

Lines changed: 12 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,119 +1,43 @@
1-
import { useCallback, useEffect, useState } from "react"
1+
import { useCallback, useState } from "react"
22

3-
import { useAppDispatch, useAppSelector } from "caches/hooks"
3+
import { useAppSelector } from "caches/hooks"
44
import {
55
getGameId,
6-
getNumPlayers,
7-
getIamGoer,
8-
getIHavePlayed,
96
getIsMyGo,
10-
getSuit,
11-
getCardsWithoutBlanks,
127
getSelectedCards,
13-
selectAll,
8+
getSuit,
149
} from "caches/GameSlice"
15-
import { pickBestCards, riskOfMistakeBuyingCards } from "utils/GameUtils"
1610
import ThrowCardsWarningModal from "./ThrowCardsWarningModal"
17-
import { Card, CardName } from "model/Cards"
1811
import { Button } from "@mui/material"
19-
import { useSettings } from "components/Hooks/useSettings"
2012
import { useGameActions } from "components/Hooks/useGameActions"
2113

22-
const WaitingForRoundToStart = () => (
23-
<Button variant="contained" disableRipple color="primary">
24-
<b>Waiting for round to start...</b>
25-
</Button>
26-
)
27-
2814
const Buying = () => {
29-
const dispatch = useAppDispatch()
3015
const { buyCards } = useGameActions()
31-
const { settings } = useSettings()
3216

33-
const numPlayers = useAppSelector(getNumPlayers)
3417
const gameId = useAppSelector(getGameId)
3518
const suit = useAppSelector(getSuit)
36-
const myCards = useAppSelector(getCardsWithoutBlanks)
37-
const [readyToBuy, setReadyToBuy] = useState(false)
38-
const iHavePlayed = useAppSelector(getIHavePlayed)
3919
const isMyGo = useAppSelector(getIsMyGo)
40-
const iamGoer = useAppSelector(getIamGoer)
4120

4221
const [deleteCardsDialog, setDeleteCardsDialog] = useState(false)
4322

4423
const selectedCards = useAppSelector(getSelectedCards)
4524

46-
const toggleReadyToBuy = useCallback(() => {
47-
setReadyToBuy(!readyToBuy)
48-
}, [readyToBuy])
49-
50-
const buyCardsWrapper = useCallback(
51-
(sel: CardName[] | Card[]) => {
52-
if (!gameId) return
53-
buyCards({
54-
gameId,
55-
cards: sel.map(c => (typeof c === "string" ? c : c.name)),
56-
})
57-
},
58-
[gameId],
59-
)
25+
const buyCardsWrapper = useCallback(() => {
26+
if (!gameId) return
27+
buyCards({
28+
gameId,
29+
cards: selectedCards.map(c => (typeof c === "string" ? c : c.name)),
30+
})
31+
}, [gameId, selectedCards])
6032

6133
const hideCancelDeleteCardsDialog = useCallback(() => {
6234
setDeleteCardsDialog(false)
63-
setReadyToBuy(false)
6435
}, [])
6536

66-
useEffect(() => {
67-
if (iamGoer) {
68-
dispatch(selectAll())
69-
setReadyToBuy(true)
70-
}
71-
}, [iamGoer])
72-
73-
useEffect(() => {
74-
// 1. If it is not my go then do nothing
75-
if (!isMyGo || !suit || !gameId) return
76-
// 2. If I am the goer and it is my go then keep all cards
77-
else if (iamGoer) {
78-
buyCards({ gameId, cards: myCards.map(c => c.name) })
79-
}
80-
// 3. If I am not the goer and it is my go and I have enabled auto buy cards then keep best cards
81-
else if (!iamGoer && settings?.autoBuyCards) {
82-
buyCards({
83-
gameId,
84-
cards: pickBestCards(myCards, suit, numPlayers).map(
85-
c => c.name,
86-
),
87-
})
88-
}
89-
// 4. If I am not the goer and it is my go and I am ready to buy then keep selected cards
90-
else if (!iamGoer && readyToBuy) {
91-
if (riskOfMistakeBuyingCards(suit, selectedCards, myCards)) {
92-
setDeleteCardsDialog(true)
93-
} else buyCardsWrapper(selectedCards)
94-
}
95-
}, [
96-
settings,
97-
gameId,
98-
iamGoer,
99-
suit,
100-
selectedCards,
101-
myCards,
102-
isMyGo,
103-
numPlayers,
104-
readyToBuy,
105-
])
106-
107-
if (iHavePlayed || settings?.autoBuyCards || iamGoer)
108-
return <WaitingForRoundToStart />
10937
return (
11038
<>
111-
<Button type="button" onClick={toggleReadyToBuy} color="primary">
112-
<b>
113-
{isMyGo || !readyToBuy
114-
? "Keep Cards"
115-
: "Waiting to buy cards..."}
116-
</b>
39+
<Button type="button" onClick={buyCardsWrapper} color="primary">
40+
<b>{isMyGo ? "Keep Cards" : "Waiting to buy cards..."}</b>
11741
</Button>
11842

11943
{suit && (

0 commit comments

Comments
 (0)