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:
@@ -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": []
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user