bind fewer events on homepage

pull/4065/head
Thibault Duplessis 2018-02-24 17:45:26 -06:00
parent 98346bfa9b
commit 5e9cbe79b1
2 changed files with 21 additions and 8 deletions

View File

@ -1,17 +1,19 @@
import { h } from 'snabbdom';
import { VNodeData } from 'snabbdom/vnode';
import renderTabs from './tabs';
import renderPools from './pools';
import * as renderPools from './pools';
import renderRealTime from './realTime/main';
import renderSeeks from './correspondence';
import renderPlaying from './playing';
import LobbyController from '../ctrl';
export default function(ctrl: LobbyController) {
let body;
let body, data: VNodeData = {};
if (ctrl.playban || ctrl.currentGame) return h('div#hooks_wrap');
switch (ctrl.tab) {
case 'pools':
body = renderPools(ctrl);
body = renderPools.render(ctrl);
data = { hook: renderPools.hooks(ctrl) };
break;
case 'real_time':
body = renderRealTime(ctrl);
@ -23,8 +25,9 @@ export default function(ctrl: LobbyController) {
body = renderPlaying(ctrl);
break;
}
console.log(data);
return h('div#hooks_wrap', [
h('div.tabs', renderTabs(ctrl)),
h('div.lobby_box.' + ctrl.tab, body)
h('div.lobby_box.' + ctrl.tab, data, body)
]);
};

View File

@ -1,4 +1,5 @@
import { h } from 'snabbdom';
import { Hooks } from 'snabbdom/hooks'
import LobbyController from '../ctrl';
import { bind, spinner } from './util';
@ -6,9 +7,18 @@ function renderRange(range: string) {
return h('div.range', range.replace('-', ''));
}
export default function(ctrl: LobbyController) {
export function hooks(ctrl: LobbyController): Hooks {
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') $('#start_buttons .config_hook').mousedown();
else id && ctrl.clickPool(id);
}, ctrl.redraw);
}
export function render(ctrl: LobbyController) {
const member = ctrl.poolMember;
return ctrl.pools.map(function(pool) {
return ctrl.pools.map(pool => {
const active = !!member && member.id === pool.id,
transp = !!member && !active;
return h('div.pool', {
@ -16,7 +26,7 @@ export default function(ctrl: LobbyController) {
active,
transp: !active && transp
},
hook: bind('click', _ => ctrl.clickPool(pool.id), ctrl.redraw)
attrs: { 'data-id': pool.id }
}, [
h('div.clock', pool.lim + '+' + pool.inc),
(active && member!.range) ? renderRange(member!.range!) : h('div.perf', pool.perf),
@ -25,7 +35,7 @@ export default function(ctrl: LobbyController) {
}).concat(
h('div.custom', {
class: { transp: !!member },
hook: bind('click', _ => $('#start_buttons .config_hook').mousedown())
attrs: { 'data-id': 'custom' }
}, ctrl.trans.noarg('custom'))
);
}