join and cancel seeks

This commit is contained in:
Thibault Duplessis 2014-12-28 19:01:48 +01:00
parent 85f87f19b6
commit bd838686be
3 changed files with 10 additions and 11 deletions

View file

@ -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);

View file

@ -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);
}

View file

@ -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'));