Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/components/Analysis/BoardChrome.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useEffect, useRef } from 'react'
import { motion, type MotionValue } from 'framer-motion'
import type { ColorSanMapping, BlunderMeterResult } from 'src/types'

Expand Down Expand Up @@ -350,6 +351,21 @@ export const AnalysisCompactBlunderMeter: React.FC<
variant = 'mobile',
}) => {
const isDesktop = variant === 'desktop'
const sanLabelCacheRef = useRef<Record<string, string>>({})

useEffect(() => {
if (!colorSanMapping) return

for (const [move, entry] of Object.entries(colorSanMapping)) {
if (entry?.san) {
sanLabelCacheRef.current[move] = entry.san
}
}
}, [colorSanMapping])

const getDisplayMoveLabel = (move: string) =>
colorSanMapping?.[move]?.san ?? sanLabelCacheRef.current[move] ?? '...'

const getTopCategoryMoves = (
moves: { move: string; probability: number }[],
) => {
Expand All @@ -360,7 +376,7 @@ export const AnalysisCompactBlunderMeter: React.FC<
.map((entry) => ({
move: entry.move,
probability: Math.round(entry.probability),
label: colorSanMapping?.[entry.move]?.san || entry.move,
label: getDisplayMoveLabel(entry.move),
}))

if (!playedMove || topMoves.some((entry) => entry.move === playedMove)) {
Expand All @@ -377,8 +393,7 @@ export const AnalysisCompactBlunderMeter: React.FC<
{
move: playedMoveEntry.move,
probability: Math.round(playedMoveEntry.probability),
label:
colorSanMapping?.[playedMoveEntry.move]?.san || playedMoveEntry.move,
label: getDisplayMoveLabel(playedMoveEntry.move),
},
]
}
Expand Down
Loading