Skip to content

Commit a804db4

Browse files
committed
fix code duplication in ui/round/ctrl
1 parent d0dcf31 commit a804db4

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

ui/round/src/ctrl.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export default class RoundController implements MoveRootCtrl {
9292
preDrop?: cg.Role;
9393
sign: string = Math.random().toString(36);
9494
keyboardHelp: boolean = location.hash === '#keyboard';
95+
blindfoldStorage: LichessBooleanStorage;
9596

9697
constructor(
9798
readonly opts: RoundOpts,
@@ -111,6 +112,7 @@ export default class RoundController implements MoveRootCtrl {
111112
}, 3000);
112113

113114
this.socket = makeSocket(opts.socketSend, this);
115+
this.blindfoldStorage = lichess.storage.boolean(`blindfold.${this.data.player.user?.id ?? 'anon'}`);
114116

115117
if (d.clock)
116118
this.clock = new ClockController(d, {
@@ -856,7 +858,7 @@ export default class RoundController implements MoveRootCtrl {
856858

857859
blindfold = (v?: boolean): boolean => {
858860
if (v === undefined || v === this.data.player.blindfold) return this.data.player.blindfold ?? false;
859-
lichess.storage.set(`blindfold.${this.data.player.user?.id ?? 'anon'}`, v ? 'true' : 'false');
861+
this.blindfoldStorage.set(v);
860862
this.data.player.blindfold = v;
861863
this.socket.send(`blindfold-${v ? 'yes' : 'no'}`);
862864
this.redraw();
@@ -899,10 +901,10 @@ export default class RoundController implements MoveRootCtrl {
899901
if (lichess.storage.get('blindfold') === 'true') {
900902
// TODO - delete this if block & storage.set once a few weeks pass
901903
lichess.storage.remove('blindfold');
902-
lichess.storage.set(`blindfold.${this.data.player.user?.id ?? 'anon'}`, 'true');
904+
this.blindfoldStorage.set(true);
903905
}
904906

905-
this.blindfold(lichess.storage.get(`blindfold.${this.data.player.user?.id ?? 'anon'}`) === 'true');
907+
this.blindfold(this.blindfoldStorage.get());
906908
}
907909
wakeLock.request();
908910

0 commit comments

Comments
 (0)