Skip to content

Commit c27d261

Browse files
Fix MoveTooltip persistence on mobile by clearing tooltip state on position changes
Co-authored-by: kevinjosethomas <46242684+kevinjosethomas@users.noreply.github.com>
1 parent 7fa4a2f commit c27d261

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

src/components/Analysis/BlunderMeter.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useContext, useState } from 'react'
1+
import React, { useContext, useState, useEffect } from 'react'
22
import { motion } from 'framer-motion'
33

44
import {
@@ -216,6 +216,11 @@ function MovesList({
216216
position: { x: number; y: number }
217217
} | null>(null)
218218

219+
// Clear tooltip when position changes (indicated by colorSanMapping change)
220+
useEffect(() => {
221+
setTooltipData(null)
222+
}, [colorSanMapping])
223+
219224
const filteredMoves = () => {
220225
return moves.slice(0, 6).filter((move) => move.probability >= 8)
221226
}
@@ -338,6 +343,11 @@ function Meter({
338343
position: { x: number; y: number }
339344
} | null>(null)
340345

346+
// Clear tooltip when position changes (indicated by colorSanMapping change)
347+
useEffect(() => {
348+
setTooltipData(null)
349+
}, [colorSanMapping])
350+
341351
const filteredMoves = () => {
342352
return moves.slice(0, 6).filter((move) => move.probability >= 8)
343353
}

src/components/Analysis/Highlight.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ export const Highlight: React.FC<Props> = ({
6161
position: { x: number; y: number }
6262
} | null>(null)
6363

64+
// Clear tooltip when position changes (indicated by currentNode change)
65+
useEffect(() => {
66+
setTooltipData(null)
67+
}, [currentNode])
68+
6469
const findMatchingMove = (move: string, source: 'maia' | 'stockfish') => {
6570
if (source === 'maia') {
6671
return recommendations.stockfish?.find((rec) => rec.move === move)

src/components/Analysis/MoveMap.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
CartesianGrid,
99
ResponsiveContainer,
1010
} from 'recharts'
11-
import { useContext, useState } from 'react'
11+
import { useContext, useState, useEffect } from 'react'
1212
import { ColorSanMapping } from 'src/types'
1313
import type { Key } from 'chessground/types'
1414
import type { DrawShape } from 'chessground/draw'
@@ -65,6 +65,13 @@ export const MoveMap: React.FC<Props> = ({
6565
y: number
6666
} | null>(null)
6767

68+
// Clear tooltip when position changes (indicated by colorSanMapping change)
69+
useEffect(() => {
70+
setHoveredMove(null)
71+
setHoveredMoveData(null)
72+
setMousePosition(null)
73+
}, [colorSanMapping])
74+
6875
// Responsive font sizing based on screen width
6976
const getAxisLabelFontSize = () => {
7077
if (width < 640) return 10 // Very small screens

0 commit comments

Comments
 (0)