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';
|
2017-07-04 08:26:14 -06:00
|
|
|
|
import LobbyController from '../ctrl';
|
|
|
|
|
|
2017-07-14 03:04:34 -06:00
|
|
|
|
function renderRange(range: string) {
|
2018-02-15 18:02:14 -07:00
|
|
|
|
return h('div.range', range.replace('-', '–'));
|
2017-07-04 08:26:14 -06:00
|
|
|
|
}
|
|
|
|
|
|
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) {
|
2017-07-04 08:26:14 -06:00
|
|
|
|
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),
|
2021-12-08 19:22:42 -07:00
|
|
|
|
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')
|
|
|
|
|
)
|
|
|
|
|
);
|
2017-07-04 08:26:14 -06:00
|
|
|
|
}
|