join and cancel seeks
This commit is contained in:
parent
85f87f19b6
commit
bd838686be
|
@ -12,7 +12,7 @@ module.exports = function(env) {
|
|||
this.data = env.data;
|
||||
this.data.hooks.forEach(hookRepo.init);
|
||||
hookRepo.sort(this);
|
||||
this.data.seeks.forEach(seekRepo.init);
|
||||
this.data.seeks.forEach(util.partial(seekRepo.init, this));
|
||||
seekRepo.sort(this);
|
||||
|
||||
this.socket = new socket(env.socketSend, this);
|
||||
|
@ -47,6 +47,7 @@ module.exports = function(env) {
|
|||
this.setTab = function(tab) {
|
||||
if (tab === 'seeks' && tab !== this.vm.tab) xhr.seeks().then(this.setSeeks);
|
||||
this.vm.tab = store.tab.set(tab);
|
||||
this.vm.filter.open = false;
|
||||
}.bind(this);
|
||||
|
||||
this.setMode = function(mode) {
|
||||
|
@ -66,20 +67,18 @@ module.exports = function(env) {
|
|||
if (this.vm.stepping) return;
|
||||
var hook = hookRepo.find(this, id);
|
||||
if (!hook || hook.disabled) return;
|
||||
console.log(hook);
|
||||
// if (hook.action === 'cancel' || variant.confirm(hook.variant)) this.socket.send(hook.action, hook.id);
|
||||
if (hook.action === 'cancel' || variant.confirm(hook.variant)) this.socket.send(hook.action, hook.id);
|
||||
}.bind(this);
|
||||
|
||||
this.clickSeek = function(id) {
|
||||
var seek = seekRepo.find(this, id);
|
||||
if (!seek) return;
|
||||
console.log(seek);
|
||||
// if (hook.action === 'cancel' || variant.confirm(hook.variant)) this.socket.send(hook.action, hook.id);
|
||||
if (seek.action === 'cancelSeek' || variant.confirm(seek.variant)) this.socket.send(seek.action, seek.id);
|
||||
}.bind(this);
|
||||
|
||||
this.setSeeks = function(seeks) {
|
||||
this.data.seeks = seeks;
|
||||
this.data.seeks.forEach(seekRepo.init);
|
||||
this.data.seeks.forEach(util.partial(seekRepo.init, this));
|
||||
seekRepo.sort(this);
|
||||
}.bind(this);
|
||||
|
||||
|
|
|
@ -10,8 +10,8 @@ function fixBC(seek) {
|
|||
seek.mode = seek.mode === 'Casual' ? 0 : 1;
|
||||
}
|
||||
|
||||
function init(seek) {
|
||||
seek.action = seek.uid === lichess.socket.settings.params.sri ? 'cancelSeek' : 'joinSeek';
|
||||
function init(ctrl, seek) {
|
||||
seek.action = (ctrl.data.me && seek.username === ctrl.data.me.username) ? 'cancelSeek' : 'joinSeek';
|
||||
fixBC(seek);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ function renderSeek(ctrl, seek) {
|
|||
key: seek.id,
|
||||
title: (seek.action === 'joinSeek') ? ctrl.trans('joinTheGame') + ' - ' + seek.perf.name : ctrl.trans('cancel'),
|
||||
'data-id': seek.id,
|
||||
class: 'seek ' + seek.action
|
||||
class: 'seek ' + (seek.action === 'joinSeek' ? 'join' : 'cancel')
|
||||
}, tds([
|
||||
m('span', {
|
||||
class: 'is is2 color-icon ' + (seek.color || 'random')
|
||||
|
@ -40,8 +40,8 @@ module.exports = function(ctrl) {
|
|||
do {
|
||||
el = el.parentNode;
|
||||
if (el.nodeName === 'TR') {
|
||||
if (!this.data.me) {
|
||||
if (confirm(this.trans('youNeedAnAccountToDoThat'))) location.href = '/signup';
|
||||
if (!ctrl.data.me) {
|
||||
if (confirm(ctrl.trans('youNeedAnAccountToDoThat'))) location.href = '/signup';
|
||||
return;
|
||||
}
|
||||
return ctrl.clickSeek(el.getAttribute('data-id'));
|
||||
|
|
Loading…
Reference in a new issue