Skip to content

Commit 2708616

Browse files
committed
use a toggle for multiboard showEval
1 parent 7704dc4 commit 2708616

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

ui/analyse/src/study/multiBoard.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { ChapterPreview, ChapterPreviewPlayer, Position, StudyChapterMeta } from
1111
import StudyCtrl from './studyCtrl';
1212
import { EvalHitMulti } from '../interfaces';
1313
import { povChances } from 'ceval/src/winningChances';
14-
import { defined } from 'common';
14+
import { Toggle, defined, toggle } from 'common';
1515

1616
interface CloudEval extends EvalHitMulti {
1717
chances: number;
@@ -22,7 +22,7 @@ export class MultiBoardCtrl {
2222
page = 1;
2323
pager?: Paginator<ChapterPreview>;
2424
playing = false;
25-
showEval = false;
25+
showEval: Toggle;
2626

2727
private cloudEvals: Map<Fen, CloudEval> = new Map();
2828

@@ -32,7 +32,9 @@ export class MultiBoardCtrl {
3232
readonly trans: Trans,
3333
private readonly send: SocketSend,
3434
private readonly variant: () => VariantKey,
35-
) {}
35+
) {
36+
this.showEval = toggle(false, redraw);
37+
}
3638

3739
addNode = (pos: Position, node: Tree.Node) => {
3840
const cp = this.pager?.currentPageResults.find(cp => cp.id == pos.chapterId);
@@ -106,11 +108,6 @@ export class MultiBoardCtrl {
106108
this.reload();
107109
};
108110

109-
setShowEval = (v: boolean) => {
110-
this.showEval = v;
111-
this.redraw();
112-
};
113-
114111
onCloudEval = (d: EvalHitMulti) => {
115112
this.cloudEvals.set(d.fen, { ...d, chances: povChances('white', d) });
116113
this.redraw();
@@ -151,7 +148,7 @@ export function view(ctrl: MultiBoardCtrl, study: StudyCtrl): VNode | undefined
151148

152149
function renderPager(pager: Paginator<ChapterPreview>, study: StudyCtrl): MaybeVNodes {
153150
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;
155152
return [
156153
h('div.top', [renderPagerNav(pager, ctrl), renderEvalToggle(ctrl), renderPlayingToggle(ctrl)]),
157154
h('div.now-playing', pager.currentPageResults.map(makePreview(study, cloudEval))),
@@ -171,8 +168,8 @@ function renderPlayingToggle(ctrl: MultiBoardCtrl): VNode {
171168
function renderEvalToggle(ctrl: MultiBoardCtrl): VNode {
172169
return h('label.eval', [
173170
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)),
176173
}),
177174
ctrl.trans.noarg('showEval'),
178175
]);

0 commit comments

Comments
 (0)