ssb-chess-mithril 2.0.9 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/css/chessground-examples/README.md +14 -4
  2. package/css/chessground-examples/assets/3d.css +24 -23
  3. package/css/chessground-examples/assets/chessground.css +73 -15
  4. package/css/chessground-examples/assets/examples.css +1 -1
  5. package/css/chessground-examples/assets/theme.css +37 -26
  6. package/css/chessground-examples/index.html +5 -5
  7. package/css/chessground-examples/package-lock.json +1747 -8086
  8. package/css/chessground-examples/package.json +32 -17
  9. package/css/chessground-examples/pnpm-lock.yaml +874 -0
  10. package/css/chessground-examples/rollup.config.mjs +20 -0
  11. package/css/chessground-examples/src/main.ts +81 -48
  12. package/css/chessground-examples/src/units/anim.ts +63 -42
  13. package/css/chessground-examples/src/units/basics.ts +73 -13
  14. package/css/chessground-examples/src/units/fen.ts +21 -18
  15. package/css/chessground-examples/src/units/in3d.ts +26 -26
  16. package/css/chessground-examples/src/units/perf.ts +29 -15
  17. package/css/chessground-examples/src/units/play.ts +71 -52
  18. package/css/chessground-examples/src/units/svg.ts +230 -102
  19. package/css/chessground-examples/src/units/unit.ts +47 -18
  20. package/css/chessground-examples/src/units/viewOnly.ts +11 -11
  21. package/css/chessground-examples/src/units/zh.ts +25 -23
  22. package/css/chessground-examples/src/util.ts +30 -18
  23. package/css/chessground-examples/tsconfig.json +6 -4
  24. package/css/miniboards.css +1 -0
  25. package/index.js +87 -78
  26. package/package.json +4 -4
  27. package/ui/game/PieceGraveyard.js +1 -1
  28. package/ui/game/chat.js +51 -0
  29. package/ui/game/gameHistory.js +5 -1
  30. package/ui/game/gameView.js +242 -269
  31. package/ui/miniboard/miniboard.js +8 -5
  32. package/ui/pageLayout/navigation.js +11 -7
  33. package/css/chessground-examples/gulpfile.js +0 -52
  34. package/css/chessground-examples/index.standalone.html +0 -17
  35. package/css/chessground-examples/yarn.lock +0 -3529
@@ -1,334 +1,307 @@
1
1
  const m = require('mithril');
2
- const { Chessground } = require('chessground');
2
+ const { Chessground } = require('@lichess-org/chessground');
3
3
  const PubSub = require('pubsub-js');
4
4
  const Value = require('mutant/value');
5
5
  const watchAll = require('mutant/watch-all');
6
6
  const computed = require('mutant/computed');
7
7
  const when = require('mutant/when');
8
8
  const { Howl } = require('howler');
9
+ const watch = require('mutant/watch');
9
10
 
10
- const EmbeddedChat = require('ssb-embedded-chat');
11
11
  const ActionButtons = require('./gameActions');
12
12
  const GameHistory = require('./gameHistory');
13
13
  const PromotionBox = require('./promote');
14
+ const ChatBox = require('./chat')
14
15
 
15
16
  const PieceGraveyard = require('./PieceGraveyard');
16
17
  const NextPreviousButtons = require('./nextGameControl');
17
18
 
18
- const pull = require('pull-stream')
19
+ function getInitialSituation(situationObservable) {
20
+ return new Promise((resolve, reject) => {
21
+ const w = watch(situationObservable, (situation) => {
22
+ if (situation) {
23
+ resolve(situation)
24
+
25
+ // hack: Keep the observable warm - the ssb-chess 'getSituationObservable' doesn't handle
26
+ // the observable having 0 listeners then 1 again - it aborts the underyling stream when it
27
+ // reaches 0 listeners but doesn't start it again if it reaches >= 1 again.
28
+ // TODO: fix this properly
29
+ setTimeout(w, 50000);
30
+ }
31
+ })
32
+ })
19
33
 
20
- module.exports = (dataAccess, gameCtrl, observables, settings) => {
21
- const myIdent = gameCtrl.getMyIdent();
34
+ }
22
35
 
23
- const { situationObservable, gamesWhereMyMove, observableGames } = observables;
36
+ module.exports = async (gameId, dataAccess, gameCtrl, observables, settings) => {
24
37
 
25
- let chessGround = null;
26
- const chessGroundObservable = Value();
38
+ const myIdent = gameCtrl.getMyIdent();
39
+ const { situationObservable, gamesWhereMyMove, observableGames } = observables;
40
+ const originalSituation = await getInitialSituation(situationObservable);
27
41
 
28
- const gameHistory = GameHistory(situationObservable, myIdent);
29
- const actionButtons = ActionButtons(
30
- gameCtrl.getMoveCtrl(),
31
- gameCtrl.getInviteCtrl(),
32
- myIdent,
33
- situationObservable,
34
- );
42
+ let chessGround = null;
43
+ const chessGroundObservable = Value();
35
44
 
36
- const gameHistoryObs = gameHistory.getMoveSelectedObservable();
45
+ const gameHistory = GameHistory(situationObservable, myIdent);
46
+ const actionButtons = ActionButtons(
47
+ gameCtrl.getMoveCtrl(),
48
+ gameCtrl.getInviteCtrl(),
49
+ myIdent,
50
+ situationObservable,
51
+ );
37
52
 
38
- const pieceGraveOpponent = PieceGraveyard(
39
- chessGroundObservable,
40
- situationObservable,
41
- gameHistoryObs,
42
- myIdent,
43
- false,
44
- );
53
+ const gameHistoryObs = gameHistory.getMoveSelectedObservable();
45
54
 
46
- const pieceGraveMe = PieceGraveyard(
47
- chessGroundObservable,
48
- situationObservable,
49
- gameHistoryObs,
50
- myIdent,
51
- true,
52
- );
55
+ const pieceGraveOpponent = PieceGraveyard(
56
+ chessGroundObservable,
57
+ situationObservable,
58
+ gameHistoryObs,
59
+ myIdent,
60
+ false,
61
+ );
53
62
 
54
- const nextPrevButtons = NextPreviousButtons(situationObservable, arrowScrollsThroughGameCollection());
63
+ const pieceGraveMe = PieceGraveyard(
64
+ chessGroundObservable,
65
+ situationObservable,
66
+ gameHistoryObs,
67
+ myIdent,
68
+ true,
69
+ );
55
70
 
56
- const rootDir = `${__dirname.replace('/ui/game', '')}/`;
71
+ const nextPrevButtons = NextPreviousButtons(situationObservable, arrowScrollsThroughGameCollection());
57
72
 
58
- const moveSound = new Howl({
59
- src: [`${rootDir}assets/sounds/Move.mp3`],
60
- });
73
+ const rootDir = `${__dirname.replace('/ui/game', '')}/`;
61
74
 
62
- const captureSound = new Howl({
63
- src: [`${rootDir}assets/sounds/Capture.mp3`],
64
- });
65
-
66
- function arrowScrollsThroughGameCollection() {
67
- const playerIsPlaying = computed([situationObservable], (situation) => situation.currentPlayerIsInGame());
75
+ const moveSound = new Howl({
76
+ src: [`${rootDir}assets/sounds/Move.mp3`],
77
+ });
68
78
 
69
- return when(playerIsPlaying,
70
- gamesWhereMyMove, observableGames
71
- );
72
- }
79
+ const captureSound = new Howl({
80
+ src: [`${rootDir}assets/sounds/Capture.mp3`],
81
+ });
73
82
 
74
- function plyToColourToPlay(ply) {
75
- return ply % 2 === 0 ? 'white' : 'black';
76
- }
83
+ function arrowScrollsThroughGameCollection() {
84
+ const playerIsPlaying = computed([situationObservable], (situation) => situation.currentPlayerIsInGame());
77
85
 
78
- function isPromotionMove(cg, dest) {
79
- return (dest[1] === '8' || dest[1] === '1')
80
- && cg.state.pieces[dest]
81
- && (cg.state.pieces[dest].role === 'pawn');
82
- }
83
-
84
- function renderBoard(gameId) {
85
- const chessDom = m('div', {
86
- class: 'cg-wrap ssb-chess-board-large',
87
- id: gameId,
88
- });
86
+ return when(playerIsPlaying,
87
+ gamesWhereMyMove, observableGames
88
+ );
89
+ }
90
+
91
+ function plyToColourToPlay(ply) {
92
+ return ply % 2 === 0 ? 'white' : 'black';
93
+ }
94
+
95
+ function isPromotionMove(cg, dest) {
96
+ return (dest[1] === '8' || dest[1] === '1')
97
+ && cg.state.pieces.get(dest)
98
+ && (cg.state.pieces.get(dest).role === 'pawn');
99
+ }
100
+
101
+ function renderBoard(gameId) {
102
+ const chessDom = m('div', {
103
+ class: 'cg-wrap ssb-chess-board-large',
104
+ id: gameId,
105
+ });
89
106
 
90
- return m('div', { class: 'ssb-chess-board-area' }, [
91
- chessDom,
92
- m(nextPrevButtons)
93
- ]);
107
+ return m('div', { class: 'ssb-chess-board-area' }, [
108
+ chessDom,
109
+ m(nextPrevButtons)
110
+ ]);
111
+ }
112
+
113
+ function setNotMovable(conf) {
114
+ conf.movable = {};
115
+ conf.movable.color = null;
116
+ }
117
+
118
+ function watchForMoveConfirmation(situation, onConfirm, validMoves) {
119
+ if (!settings.getMoveConfirmation()) {
120
+ // If move confirmation is not enabled, perform the move immediately
121
+ onConfirm();
122
+ return;
94
123
  }
95
124
 
96
- function renderChat(gameId) {
97
- return m('div', {
98
- class: 'ssb-chess-chat',
99
- id: `chat-${gameId}`,
100
- });
101
- }
125
+ const confirmedObs = actionButtons.showMoveConfirmation();
126
+ m.redraw();
102
127
 
103
- function setNotMovable(conf) {
104
- conf.movable = {};
105
- conf.movable.color = null;
106
- }
128
+ const watches = computed(
129
+ [confirmedObs, gameHistory.getMoveSelectedObservable()],
130
+ (confirmed, moveSelected) => ({
131
+ moveConfirmed: confirmed,
132
+ moveSelected,
133
+ }),
134
+ );
107
135
 
108
- function watchForMoveConfirmation(situation, onConfirm, validMoves) {
109
- if (!settings.getMoveConfirmation()) {
110
- // If move confirmation is not enabled, perform the move immediately
136
+ const removeConfirmationListener = watches((value) => {
137
+ if (value.moveConfirmed.confirmed) {
111
138
  onConfirm();
112
- return;
113
- }
139
+ } else if (value.moveSelected !== 'live' || value.moveConfirmed.confirmed === false) {
140
+ const oldConfig = situationToChessgroundConfig(situation, 'live', validMoves);
114
141
 
115
- const confirmedObs = actionButtons.showMoveConfirmation();
116
- m.redraw();
117
-
118
- const watches = computed(
119
- [confirmedObs, gameHistory.getMoveSelectedObservable()],
120
- (confirmed, moveSelected) => ({
121
- moveConfirmed: confirmed,
122
- moveSelected,
123
- }),
124
- );
125
-
126
- const removeConfirmationListener = watches((value) => {
127
- if (value.moveConfirmed.confirmed) {
128
- onConfirm();
129
- } else if (value.moveSelected !== 'live' || value.moveConfirmed.confirmed === false) {
130
- const oldConfig = situationToChessgroundConfig(situation, 'live', validMoves);
131
-
132
- if (value.moveSelected === 'live') {
133
- chessGround.set(oldConfig);
134
- }
142
+ if (value.moveSelected === 'live') {
143
+ chessGround.set(oldConfig);
135
144
  }
145
+ }
136
146
 
137
- removeConfirmationListener();
138
- actionButtons.hideMoveConfirmation();
139
- });
140
- }
141
-
142
- function situationToChessgroundConfig(situation, moveSelected, validMoves) {
143
- const playerColour = situation.players[myIdent] ? situation.players[myIdent].colour : 'white';
144
-
145
- const colourToPlay = plyToColourToPlay(situation.ply);
146
-
147
- const config = {
148
- fen: situation.fen,
149
- orientation: playerColour,
150
- turnColor: colourToPlay,
151
- ply: situation.ply,
152
- check: situation.check,
153
- movable: {
154
- dests: validMoves,
155
- free: false,
156
- color: situation.toMove === myIdent ? playerColour : null,
157
- events: {
158
- after: (orig, dest) => {
159
- if (isPromotionMove(chessGround, dest)) {
160
- const chessboardDom = document.getElementsByClassName('cg-wrap')[0];
161
-
162
- PromotionBox(chessboardDom, colourToPlay, dest[0],
163
- (promotingToPiece) => {
164
- const onConfirmMove = () => gameCtrl.getMoveCtrl().makeMove(
165
- situation.gameId,
166
- orig,
167
- dest,
168
- promotingToPiece,
169
- );
170
- watchForMoveConfirmation(situation, onConfirmMove);
171
- }).renderPromotionOptionsOverlay();
172
- } else {
173
- const onConfirmMove = () => {
174
- gameCtrl.getMoveCtrl().makeMove(situation.gameId, orig, dest);
175
- };
176
-
177
- watchForMoveConfirmation(situation, onConfirmMove, validMoves);
178
- }
179
-
180
- const notMovable = {
181
- check: false,
182
- movable: {
183
- color: null,
184
- },
147
+ removeConfirmationListener();
148
+ actionButtons.hideMoveConfirmation();
149
+ });
150
+ }
151
+
152
+ function situationToChessgroundConfig(situation, moveSelected, validMoves) {
153
+ const ended = ["mate", "draw", "resigned"].indexOf(situation.status.status) !== -1;
154
+
155
+ const playerColour = situation.players[myIdent] ? situation.players[myIdent].colour : 'white';
156
+
157
+ const colourToPlay = plyToColourToPlay(situation.ply);
158
+
159
+ const config = {
160
+ viewOnly: ended,
161
+ fen: situation.fen,
162
+ orientation: playerColour,
163
+ turnColor: colourToPlay,
164
+ ply: situation.ply,
165
+ check: situation.check,
166
+ movable: {
167
+ dests: new Map(Object.entries(validMoves)),
168
+ free: false,
169
+ color: situation.toMove === myIdent ? playerColour : null,
170
+ events: {
171
+ after: (orig, dest) => {
172
+ if (isPromotionMove(chessGround, dest)) {
173
+ const chessboardDom = document.getElementsByClassName('cg-wrap')[0];
174
+
175
+ PromotionBox(chessboardDom, colourToPlay, dest[0],
176
+ (promotingToPiece) => {
177
+ const onConfirmMove = () => gameCtrl.getMoveCtrl().makeMove(
178
+ situation.gameId,
179
+ orig,
180
+ dest,
181
+ promotingToPiece,
182
+ );
183
+ watchForMoveConfirmation(situation, onConfirmMove);
184
+ }).renderPromotionOptionsOverlay();
185
+ } else {
186
+ const onConfirmMove = () => {
187
+ gameCtrl.getMoveCtrl().makeMove(situation.gameId, orig, dest);
185
188
  };
186
189
 
187
- chessGround.set(notMovable);
188
- },
189
- },
190
- },
191
- };
190
+ watchForMoveConfirmation(situation, onConfirmMove, validMoves);
191
+ }
192
192
 
193
- if (situation.lastMove) {
194
- config.lastMove = [situation.lastMove.orig, situation.lastMove.dest];
195
- }
193
+ const notMovable = {
194
+ check: false,
195
+ movable: {
196
+ color: null,
197
+ },
198
+ };
196
199
 
197
- if (moveSelected !== 'live') {
198
- resetConfigToOlderPosition(situation, config, moveSelected);
199
- }
200
+ chessGround.set(notMovable);
201
+ },
202
+ },
203
+ },
204
+ };
200
205
 
201
- return config;
206
+ if (situation.lastMove) {
207
+ config.lastMove = [situation.lastMove.orig, situation.lastMove.dest];
202
208
  }
203
209
 
204
- function resetConfigToOlderPosition(newSituation, newConfig, moveNumber) {
205
- setNotMovable(newConfig);
206
- newConfig.fen = newSituation.fenHistory[moveNumber];
207
-
208
- if (moveNumber > 0) {
209
- newConfig.lastMove = [
210
- newSituation.origDests[moveNumber - 1].orig,
211
- newSituation.origDests[moveNumber - 1].dest,
212
- ];
213
- } else {
214
- newConfig.lastMove = null;
215
- }
216
-
217
- const colourToPlay = plyToColourToPlay(moveNumber);
218
- newConfig.turnColor = colourToPlay;
219
-
220
- newConfig.check = newSituation.isCheckOnMoveNumber(moveNumber);
210
+ if (moveSelected !== 'live') {
211
+ resetConfigToOlderPosition(situation, config, moveSelected);
221
212
  }
222
213
 
223
- function makeEmbeddedChat(situation) {
224
- const config = {
225
- rootMessageId: situation.gameId,
226
- chatMessageType: 'chess_chat',
227
- chatMessageField: 'msg',
228
- chatboxEnabled: true,
229
- previousChatId: situation.rematchFrom
230
- };
231
-
232
- if (situation.players[myIdent] != null) {
233
- config.isPublic = false;
234
- config.participants = Object.keys(situation.players);
235
- } else {
236
- config.isPublic = true;
237
- }
238
-
239
- config.publishPublic = dataAccess.publishPublicChessMessage.bind(dataAccess);
240
- config.publishPrivate = dataAccess.publishPrivateChessMessage.bind(dataAccess);
214
+ return config;
215
+ }
241
216
 
242
- config.getChatStream = (gameId, live) =>
243
- pull(dataAccess.allGameMessages(gameId, live), pull.filter(msg => !msg.sync && msg.value && msg.value.content.type == "chess_chat"));
217
+ function resetConfigToOlderPosition(newSituation, newConfig, moveNumber) {
218
+ setNotMovable(newConfig);
219
+ newConfig.fen = newSituation.fenHistory[moveNumber];
244
220
 
245
- config.aboutSelfChangeStream = (since) => dataAccess.aboutSelfChangesUserIds(since);
246
-
247
- config.getDisplayName = (id, cb) => dataAccess.getPlayerDisplayName(id, cb);
221
+ if (moveNumber > 0) {
222
+ newConfig.lastMove = [
223
+ newSituation.origDests[moveNumber - 1].orig,
224
+ newSituation.origDests[moveNumber - 1].dest,
225
+ ];
226
+ } else {
227
+ newConfig.lastMove = null;
228
+ }
248
229
 
249
- const chat = EmbeddedChat(config);
230
+ const colourToPlay = plyToColourToPlay(moveNumber);
231
+ newConfig.turnColor = colourToPlay;
250
232
 
251
- return chat;
252
- }
233
+ newConfig.check = newSituation.isCheckOnMoveNumber(moveNumber);
234
+ }
253
235
 
254
- function playMoveSound(situation, newConfig, cg, moveSelected) {
255
- if (newConfig.fen !== cg.state.fen && moveSelected !== 0) {
256
- const pgnMove = moveSelected === 'live' ? situation.pgnMoves[
257
- situation.pgnMoves.length - 1] : situation.pgnMoves[moveSelected - 1];
236
+ function playMoveSound(situation, newConfig, cg, moveSelected) {
237
+ if (newConfig.fen !== cg.state.fen && moveSelected !== 0) {
238
+ const pgnMove = moveSelected === 'live' ? situation.pgnMoves[
239
+ situation.pgnMoves.length - 1] : situation.pgnMoves[moveSelected - 1];
258
240
 
259
- // Hacky way of determining if it's a capture move.
260
- if (pgnMove.indexOf('x') !== -1) {
261
- captureSound.play();
262
- } else {
263
- moveSound.play();
264
- }
241
+ // Hacky way of determining if it's a capture move.
242
+ if (pgnMove.indexOf('x') !== -1) {
243
+ captureSound.play();
244
+ } else {
245
+ moveSound.play();
265
246
  }
266
247
  }
248
+ }
267
249
 
268
- return {
269
-
270
- view(ctrl) {
271
- const gameId = atob(ctrl.attrs.gameId);
272
-
273
- return m('div', {
274
- class: 'ssb-chess-board-background-blue3 merida ssb-chess-game-layout',
275
- }, [renderChat(gameId), renderBoard(gameId),
276
- m('div', { class: 'ssb-chess-history-area' }, [
277
- m(pieceGraveOpponent),
278
- m(gameHistory),
279
- m(actionButtons),
280
- m(pieceGraveMe)
281
- ])]);
282
- },
283
- oncreate(vNode) {
284
- const gameId = atob(vNode.attrs.gameId);
285
- const boardDom = document.getElementById(gameId);
286
- const chatDom = document.getElementById(`chat-${gameId}`);
250
+ const Chat = ChatBox(myIdent, dataAccess, originalSituation);
287
251
 
288
- const originalSituation = situationObservable();
252
+ return {
289
253
 
290
- const config = situationToChessgroundConfig(originalSituation, 'live', {});
291
- chessGround = Chessground(boardDom, config);
292
- chessGroundObservable.set(chessGround);
254
+ view(ctrl) {
293
255
 
294
- this.embeddedChat = makeEmbeddedChat(originalSituation);
295
- chatDom.appendChild(this.embeddedChat.getChatboxElement());
296
-
297
- const validMovesObservable = gameCtrl.getMovesFinderCtrl()
298
- .validMovesForSituationObs(situationObservable);
299
-
300
- this.removeWatches = watchAll([situationObservable,
301
- gameHistory.getMoveSelectedObservable(), validMovesObservable],
302
- (newSituation, moveSelected, validMoves) => {
303
- const newConfig = situationToChessgroundConfig(newSituation, moveSelected, validMoves);
304
-
305
- if (settings.getPlaySounds()) {
306
- playMoveSound(newSituation, newConfig, chessGround, moveSelected);
307
- }
308
-
309
- chessGround.set(newConfig);
310
- });
256
+ return m('div', {
257
+ class: 'ssb-chess-board-background-blue3 merida ssb-chess-game-layout',
258
+ }, [m(Chat), renderBoard(gameId),
259
+ m('div', { class: 'ssb-chess-history-area' }, [
260
+ m(pieceGraveOpponent),
261
+ m(gameHistory),
262
+ m(actionButtons),
263
+ m(pieceGraveMe)
264
+ ])]);
265
+ },
266
+ oncreate(vNode) {
267
+ const boardDom = document.getElementById(gameId);
268
+
269
+ const config = situationToChessgroundConfig(originalSituation, 'live', {});
270
+ chessGround = Chessground(boardDom, config);
271
+
272
+ chessGroundObservable.set(chessGround);
273
+
274
+ const validMovesObservable = gameCtrl.getMovesFinderCtrl()
275
+ .validMovesForSituationObs(situationObservable);
276
+
277
+ this.removeWatches = watchAll([situationObservable,
278
+ gameHistory.getMoveSelectedObservable(), validMovesObservable],
279
+ (newSituation, moveSelected, validMoves) => {
280
+ const newConfig = situationToChessgroundConfig(newSituation, moveSelected, validMoves);
281
+
282
+ if (settings.getPlaySounds()) {
283
+ playMoveSound(newSituation, newConfig, chessGround, moveSelected);
284
+ }
311
285
 
312
- PubSub.publish('viewing_game', {
313
- gameId,
286
+ chessGround.set(newConfig);
314
287
  });
315
- },
316
- onremove() {
317
- if (this.removeWatches) {
318
- this.removeWatches();
319
- }
320
288
 
321
- if (chessGround) {
322
- // Yuck. This has been null for people at this stage before. Perhaps onremove
323
- // can be called before oncreate in edge cases?
324
- chessGround.destroy();
325
- }
289
+ PubSub.publish('viewing_game', {
290
+ gameId,
291
+ });
292
+ },
293
+ onremove() {
294
+ if (this.removeWatches) {
295
+ this.removeWatches();
296
+ }
326
297
 
327
- if (this.embeddedChat) {
328
- this.embeddedChat.destroy();
329
- }
298
+ if (chessGround) {
299
+ // Yuck. This has been null for people at this stage before. Perhaps onremove
300
+ // can be called before oncreate in edge cases?
301
+ chessGround.destroy();
302
+ }
330
303
 
331
- PubSub.publish('exited_game');
332
- },
333
- };
304
+ PubSub.publish('exited_game');
305
+ },
334
306
  };
307
+ };
@@ -1,5 +1,5 @@
1
1
  const m = require('mithril');
2
- const { Chessground } = require('chessground');
2
+ const { Chessground } = require('@lichess-org/chessground');
3
3
  const timeAgo = require('./timeAgo');
4
4
 
5
5
  module.exports = (gameSummaryObservable, summary, identPerspective, opts) => {
@@ -13,9 +13,10 @@ module.exports = (gameSummaryObservable, summary, identPerspective, opts) => {
13
13
  && summary.players[identPerspective].colour) ? summary.players[identPerspective].colour : 'white';
14
14
 
15
15
  function renderPlayerName(player) {
16
- return m(`a[href=/player/${btoa(player.id)}]`, {
16
+ const link = `/player/${btoa(player.id)}`;
17
+ return m(m.route.Link, {
17
18
  class: 'ssb-chess-miniboard-name',
18
- oncreate: m.route.link,
19
+ href: link,
19
20
  },
20
21
  player.name.substring(0, 10));
21
22
  }
@@ -48,14 +49,16 @@ module.exports = (gameSummaryObservable, summary, identPerspective, opts) => {
48
49
  const observing = Object.keys(summary.players).indexOf(identPerspective) === -1;
49
50
  const boardSizeClass = opts && opts.small ? 'ssb-chess-board-small' : 'ssb-chess-board-medium';
50
51
 
52
+ const link = `/games/${btoa(summary.gameId)}?observing=${observing}`;
53
+
51
54
  return m('div', {
52
55
  class: 'ssb-chess-miniboard ssb-chess-board-background-blue3 merida',
53
56
  }, [
54
- m(`${'a[href=/games/'}${btoa(summary.gameId)}?observing=${observing}]`, {
57
+ m(m.route.Link, {
55
58
  class: `ssb-chessground-container cg-wrap ${boardSizeClass}`,
56
59
  title: summary.gameId,
57
60
  id: summary.gameId,
58
- oncreate: m.route.link,
61
+ href: link,
59
62
  }), renderSummaryBottom(),
60
63
  ]);
61
64
  }
@@ -2,7 +2,7 @@ const m = require('mithril');
2
2
  const SettingsDialog = require('../settings/settings-dialog');
3
3
 
4
4
  module.exports = (mainCtrl, settings) => {
5
- m.route.prefix('?');
5
+ m.route.prefix = '?';
6
6
 
7
7
  const gamesInProgress = {
8
8
  name: 'Games',
@@ -45,8 +45,8 @@ module.exports = (mainCtrl, settings) => {
45
45
  function renderNavItem(navItem) {
46
46
  return m('span', {
47
47
  class: 'ssb-chess-nav-item',
48
- }, m(`a[href=${navItem.link}]`, {
49
- oncreate: m.route.link,
48
+ }, m(m.route.Link, {
49
+ href: navItem.link,
50
50
  title: navItem.countHoverText(),
51
51
  },
52
52
 
@@ -89,24 +89,28 @@ module.exports = (mainCtrl, settings) => {
89
89
  }
90
90
 
91
91
  function keepCountsUpdated() {
92
- navItems.forEach((navItem) => {
92
+ const watches = navItems.map((navItem) => {
93
93
  if (navItem.countUpdateFn) {
94
- navItem.countUpdateFn()((items) => {
94
+ return navItem.countUpdateFn()((items) => {
95
95
  const numItems = items.length;
96
96
  navItem.count = numItems;
97
97
  m.redraw();
98
98
  });
99
+ } else {
100
+ return () => {}
99
101
  }
100
102
  });
103
+
104
+ return watches;
101
105
  }
102
106
 
103
107
  return {
104
108
  view: () => renderNavigation(),
105
109
  oncreate: () => {
106
- keepCountsUpdated();
110
+ this.watches = keepCountsUpdated();
107
111
  },
108
112
  onremove: () => {
109
-
113
+ this.watches.forEach(watch => watch());
110
114
  },
111
115
  };
112
116
  };