11import React from 'react'
2+ import Image from 'next/image'
3+ import { Tooltip } from 'react-tooltip'
24import { OpeningSelection , GameNode , GameTree } from 'src/types'
35import { GameInfo } from '../Misc/GameInfo'
46import { MovesContainer } from '../Board/MovesContainer'
@@ -9,6 +11,7 @@ interface Props {
911 currentSelectionIndex : number
1012 onSwitchSelection : ( index : number ) => void
1113 onResetCurrent : ( ) => void
14+ onResetOpening : ( selectionId : string ) => void
1215 gameTree : GameTree
1316 currentNode : GameNode
1417 goToNode : ( node : GameNode ) => void
@@ -18,13 +21,15 @@ interface Props {
1821 plyCount : number
1922 orientation : 'white' | 'black'
2023 setOrientation : ( orientation : 'white' | 'black' ) => void
24+ analysisEnabled : boolean
2125}
2226
2327export const OpeningDrillSidebar : React . FC < Props > = ( {
2428 selections,
2529 currentSelectionIndex,
2630 onSwitchSelection,
2731 onResetCurrent,
32+ onResetOpening,
2833 gameTree,
2934 currentNode,
3035 goToNode,
@@ -34,6 +39,7 @@ export const OpeningDrillSidebar: React.FC<Props> = ({
3439 plyCount,
3540 orientation,
3641 setOrientation,
42+ analysisEnabled,
3743} ) => {
3844 const currentSelection = selections [ currentSelectionIndex ]
3945
@@ -53,36 +59,25 @@ export const OpeningDrillSidebar: React.FC<Props> = ({
5359
5460 return (
5561 < div className = "flex h-[85vh] w-72 min-w-60 max-w-72 flex-col gap-2 overflow-hidden 2xl:min-w-72" >
56- < GameInfo title = "Opening Drill" icon = "school" type = "analysis" >
62+ < GameInfo title = "Drill Openings " icon = "school" type = "analysis" >
5763 < div className = "space-y-2" >
58- < p className = "text-sm text-secondary" >
59- Current Opening:{ ' ' }
60- < span className = "text-primary" >
61- { currentSelection ?. opening . name }
62- </ span >
63- </ p >
64- { currentSelection ?. variation && (
64+ < div className = "min-h-[30px]" >
6565 < p className = "text-sm text-secondary" >
66- Variation :{ ' ' }
66+ Current Opening :{ ' ' }
6767 < span className = "text-primary" >
68- { currentSelection . variation . name }
68+ { currentSelection ?. opening . name }
6969 </ span >
7070 </ p >
71- ) }
72- < div className = "flex items-center gap-2 text-sm" >
73- < span
74- className = { `inline-flex items-center gap-1 ${
75- currentSelection ?. playerColor === 'white'
76- ? 'text-white'
77- : 'text-gray-400'
78- } `}
79- >
80- < span className = "material-symbols-outlined text-xs" > chess</ span >
81- Playing as { currentSelection ?. playerColor }
82- </ span >
83- < span className = "text-human-3" >
84- vs { currentSelection ?. maiaVersion . replace ( 'maia_kdd_' , 'Maia ' ) }
85- </ span >
71+ < div className = "min-h-[20px]" >
72+ { currentSelection ?. variation && (
73+ < p className = "text-sm text-secondary" >
74+ Variation:{ ' ' }
75+ < span className = "text-primary" >
76+ { currentSelection . variation . name }
77+ </ span >
78+ </ p >
79+ ) }
80+ </ div >
8681 </ div >
8782 </ div >
8883 </ GameInfo >
@@ -94,73 +89,104 @@ export const OpeningDrillSidebar: React.FC<Props> = ({
9489 </ h3 >
9590 < button
9691 onClick = { onResetCurrent }
97- className = "text-xs text-secondary transition-colors hover:text-human-4 "
98- title = "Reset current opening "
92+ className = "text-xs text-secondary transition-colors hover:text-primary "
93+ data-tooltip-id = "reset-all-tooltip "
9994 >
100- < span className = "material-symbols-outlined text-sm " > refresh</ span >
95+ < span className = "material-symbols-outlined text-base " > refresh</ span >
10196 </ button >
97+ < Tooltip
98+ id = "reset-all-tooltip"
99+ content = "Reset All Openings"
100+ place = "top"
101+ delayShow = { 300 }
102+ className = "z-50 !bg-background-2 !px-2 !py-1 !text-xs"
103+ />
102104 </ div >
103105
104106 < div className = "flex-1 overflow-y-auto" >
105107 { selections . map ( ( selection , index ) => (
106108 < div
107109 key = { selection . id }
108- role = "button"
109- tabIndex = { 0 }
110- className = { `cursor-pointer border-b border-white/5 p-3 transition-colors ${
110+ className = { `flex cursor-pointer items-center justify-between border-b border-white/5 p-3 transition-colors ${
111111 index === currentSelectionIndex
112112 ? 'bg-human-2/20'
113113 : 'hover:bg-human-2/10'
114114 } `}
115- onClick = { ( ) => onSwitchSelection ( index ) }
116- onKeyDown = { ( e ) => {
117- if ( e . key === 'Enter' || e . key === ' ' ) {
118- onSwitchSelection ( index )
119- }
120- } }
121115 >
122- < div className = "flex items-start justify-between" >
123- < div className = "min-w-0 flex-1" >
124- < h4 className = "truncate text-sm font-medium" >
125- { selection . opening . name }
126- </ h4 >
127- { selection . variation && (
128- < p className = "truncate text-xs text-secondary" >
129- { selection . variation . name }
130- </ p >
131- ) }
132- < div className = "mt-1 flex items-center gap-2" >
133- < span
134- className = { `inline-flex items-center gap-1 text-xs ${
116+ < div
117+ role = "button"
118+ tabIndex = { 0 }
119+ className = "min-w-0 flex-1"
120+ onClick = { ( ) => onSwitchSelection ( index ) }
121+ onKeyDown = { ( e ) => {
122+ if ( e . key === 'Enter' || e . key === ' ' ) {
123+ onSwitchSelection ( index )
124+ }
125+ } }
126+ >
127+ < div className = "flex items-center gap-3" >
128+ < div className = "relative h-5 w-5 flex-shrink-0" >
129+ < Image
130+ src = {
135131 selection . playerColor === 'white'
136- ? 'text-white'
137- : 'text-gray-400'
138- } `}
139- >
140- < span className = "material-symbols-outlined text-xs" >
141- chess
142- </ span >
143- { selection . playerColor }
144- </ span >
145- < span className = "text-xs text-human-3" >
146- { selection . maiaVersion . replace ( 'maia_kdd_' , 'Maia ' ) }
132+ ? '/assets/pieces/white king.svg'
133+ : '/assets/pieces/black king.svg'
134+ }
135+ fill = { true }
136+ alt = { `${ selection . playerColor } king` }
137+ />
138+ </ div >
139+ < div className = "flex min-w-0 flex-1 flex-col" >
140+ < span className = "truncate text-sm font-medium text-primary" >
141+ { selection . opening . name }
147142 </ span >
143+ < div className = "flex items-center gap-1 text-xs text-secondary" >
144+ { selection . variation && (
145+ < >
146+ < span className = "truncate" >
147+ { selection . variation . name }
148+ </ span >
149+ < span > •</ span >
150+ </ >
151+ ) }
152+ < span >
153+ v. Maia { selection . maiaVersion . replace ( 'maia_kdd_' , '' ) }
154+ </ span >
155+ </ div >
148156 </ div >
149157 </ div >
150- { index === currentSelectionIndex && (
151- < span className = "material-symbols-outlined ml-2 text-sm text-human-3" >
152- play_arrow
153- </ span >
154- ) }
155158 </ div >
159+ < button
160+ onClick = { ( e ) => {
161+ e . stopPropagation ( )
162+ onResetOpening ( selection . id )
163+ } }
164+ className = "ml-2 text-secondary transition-colors hover:text-primary"
165+ data-tooltip-id = { `reset-opening-${ selection . id } ` }
166+ >
167+ < span className = "material-symbols-outlined text-sm" >
168+ refresh
169+ </ span >
170+ </ button >
171+ < Tooltip
172+ id = { `reset-opening-${ selection . id } ` }
173+ content = "Reset Opening"
174+ place = "top"
175+ delayShow = { 300 }
176+ className = "z-50 !bg-background-2 !px-2 !py-1 !text-xs"
177+ />
156178 </ div >
157179 ) ) }
158180 </ div >
159181 </ div >
160182
161183 < div className = "flex h-1/2 w-full flex-1 flex-col gap-2" >
162184 < div className = "flex h-full flex-col overflow-y-scroll" >
163- < MovesContainer game = { baseGame } type = "analysis" />
185+ < MovesContainer
186+ game = { baseGame }
187+ type = "analysis"
188+ showAnnotations = { analysisEnabled }
189+ />
164190 < BoardController
165191 gameTree = { gameTree }
166192 orientation = { orientation }
0 commit comments