migrate ui/puzzle to vdom-only mithril

pull/2713/merge
Thibault Duplessis 2017-03-08 15:02:44 +01:00
parent 801bf548bf
commit 29a5a93e5a
5 changed files with 30 additions and 49 deletions

View File

@ -81,7 +81,7 @@ object Puzzle extends LilaController {
renderJson(puzzle, infos, ctx.isAuth.fold("play", "try"), voted = none) map { json =>
Ok(json) as JSON
}
} map (_ as JSON)
}
}
}

View File

@ -31,7 +31,6 @@
},
"dependencies": {
"common": "file:../common",
"chess": "file:../chess",
"mithril": "github:ornicar/mithril.js#lila-1"
"chess": "file:../chess"
}
}

View File

@ -35,6 +35,6 @@
"chess": "file:../chess",
"tree": "file:../tree",
"ceval": "file:../ceval",
"mithril": "github:ornicar/mithril.js#lila-1"
"mithril": "github:ornicar/mithril.js#lila-vdom-only-1"
}
}

View File

@ -223,7 +223,8 @@ module.exports = function(opts, i18n) {
var nextPuzzle = function() {
ceval.stop();
vm.loading = true;
xhr.nextPuzzle().then(function(d) {
m.redraw();
xhr.nextPuzzle().done(function(d) {
vm.round = null;
vm.loading = false;
initiate(d);

View File

@ -1,48 +1,29 @@
var m = require('mithril');
var xhrConfig = function(xhr) {
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
}
function uncache(url) {
return url + '?_=' + new Date().getTime();
}
function round(puzzleId, win) {
return m.request({
method: 'POST',
url: '/training/' + puzzleId + '/round2',
data: {
win: win ? 1 : 0
},
config: xhrConfig,
background: true
});
}
function vote(puzzleId, v) {
return m.request({
method: 'POST',
url: '/training/' + puzzleId + '/vote',
data: {
vote: v ? 1 : 0
},
config: xhrConfig,
background: true
});
}
function nextPuzzle() {
return m.request({
method: 'GET',
url: uncache('/training/new'),
config: xhrConfig,
background: true
});
}
// do NOT set mobile API headers here
// they trigger a compat layer
module.exports = {
round: round,
vote: vote,
nextPuzzle: nextPuzzle
round: function(puzzleId, win) {
return $.ajax({
method: 'POST',
url: '/training/' + puzzleId + '/round2',
data: {
win: win ? 1 : 0
}
});
},
vote: function(puzzleId, v) {
return $.ajax({
method: 'POST',
url: '/training/' + puzzleId + '/vote',
data: {
vote: v ? 1 : 0
}
});
},
nextPuzzle: function() {
return $.ajax({
url: '/training/new'
});
}
};