2020-09-22 00:56:13 -06:00
|
|
|
|
import { Controller, Puzzle, PuzzleGame, MaybeVNode } from '../interfaces';
|
|
|
|
|
import { dataIcon } from '../util';
|
2020-11-12 01:11:25 -07:00
|
|
|
|
import { h } from 'snabbdom';
|
2020-09-12 02:13:01 -06:00
|
|
|
|
import { numberFormat } from 'common/number';
|
2020-09-22 00:56:13 -06:00
|
|
|
|
import { VNode } from 'snabbdom/vnode';
|
2017-07-03 05:52:21 -06:00
|
|
|
|
|
2020-01-02 08:51:13 -07:00
|
|
|
|
export function puzzleBox(ctrl: Controller): VNode {
|
2017-07-03 05:52:21 -06:00
|
|
|
|
var data = ctrl.getData();
|
2019-02-14 21:04:24 -07:00
|
|
|
|
return h('div.puzzle__side__metas', [
|
2017-07-03 05:52:21 -06:00
|
|
|
|
puzzleInfos(ctrl, data.puzzle),
|
2019-02-14 21:04:24 -07:00
|
|
|
|
gameInfos(ctrl, data.game, data.puzzle)
|
|
|
|
|
]);
|
2017-07-03 05:52:21 -06:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-11 00:58:13 -06:00
|
|
|
|
function puzzleInfos(ctrl: Controller, puzzle: Puzzle): VNode {
|
2019-02-14 21:04:24 -07:00
|
|
|
|
return h('div.infos.puzzle', {
|
2017-07-03 05:52:21 -06:00
|
|
|
|
attrs: dataIcon('-')
|
2019-02-14 21:04:24 -07:00
|
|
|
|
}, [h('div', [
|
2019-08-16 05:52:10 -06:00
|
|
|
|
h('p', ctrl.trans.vdom('ratingX', ctrl.vm.mode === 'play' ? h('span.hidden', ctrl.trans.noarg('hidden')) : h('strong', puzzle.rating))),
|
2020-11-12 01:11:25 -07:00
|
|
|
|
h('p', ctrl.trans.vdom('playedXTimes', h('strong', numberFormat(puzzle.plays))))
|
2019-02-14 21:04:24 -07:00
|
|
|
|
])]);
|
2017-07-03 05:52:21 -06:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-11 00:58:13 -06:00
|
|
|
|
function gameInfos(ctrl: Controller, game: PuzzleGame, puzzle: Puzzle): VNode {
|
2019-02-14 21:04:24 -07:00
|
|
|
|
return h('div.infos', {
|
|
|
|
|
attrs: dataIcon(game.perf.icon)
|
|
|
|
|
}, [h('div', [
|
2019-08-16 05:21:06 -06:00
|
|
|
|
h('p', ctrl.trans.vdom('fromGameLink', h('a', {
|
2020-11-12 01:11:25 -07:00
|
|
|
|
attrs: { href: `/${game.id}/${ctrl.vm.pov}#${puzzle.initialPly}` }
|
2019-08-16 05:21:06 -06:00
|
|
|
|
}, '#' + game.id))),
|
2019-02-14 21:04:24 -07:00
|
|
|
|
h('p', [
|
|
|
|
|
game.clock, ' • ',
|
|
|
|
|
game.perf.name, ' • ',
|
|
|
|
|
ctrl.trans.noarg(game.rated ? 'rated' : 'casual')
|
2017-07-03 05:52:21 -06:00
|
|
|
|
]),
|
|
|
|
|
h('div.players', game.players.map(function(p) {
|
|
|
|
|
return h('div.player.color-icon.is.text.' + p.color,
|
2019-04-08 03:19:22 -06:00
|
|
|
|
p.userId ? h('a.user-link.ulpt', {
|
2017-07-03 05:52:21 -06:00
|
|
|
|
attrs: { href: '/@/' + p.userId }
|
|
|
|
|
}, p.name) : p.name
|
|
|
|
|
);
|
|
|
|
|
}))
|
2019-02-14 21:04:24 -07:00
|
|
|
|
])]);
|
2017-07-03 05:52:21 -06:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-02 08:51:13 -07:00
|
|
|
|
export function userBox(ctrl: Controller): MaybeVNode {
|
2017-07-03 06:30:50 -06:00
|
|
|
|
const data = ctrl.getData();
|
2017-07-03 05:52:21 -06:00
|
|
|
|
if (!data.user) return;
|
2020-11-22 11:34:10 -07:00
|
|
|
|
const diff = ctrl.vm.round?.ratingDiff;
|
2019-02-14 21:04:24 -07:00
|
|
|
|
return h('div.puzzle__side__user', [
|
2019-08-16 05:21:06 -06:00
|
|
|
|
h('h2', ctrl.trans.vdom('yourPuzzleRatingX', h('strong', [
|
|
|
|
|
data.user.rating,
|
2020-11-22 11:34:10 -07:00
|
|
|
|
...(diff && diff > 0 ? [' ', h('good.rp', '+' + diff)] : []),
|
|
|
|
|
...(diff && diff < 0 ? [' ', h('bad.rp', '−' + (-diff))] : [])
|
2020-11-12 01:11:25 -07:00
|
|
|
|
])))
|
2017-07-03 05:52:21 -06:00
|
|
|
|
]);
|
|
|
|
|
}
|