@@ -11,7 +11,7 @@ import { ChapterPreview, ChapterPreviewPlayer, Position, StudyChapterMeta } from
11
11
import StudyCtrl from './studyCtrl' ;
12
12
import { EvalHitMulti } from '../interfaces' ;
13
13
import { povChances } from 'ceval/src/winningChances' ;
14
- import { defined } from 'common' ;
14
+ import { Toggle , defined , toggle } from 'common' ;
15
15
16
16
interface CloudEval extends EvalHitMulti {
17
17
chances : number ;
@@ -22,7 +22,7 @@ export class MultiBoardCtrl {
22
22
page = 1 ;
23
23
pager ?: Paginator < ChapterPreview > ;
24
24
playing = false ;
25
- showEval = false ;
25
+ showEval : Toggle ;
26
26
27
27
private cloudEvals : Map < Fen , CloudEval > = new Map ( ) ;
28
28
@@ -32,7 +32,9 @@ export class MultiBoardCtrl {
32
32
readonly trans : Trans ,
33
33
private readonly send : SocketSend ,
34
34
private readonly variant : ( ) => VariantKey ,
35
- ) { }
35
+ ) {
36
+ this . showEval = toggle ( false , redraw ) ;
37
+ }
36
38
37
39
addNode = ( pos : Position , node : Tree . Node ) => {
38
40
const cp = this . pager ?. currentPageResults . find ( cp => cp . id == pos . chapterId ) ;
@@ -106,11 +108,6 @@ export class MultiBoardCtrl {
106
108
this . reload ( ) ;
107
109
} ;
108
110
109
- setShowEval = ( v : boolean ) => {
110
- this . showEval = v ;
111
- this . redraw ( ) ;
112
- } ;
113
-
114
111
onCloudEval = ( d : EvalHitMulti ) => {
115
112
this . cloudEvals . set ( d . fen , { ...d , chances : povChances ( 'white' , d ) } ) ;
116
113
this . redraw ( ) ;
@@ -151,7 +148,7 @@ export function view(ctrl: MultiBoardCtrl, study: StudyCtrl): VNode | undefined
151
148
152
149
function renderPager ( pager : Paginator < ChapterPreview > , study : StudyCtrl ) : MaybeVNodes {
153
150
const ctrl = study . multiBoard ;
154
- const cloudEval = ctrl . showEval && study . ctrl . ceval ?. enabled ( ) ? ctrl . getCloudEval : undefined ;
151
+ const cloudEval = ctrl . showEval ( ) && study . ctrl . ceval ?. enabled ( ) ? ctrl . getCloudEval : undefined ;
155
152
return [
156
153
h ( 'div.top' , [ renderPagerNav ( pager , ctrl ) , renderEvalToggle ( ctrl ) , renderPlayingToggle ( ctrl ) ] ) ,
157
154
h ( 'div.now-playing' , pager . currentPageResults . map ( makePreview ( study , cloudEval ) ) ) ,
@@ -171,8 +168,8 @@ function renderPlayingToggle(ctrl: MultiBoardCtrl): VNode {
171
168
function renderEvalToggle ( ctrl : MultiBoardCtrl ) : VNode {
172
169
return h ( 'label.eval' , [
173
170
h ( 'input' , {
174
- attrs : { type : 'checkbox' , checked : ctrl . showEval } ,
175
- hook : bind ( 'change' , e => ctrl . setShowEval ( ( e . target as HTMLInputElement ) . checked ) ) ,
171
+ attrs : { type : 'checkbox' , checked : ctrl . showEval ( ) } ,
172
+ hook : bind ( 'change' , e => ctrl . showEval ( ( e . target as HTMLInputElement ) . checked ) ) ,
176
173
} ) ,
177
174
ctrl . trans . noarg ( 'showEval' ) ,
178
175
] ) ;
0 commit comments