lila/ui/puzzle/src/view/side.ts

58 lines
1.9 KiB
TypeScript
Raw Normal View History

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';
import { VNode } from 'snabbdom/vnode';
2020-01-02 08:51:13 -07:00
export function puzzleBox(ctrl: Controller): VNode {
var data = ctrl.getData();
2019-02-14 21:04:24 -07:00
return h('div.puzzle__side__metas', [
puzzleInfos(ctrl, data.puzzle),
2019-02-14 21:04:24 -07:00
gameInfos(ctrl, data.game, data.puzzle)
]);
}
function puzzleInfos(ctrl: Controller, puzzle: Puzzle): VNode {
2019-02-14 21:04:24 -07:00
return h('div.infos.puzzle', {
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
])]);
}
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', [
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}` }
}, '#' + game.id))),
2019-02-14 21:04:24 -07:00
h('p', [
game.clock, ' • ',
game.perf.name, ' • ',
ctrl.trans.noarg(game.rated ? 'rated' : 'casual')
]),
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', {
attrs: { href: '/@/' + p.userId }
}, p.name) : p.name
);
}))
2019-02-14 21:04:24 -07: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();
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', [
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
])))
]);
}