diff --git a/src/caches/GameSlice.ts b/src/caches/GameSlice.ts index 73c516a..15d96ba 100644 --- a/src/caches/GameSlice.ts +++ b/src/caches/GameSlice.ts @@ -93,8 +93,6 @@ export const getIsDoublesGame = createSelector( export const getIsMyGo = createSelector(getGame, game => game.isMyGo) export const getIamGoer = createSelector(getGame, game => game.iamGoer) export const getIHavePlayed = createSelector(getGame, game => { - if (game.iamGoer) return false - const myPosition = game.players.findIndex(p => p.id === game.me?.id) const currentPlayerPosition = game.players.findIndex( p => p.id === game.round?.currentHand.currentPlayerId, diff --git a/src/components/Game/Buying.tsx b/src/components/Game/Buying.tsx index 3a0decf..8782b2a 100644 --- a/src/components/Game/Buying.tsx +++ b/src/components/Game/Buying.tsx @@ -78,7 +78,7 @@ const Buying = () => { type="button" onClick={toggleReadyToBuy} color={ - isMyGo || !readyToBuy ? "warning" : "secondary" + isMyGo || !readyToBuy ? "primary" : "secondary" }> {isMyGo || !readyToBuy diff --git a/src/components/Game/MyCards.tsx b/src/components/Game/MyCards.tsx index ec0c8aa..28e7e78 100644 --- a/src/components/Game/MyCards.tsx +++ b/src/components/Game/MyCards.tsx @@ -34,11 +34,6 @@ import { } from "../../caches/AutoPlaySlice" import parseError from "../../utils/ErrorUtils" -interface DoubleClickTracker { - time: number - card: string -} - const MyCards: React.FC = () => { const dispatch = useAppDispatch() const gameId = useAppSelector(getGameId) @@ -51,9 +46,6 @@ const MyCards: React.FC = () => { const { enqueueSnackbar } = useSnackbar() - const [doubleClickTracker, updateDoubleClickTracker] = - useState() - const selectedCards = useAppSelector(getSelectedCards) const playButtonEnabled = useMemo( @@ -85,7 +77,10 @@ const MyCards: React.FC = () => { ) const handleSelectCard = useCallback( - (card: SelectableCard) => { + ( + card: SelectableCard, + event: React.MouseEvent, + ) => { if (!cardsSelectable || card.name === BLANK_CARD.name) { return } @@ -95,24 +90,17 @@ const MyCards: React.FC = () => { if (autoPlayCard === card.name) { dispatch(clearAutoPlay()) dispatch(clearSelectedCards()) - } else if ( - doubleClickTracker?.card === card.name && - Date.now() - doubleClickTracker.time < 500 - ) { + } else if (event.detail === 2) { dispatch(toggleAutoPlay(card)) } else { dispatch(toggleUniqueSelect(card)) dispatch(clearAutoPlay()) - updateDoubleClickTracker({ - card: card.name, - time: Date.now(), - }) } } else { dispatch(toggleSelect(card)) } }, - [round, myCards, autoPlayCard, doubleClickTracker], + [round, myCards, autoPlayCard], ) const handleOnDragEnd = useCallback( @@ -209,9 +197,10 @@ const MyCards: React.FC = () => { {...provided.dragHandleProps}> + onClick={event => handleSelectCard( card, + event, ) } src={`/cards/thumbnails/${card.name}.png`} @@ -263,9 +252,10 @@ const MyCards: React.FC = () => { {...provided.dragHandleProps}> + onClick={event => handleSelectCard( card, + event, ) } src={`/cards/thumbnails/${card.name}.png`} @@ -294,7 +284,7 @@ const MyCards: React.FC = () => { disabled={!playButtonEnabled} type="button" onClick={playCard} - color="warning"> + color="primary"> Play Card diff --git a/src/components/Game/WebsocketManager.tsx b/src/components/Game/WebsocketManager.tsx index bd553ef..c7c51ee 100644 --- a/src/components/Game/WebsocketManager.tsx +++ b/src/components/Game/WebsocketManager.tsx @@ -124,23 +124,32 @@ const WebsocketHandler = () => { // On round completion we need to display the last round to the user const processRoundCompleted = async ( game: GameState, - previousRound: Round, + previousRound?: Round, ) => { // Disable actions by setting isMyGo to false dispatch(disableActions()) - // Show the last card of the penultimate round being played - playCardSound() - const penultimateHand = previousRound.completedHands.pop() - if (!penultimateHand) throw Error("Failed to get the penultimate round") - dispatch(updatePlayedCards(penultimateHand.playedCards)) - await new Promise(r => setTimeout(r, 4000)) - - // Next show the final round being played - playCardSound() - dispatch(updatePlayedCards(previousRound.currentHand.playedCards)) - dispatch(updateMyCards([])) - await new Promise(r => setTimeout(r, 6000)) + // Previous round will be undefined nobody called + if (previousRound) { + // Show the last card of the penultimate round being played + playCardSound() + const penultimateHand = previousRound.completedHands.pop() + if (!penultimateHand) + throw Error("Failed to get the penultimate round") + dispatch(updatePlayedCards(penultimateHand.playedCards)) + await new Promise(r => setTimeout(r, 4000)) + + // Next show the final round being played + playCardSound() + dispatch(updatePlayedCards(previousRound.currentHand.playedCards)) + dispatch(updateMyCards([])) + await new Promise(r => setTimeout(r, 6000)) + } else { + enqueueSnackbar("Nobody called. Redealing....", { + variant: "info", + }) + await new Promise(r => setTimeout(r, 2000)) + } // Finally update the game with the latest state shuffleSound() @@ -186,7 +195,9 @@ const WebsocketHandler = () => { case "ROUND_COMPLETED": await processRoundCompleted( action.gameState, - action.transitionData as Round, + action.transitionData + ? (action.transitionData as Round) + : undefined, ) break case "BUY_CARDS":