From f63d3c8959e652b128cbbe233296a7bee2863fb6 Mon Sep 17 00:00:00 2001 From: Daithi Hearn Date: Sun, 21 May 2023 11:55:11 +0200 Subject: [PATCH 1/4] Filtering out players that haven't played in 3 months --- package.json | 2 +- public/manifest.json | 2 +- src/components/StartNewGame/StartNewGame.tsx | 18 +++++++++++++----- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 423a647..bfdc0bc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "frontend", - "version": "7.0.6", + "version": "7.0.7", "description": "React frontend for the Cards 110", "author": "Daithi Hearn", "license": "MIT", diff --git a/public/manifest.json b/public/manifest.json index 65a779c..8c52d3c 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -1,7 +1,7 @@ { "short_name": "Cards 110", "name": "Cards 110", - "version": "7.0.6", + "version": "7.0.7", "icons": [ { "src": "./assets/favicon.png", diff --git a/src/components/StartNewGame/StartNewGame.tsx b/src/components/StartNewGame/StartNewGame.tsx index 8df0d26..27bb629 100644 --- a/src/components/StartNewGame/StartNewGame.tsx +++ b/src/components/StartNewGame/StartNewGame.tsx @@ -43,11 +43,19 @@ const StartNewGame = () => { const orderedPlayers = useMemo(() => { if (!allPlayers || allPlayers.length < 1) return [] // Sort by last lastAccess which is a string timestamp in the form 1970-01-01T00:00:00 - return [...allPlayers].sort((a, b) => { - const aDate = new Date(a.lastAccess) - const bDate = new Date(b.lastAccess) - return bDate.getTime() - aDate.getTime() - }) + return [...allPlayers] + .filter(p => { + // Filter out players that have not played in the last 3 months + const lastAccess = new Date(p.lastAccess) + const threeMonthsAgo = new Date() + threeMonthsAgo.setMonth(threeMonthsAgo.getMonth() - 3) + return lastAccess.getTime() > threeMonthsAgo.getTime() + }) + .sort((a, b) => { + const aDate = new Date(a.lastAccess) + const bDate = new Date(b.lastAccess) + return bDate.getTime() - aDate.getTime() + }) }, [allPlayers]) const togglePlayer = useCallback( From 6768fa2f7778d9f7ae25814aea325f2c99f1c3e8 Mon Sep 17 00:00:00 2001 From: Daithi Hearn Date: Sun, 21 May 2023 12:00:29 +0200 Subject: [PATCH 2/4] Adding name back in --- src/components/StartNewGame/StartNewGame.tsx | 35 ++++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/src/components/StartNewGame/StartNewGame.tsx b/src/components/StartNewGame/StartNewGame.tsx index 27bb629..997e7f7 100644 --- a/src/components/StartNewGame/StartNewGame.tsx +++ b/src/components/StartNewGame/StartNewGame.tsx @@ -88,7 +88,7 @@ const StartNewGame = () => { } const payload = { - players: selectedPlayers.map(p => p.id!), + players: selectedPlayers.map(p => p.id), name: newGameName, } @@ -189,11 +189,34 @@ const StartNewGame = () => { }}>
- Image Preview + + + Image Preview + + + {FormatName( + player.name, + )} + +
From 552671adbac74d58f97ae3e8d0263b4a5395bb4a Mon Sep 17 00:00:00 2001 From: Daithi Hearn Date: Sun, 21 May 2023 12:24:13 +0200 Subject: [PATCH 3/4] Auto select trump cards --- src/caches/MyCardsSlice.ts | 6 ++++++ src/components/Game/MyCards.tsx | 36 +++++++++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/caches/MyCardsSlice.ts b/src/caches/MyCardsSlice.ts index 716a410..c80a80f 100644 --- a/src/caches/MyCardsSlice.ts +++ b/src/caches/MyCardsSlice.ts @@ -32,6 +32,11 @@ export const myCardsSlice = createSlice({ const idx = state.cards.findIndex(c => c.name === action.payload) if (idx > 0) state.cards[idx] = { ...BLANK_CARD, selected: false } }, + selectCard: (state, action: PayloadAction) => { + state.cards.forEach(c => { + if (c.name === action.payload.name) c.selected = true + }) + }, toggleSelect: (state, action: PayloadAction) => state.cards.forEach(c => { if (c.name === action.payload.name) c.selected = !c.selected @@ -61,6 +66,7 @@ export const { removeCard, clearSelectedCards, selectAll, + selectCard, toggleSelect, toggleUniqueSelect, clearMyCards, diff --git a/src/components/Game/MyCards.tsx b/src/components/Game/MyCards.tsx index c91a658..553ea9a 100644 --- a/src/components/Game/MyCards.tsx +++ b/src/components/Game/MyCards.tsx @@ -1,4 +1,4 @@ -import React, { useCallback, useMemo } from "react" +import React, { useCallback, useEffect, useMemo, useRef } from "react" import { DragDropContext, Draggable, @@ -13,6 +13,7 @@ import { clearSelectedCards, getMyCards, replaceMyCards, + selectCard, toggleSelect, toggleUniqueSelect, } from "caches/MyCardsSlice" @@ -21,7 +22,8 @@ import { toggleAutoPlay, clearAutoPlay, } from "caches/AutoPlaySlice" -import { CardContent, CardMedia, useTheme } from "@mui/material" +import { Card, CardContent, CardMedia, useTheme } from "@mui/material" +import { CARDS } from "model/Cards" const EMPTY_HAND = [ { ...BLANK_CARD, selected: false }, @@ -31,6 +33,14 @@ const EMPTY_HAND = [ { ...BLANK_CARD, selected: false }, ] +const usePrevious = (value: any) => { + const ref = useRef() + useEffect(() => { + ref.current = value + }) + return ref.current +} + const MyCards: React.FC = () => { const theme = useTheme() const dispatch = useAppDispatch() @@ -39,6 +49,28 @@ const MyCards: React.FC = () => { const myCards = useAppSelector(getMyCards) const autoPlayCard = useAppSelector(getAutoPlayCard) const iamGoer = useAppSelector(getIamGoer) + const prevRoundStatus = usePrevious(round?.status) + + useEffect(() => { + if ( + round?.status === RoundStatus.BUYING && + prevRoundStatus !== RoundStatus.BUYING && + !iamGoer && + round.suit + ) { + // Auto select all cards of a specific suit when the round status is BUYING + + const cardsOfSuit = myCards.filter( + card => + card.suit === round.suit || + card.name === "JOKER" || + card.name === "ACE_HEARTS", + ) + cardsOfSuit.forEach(card => { + dispatch(selectCard(card)) + }) + } + }, [round, myCards, prevRoundStatus, iamGoer]) const cardsSelectable = useMemo( () => From 5d06680c10c87a6ca3391f5202820fbcb2ea16f4 Mon Sep 17 00:00:00 2001 From: Daithi Hearn Date: Sun, 21 May 2023 12:24:49 +0200 Subject: [PATCH 4/4] Auto select trump cards --- src/components/Game/MyCards.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/Game/MyCards.tsx b/src/components/Game/MyCards.tsx index 553ea9a..437f490 100644 --- a/src/components/Game/MyCards.tsx +++ b/src/components/Game/MyCards.tsx @@ -22,8 +22,7 @@ import { toggleAutoPlay, clearAutoPlay, } from "caches/AutoPlaySlice" -import { Card, CardContent, CardMedia, useTheme } from "@mui/material" -import { CARDS } from "model/Cards" +import { CardContent, CardMedia, useTheme } from "@mui/material" const EMPTY_HAND = [ { ...BLANK_CARD, selected: false },