Skip to content

Commit 3b974a6

Browse files
Align drill play and analysis flows
1 parent 611c2cc commit 3b974a6

4 files changed

Lines changed: 1618 additions & 293 deletions

File tree

src/api/play.ts

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import { buildUrl } from './utils'
22
import { Color, TimeControl } from 'src/types'
33

4+
const normalizeOpeningBookFen = (fen: string) => {
5+
const parts = fen.trim().split(/\s+/)
6+
if (parts.length >= 4) {
7+
return parts.slice(0, 4).join(' ')
8+
}
9+
return fen.trim()
10+
}
11+
412
export const startGame = async (
513
playerColor: Color,
614
maiaVersion: string,
@@ -107,27 +115,36 @@ export const fetchGameMove = async (
107115
}
108116

109117
export const fetchOpeningBookMoves = async (fen: string) => {
110-
const res = await fetch(buildUrl(`play/get_book_moves?fen=${fen}`), {
111-
method: 'POST',
112-
headers: {
113-
Accept: 'application/json',
114-
'Content-Type': 'application/json',
118+
const normalizedFen = normalizeOpeningBookFen(fen)
119+
const res = await fetch(
120+
buildUrl(
121+
'play/get_book_moves?' +
122+
new URLSearchParams({
123+
fen: normalizedFen,
124+
}),
125+
),
126+
{
127+
method: 'POST',
128+
headers: {
129+
Accept: 'application/json',
130+
'Content-Type': 'application/json',
131+
},
132+
body: JSON.stringify({
133+
moves: [],
134+
maia_names: [
135+
'maia_kdd_1100',
136+
'maia_kdd_1200',
137+
'maia_kdd_1300',
138+
'maia_kdd_1400',
139+
'maia_kdd_1500',
140+
'maia_kdd_1600',
141+
'maia_kdd_1700',
142+
'maia_kdd_1800',
143+
'maia_kdd_1900',
144+
],
145+
}),
115146
},
116-
body: JSON.stringify({
117-
moves: [],
118-
maia_names: [
119-
'maia_kdd_1100',
120-
'maia_kdd_1200',
121-
'maia_kdd_1300',
122-
'maia_kdd_1400',
123-
'maia_kdd_1500',
124-
'maia_kdd_1600',
125-
'maia_kdd_1700',
126-
'maia_kdd_1800',
127-
'maia_kdd_1900',
128-
],
129-
}),
130-
})
147+
)
131148

132149
return res.json()
133150
}

src/components/Openings/OpeningDrillSidebar.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ interface Props {
1616
analysisEnabled?: boolean
1717
continueAnalyzingMode?: boolean
1818
drillTerminationNote?: string
19+
showBottomNavigation?: boolean
1920
}
2021

2122
export const OpeningDrillSidebar: React.FC<Props> = ({
@@ -28,6 +29,7 @@ export const OpeningDrillSidebar: React.FC<Props> = ({
2829
analysisEnabled,
2930
continueAnalyzingMode,
3031
drillTerminationNote,
32+
showBottomNavigation = true,
3133
}) => {
3234
const containerClass = embedded
3335
? 'flex h-full w-full max-w-full flex-col'
@@ -304,7 +306,7 @@ export const OpeningDrillSidebar: React.FC<Props> = ({
304306
</div>
305307

306308
{/* Bottom: Moves + Controller (embedded) */}
307-
{tree?.gameTree && currentDrill && (
309+
{showBottomNavigation && tree?.gameTree && currentDrill && (
308310
<div className="flex w-full flex-1 flex-col overflow-hidden border-t border-glass-border">
309311
<div className="red-scrollbar flex w-full flex-1 flex-col overflow-y-auto overflow-x-hidden">
310312
<MovesContainer

0 commit comments

Comments
 (0)