migrate ui/puzzle to vdom-only mithril
parent
801bf548bf
commit
29a5a93e5a
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"common": "file:../common",
|
||||
"chess": "file:../chess",
|
||||
"mithril": "github:ornicar/mithril.js#lila-1"
|
||||
"chess": "file:../chess"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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'
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue