@@ -14,6 +14,12 @@ import {
1414} from 'src/types'
1515import { ModalContext } from 'src/contexts'
1616import { ModalContainer } from './ModalContainer'
17+ import { Slider } from './Slider'
18+ import {
19+ customToPresetTimeControl ,
20+ parseTimeControl ,
21+ getPresetOptions ,
22+ } from 'src/lib/timeControlUtils'
1723
1824const maiaOptions = [
1925 'maia_kdd_1100' ,
@@ -82,6 +88,9 @@ export const PlaySetupModal: React.FC<Props> = (props: Props) => {
8288 const [ timeControl , setTimeControl ] = useState < TimeControl > (
8389 props . timeControl || TimeControlOptions [ 0 ] ,
8490 )
91+ const [ useCustomTime , setUseCustomTime ] = useState < boolean > ( false )
92+ const [ customMinutes , setCustomMinutes ] = useState < number > ( 10 )
93+ const [ customIncrement , setCustomIncrement ] = useState < number > ( 0 )
8594 const [ isBrain , setIsBrain ] = useState < boolean > ( props . isBrain || false )
8695 const [ sampleMoves , setSampleMoves ] = useState < boolean > (
8796 props . sampleMoves || true ,
@@ -102,9 +111,18 @@ export const PlaySetupModal: React.FC<Props> = (props: Props) => {
102111
103112 const [ openMoreOptions , setMoreOptionsOpen ] = useState < boolean > ( true )
104113
114+ // Helper function to get the effective time control
115+ const getEffectiveTimeControl = ( ) : TimeControl => {
116+ if ( useCustomTime ) {
117+ return customToPresetTimeControl ( customMinutes , customIncrement )
118+ }
119+ return timeControl
120+ }
121+
105122 const start = useCallback (
106123 ( color : Color | undefined ) => {
107124 const player = color ?? [ 'white' , 'black' ] [ Math . floor ( Math . random ( ) * 2 ) ]
125+ const effectiveTimeControl = getEffectiveTimeControl ( )
108126
109127 if ( fen && ! new Chess ( ) . validateFen ( fen ) . valid ) {
110128 toast . error ( 'Invalid Starting FEN provided' )
@@ -120,7 +138,7 @@ export const PlaySetupModal: React.FC<Props> = (props: Props) => {
120138 player : player ,
121139 //maiaPartnerVersion: maiaPartnerVersion,
122140 maiaVersion : maiaVersion ,
123- timeControl : timeControl ,
141+ timeControl : effectiveTimeControl ,
124142 sampleMoves : sampleMoves ,
125143 simulateMaiaTime : simulateMaiaTime ,
126144 startFen : fen ,
@@ -133,7 +151,7 @@ export const PlaySetupModal: React.FC<Props> = (props: Props) => {
133151 player : player ,
134152 maiaPartnerVersion : maiaPartnerVersion ,
135153 maiaVersion : maiaVersion ,
136- timeControl : timeControl ,
154+ timeControl : effectiveTimeControl ,
137155 isBrain : isBrain ,
138156 sampleMoves : sampleMoves ,
139157 simulateMaiaTime : simulateMaiaTime ,
@@ -148,7 +166,7 @@ export const PlaySetupModal: React.FC<Props> = (props: Props) => {
148166 push ,
149167 maiaPartnerVersion ,
150168 maiaVersion ,
151- timeControl ,
169+ getEffectiveTimeControl ,
152170 sampleMoves ,
153171 simulateMaiaTime ,
154172 fen ,
@@ -250,18 +268,61 @@ export const PlaySetupModal: React.FC<Props> = (props: Props) => {
250268 < div >
251269 < label
252270 htmlFor = "time-control-select"
253- className = "mb-1 block text-sm font-medium text-primary"
271+ className = "mb-2 block text-sm font-medium text-primary"
254272 >
255273 Time control:
256274 </ label >
257- < div id = "time-control-select" >
275+
276+ { /* Toggle between preset and custom */ }
277+ < div className = "mb-3" >
258278 < OptionSelect
259- options = { TimeControlOptions }
260- labels = { TimeControlOptionNames }
261- selected = { timeControl }
262- onChange = { setTimeControl }
279+ options = { [ false , true ] }
280+ labels = { [ 'Preset' , 'Custom' ] }
281+ selected = { useCustomTime }
282+ onChange = { setUseCustomTime }
263283 />
264284 </ div >
285+
286+ { useCustomTime ? (
287+ /* Custom time controls with sliders */
288+ < div className = "space-y-3 rounded bg-background-2 p-3" >
289+ < Slider
290+ id = "time-slider"
291+ label = "Time per side"
292+ value = { customMinutes }
293+ min = { 1 }
294+ max = { 180 }
295+ step = { 1 }
296+ unit = " min"
297+ onChange = { setCustomMinutes }
298+ />
299+ < Slider
300+ id = "increment-slider"
301+ label = "Increment per move"
302+ value = { customIncrement }
303+ min = { 0 }
304+ max = { 60 }
305+ step = { 1 }
306+ unit = " sec"
307+ onChange = { setCustomIncrement }
308+ />
309+ < div className = "mt-2 text-center" >
310+ < span className = "text-xs text-secondary" >
311+ Time control: { customMinutes } +{ customIncrement }
312+ </ span >
313+ </ div >
314+ </ div >
315+ ) : (
316+ /* Preset time controls */
317+ < div id = "time-control-select" >
318+ < OptionSelect
319+ options = { TimeControlOptions }
320+ labels = { TimeControlOptionNames }
321+ selected = { timeControl }
322+ onChange = { setTimeControl }
323+ />
324+ </ div >
325+ ) }
265326 </ div >
266327
267328 < div >
0 commit comments