fix: clear hover state in CLEAR_MISMATCH for clean turn transitions

The previous fix only cleared hover on turn switch, but the actual turn
transition happens during CLEAR_MISMATCH (when cards flip back). This
was causing stale hover avatars to persist at the start of new turns.

Changes:
- **MatchingGameValidator.ts**: Clear non-current players' hovers in
  validateClearMismatch to ensure clean state when cards are cleared
- **RoomMemoryPairsProvider.tsx**: Mirror the server logic in optimistic
  CLEAR_MISMATCH handling
- **LocalMemoryPairsProvider.tsx**: Same fix for local-only games

Now when CLEAR_MISMATCH fires (after 1.5s mismatch timeout), we clear
hover state for all players except the current player, ensuring:
- No stale hovers from previous turns
- Only active player's current hover shows
- Clean transition between turns

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Thomas Hallock
2025-10-10 12:55:26 -05:00
parent a578ce7f8b
commit 43f7c92f6d
4 changed files with 35 additions and 1 deletions

View File

@@ -27,7 +27,8 @@
"Bash(docker run:*)",
"Bash(docker rmi:*)",
"Bash(gh run list:*)",
"Bash(gh run view:*)"
"Bash(gh run view:*)",
"Bash(timeout 15 pnpm run dev:*)"
],
"deny": [],
"ask": []

View File

@@ -188,11 +188,21 @@ function localMemoryPairsReducer(
}
case "CLEAR_MISMATCH": {
// Clear hover for all non-current players
const clearedHovers = { ...state.playerHovers };
for (const playerId of state.activePlayers) {
if (playerId !== state.currentPlayer) {
clearedHovers[playerId] = null;
}
}
return {
...state,
flippedCards: [],
showMismatchFeedback: false,
isProcessingMove: false,
// Clear hovers for non-current players
playerHovers: clearedHovers,
};
}

View File

@@ -120,12 +120,22 @@ function applyMoveOptimistically(
}
case "CLEAR_MISMATCH": {
// Clear hover for all non-current players
const clearedHovers = { ...state.playerHovers };
for (const playerId of state.activePlayers) {
if (playerId !== state.currentPlayer) {
clearedHovers[playerId] = null;
}
}
// Clear mismatched cards and feedback
return {
...state,
flippedCards: [],
showMismatchFeedback: false,
isProcessingMove: false,
// Clear hovers for non-current players
playerHovers: clearedHovers,
};
}

View File

@@ -285,6 +285,17 @@ export class MatchingGameValidator
};
}
// Get the list of all non-current players whose hovers should be cleared
// (They're not playing this turn, so their hovers from previous turns should not show)
const clearedHovers = { ...state.playerHovers };
for (const playerId of state.activePlayers) {
// Clear hover for all players except the current player
// This ensures only the current player's active hover shows
if (playerId !== state.currentPlayer) {
clearedHovers[playerId] = null;
}
}
// Clear mismatched cards and feedback
return {
valid: true,
@@ -293,6 +304,8 @@ export class MatchingGameValidator
flippedCards: [],
showMismatchFeedback: false,
isProcessingMove: false,
// Clear hovers for non-current players when cards are cleared
playerHovers: clearedHovers,
},
};
}