lila/ui/lobby/src/view/pools.ts

57 lines
1.4 KiB
TypeScript
Raw Normal View History

2021-04-05 01:10:35 -06:00
import { h, Hooks } from 'snabbdom';
2021-08-21 06:27:23 -06:00
import spinner from 'common/spinner';
import { bind } from 'common/snabbdom';
import LobbyController from '../ctrl';
2017-07-14 03:04:34 -06:00
function renderRange(range: string) {
return h('div.range', range.replace('-', ''));
}
2018-02-24 16:45:26 -07:00
export function hooks(ctrl: LobbyController): Hooks {
2021-02-06 06:26:05 -07:00
return bind(
'click',
e => {
const id =
(e.target as HTMLElement).getAttribute('data-id') ||
((e.target as HTMLElement).parentNode as HTMLElement).getAttribute('data-id');
if (id === 'custom') $('.config_hook').trigger('mousedown');
else if (id) ctrl.clickPool(id);
},
ctrl.redraw
);
2018-02-24 16:45:26 -07:00
}
export function render(ctrl: LobbyController) {
const member = ctrl.poolMember;
2021-02-06 06:26:05 -07:00
return ctrl.pools
.map(pool => {
const active = !!member && member.id === pool.id,
transp = !!member && !active;
return h(
'div',
{
class: {
active,
transp: !active && transp,
},
attrs: { 'data-id': pool.id },
},
[
h('div.clock', pool.lim + '+' + pool.inc),
active && member!.range && ctrl.opts.showRatings ? renderRange(member!.range!) : h('div.perf', pool.perf),
2021-02-06 06:26:05 -07:00
active ? spinner() : null,
]
);
})
.concat(
h(
'div.custom',
{
class: { transp: !!member },
attrs: { 'data-id': 'custom' },
},
ctrl.trans.noarg('custom')
)
);
}