Skip to content

Commit c2afeea

Browse files
feat: handle all drill terminations and surface end reason in gameplay + feedback move lists
1 parent 03cdc17 commit c2afeea

5 files changed

Lines changed: 298 additions & 40 deletions

File tree

src/components/Board/MovesContainer.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ interface Props {
99
game: BaseGame
1010
highlightIndices?: number[]
1111
termination?: Termination
12+
terminationNote?: string
1213
showAnnotations?: boolean
1314
showVariations?: boolean
1415
disableKeyboardNavigation?: boolean
@@ -41,6 +42,7 @@ export const MovesContainer: React.FC<
4142
const {
4243
game,
4344
termination,
45+
terminationNote,
4446
highlightIndices,
4547
showAnnotations = true,
4648
showVariations = true,
@@ -362,6 +364,11 @@ export const MovesContainer: React.FC<
362364
: 'draw'}
363365
</div>
364366
)}
367+
{terminationNote && (
368+
<div className="min-w-fit border-b border-t border-glass-border bg-glass px-3 py-1 text-xs text-white/70">
369+
{terminationNote}
370+
</div>
371+
)}
365372
</div>
366373
</div>
367374
)
@@ -483,6 +490,11 @@ export const MovesContainer: React.FC<
483490
: 'draw'}
484491
</div>
485492
)}
493+
{terminationNote && !isMobile && (
494+
<div className="col-span-5 border-b border-glass-border bg-glass px-2 py-1 text-center text-xs text-white/70">
495+
{terminationNote}
496+
</div>
497+
)}
486498
</div>
487499
)
488500
}

src/components/Openings/DrillPerformanceModal.tsx

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,14 @@ const AnimatedGameReplay: React.FC<{
9090
playerColor: 'white' | 'black'
9191
gameTree: GameTree
9292
openingEndNode: GameNode
93-
}> = ({ openingFen, playerColor, gameTree, openingEndNode }) => {
93+
terminationNote?: string
94+
}> = ({
95+
openingFen,
96+
playerColor,
97+
gameTree,
98+
openingEndNode,
99+
terminationNote,
100+
}) => {
94101
const [currentFen, setCurrentFen] = useState(openingFen)
95102
const [currentNode, setCurrentNode] = useState<GameNode | null>(null)
96103
const [orientation, setOrientation] = useState<'white' | 'black'>(playerColor)
@@ -258,6 +265,7 @@ const AnimatedGameReplay: React.FC<{
258265
}}
259266
startFromNode={openingEndNode}
260267
restrictNavigationBefore={openingEndNode}
268+
terminationNote={terminationNote}
261269
showAnnotations={true}
262270
showVariations={false}
263271
/>
@@ -768,6 +776,7 @@ const DesktopLayout: React.FC<{
768776
treeController: ReturnType<typeof useTreeController>
769777
gameNodesMap: Map<string, GameNode>
770778
currentMoveIndex: number
779+
terminationNote?: string
771780
getChartClassification: (
772781
analysis: MoveAnalysis,
773782
gameNodesMap: Map<string, GameNode>,
@@ -786,6 +795,7 @@ const DesktopLayout: React.FC<{
786795
treeController,
787796
gameNodesMap,
788797
currentMoveIndex,
798+
terminationNote,
789799
getChartClassification,
790800
}) => (
791801
<div className="from-white/8 to-white/4 relative flex h-[90vh] max-h-[800px] w-[95vw] max-w-[1200px] flex-col overflow-hidden rounded-lg border border-glass-border bg-gradient-to-br backdrop-blur-md">
@@ -841,6 +851,7 @@ const DesktopLayout: React.FC<{
841851
playerColor={drill.selection.playerColor}
842852
gameTree={gameTree}
843853
openingEndNode={openingEndNode}
854+
terminationNote={terminationNote}
844855
/>
845856
</TreeControllerContext.Provider>
846857
</div>
@@ -1091,6 +1102,7 @@ const MobileLayout: React.FC<{
10911102
treeController: ReturnType<typeof useTreeController>
10921103
gameNodesMap: Map<string, GameNode>
10931104
currentMoveIndex: number
1105+
terminationNote?: string
10941106
getChartClassification: (
10951107
analysis: MoveAnalysis,
10961108
gameNodesMap: Map<string, GameNode>,
@@ -1111,6 +1123,7 @@ const MobileLayout: React.FC<{
11111123
treeController,
11121124
gameNodesMap,
11131125
currentMoveIndex,
1126+
terminationNote,
11141127
getChartClassification,
11151128
}) => (
11161129
<div className="from-white/8 to-white/4 relative flex h-[95vh] w-[95vw] flex-col overflow-hidden rounded-lg border border-glass-border bg-gradient-to-br backdrop-blur-md">
@@ -1196,6 +1209,7 @@ const MobileLayout: React.FC<{
11961209
playerColor={drill.selection.playerColor}
11971210
gameTree={gameTree}
11981211
openingEndNode={openingEndNode}
1212+
terminationNote={terminationNote}
11991213
/>
12001214
</TreeControllerContext.Provider>
12011215
)}
@@ -1457,6 +1471,14 @@ export const DrillPerformanceModal: React.FC<Props> = ({
14571471

14581472
// Get opening FEN from the opening end node
14591473
const openingFen = openingEndNode.fen
1474+
const moveListTerminationNote = useMemo(() => {
1475+
const reasonLine = performanceData.feedback.find((entry) =>
1476+
entry.toLowerCase().startsWith('drill ended:'),
1477+
)
1478+
if (!reasonLine) return undefined
1479+
1480+
return reasonLine.replace(/^Drill ended:\s*/i, '').replace(/\.$/, '')
1481+
}, [performanceData.feedback])
14601482

14611483
return (
14621484
<ModalContainer dismiss={onContinueAnalyzing}>
@@ -1477,6 +1499,7 @@ export const DrillPerformanceModal: React.FC<Props> = ({
14771499
treeController={treeController}
14781500
gameNodesMap={gameNodesMap}
14791501
currentMoveIndex={currentMoveIndex}
1502+
terminationNote={moveListTerminationNote}
14801503
getChartClassification={getChartClassification}
14811504
/>
14821505
) : (
@@ -1494,6 +1517,7 @@ export const DrillPerformanceModal: React.FC<Props> = ({
14941517
treeController={treeController}
14951518
gameNodesMap={gameNodesMap}
14961519
currentMoveIndex={currentMoveIndex}
1520+
terminationNote={moveListTerminationNote}
14971521
getChartClassification={getChartClassification}
14981522
/>
14991523
)}

src/components/Openings/OpeningDrillSidebar.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ interface Props {
1515
openingEndNode?: GameNode | null
1616
analysisEnabled?: boolean
1717
continueAnalyzingMode?: boolean
18+
drillTerminationNote?: string
1819
}
1920

2021
export const OpeningDrillSidebar: React.FC<Props> = ({
@@ -26,6 +27,7 @@ export const OpeningDrillSidebar: React.FC<Props> = ({
2627
openingEndNode,
2728
analysisEnabled,
2829
continueAnalyzingMode,
30+
drillTerminationNote,
2931
}) => {
3032
const containerClass = embedded
3133
? 'flex h-full w-full max-w-full flex-col'
@@ -309,6 +311,7 @@ export const OpeningDrillSidebar: React.FC<Props> = ({
309311
game={{ id: currentDrill.id, tree: tree.gameTree }}
310312
startFromNode={openingEndNode || undefined}
311313
restrictNavigationBefore={openingEndNode || undefined}
314+
terminationNote={drillTerminationNote}
312315
showAnnotations={!!(analysisEnabled || continueAnalyzingMode)}
313316
showVariations={!!continueAnalyzingMode}
314317
embedded

0 commit comments

Comments
 (0)