Skip to content

Commit

Permalink
locally persist explorer preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Feb 8, 2016
1 parent b9a6fc0 commit f5a2047
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions ui/analyse/src/explorer/explorerConfig.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
var m = require('mithril');
var partial = require('chessground').util.partial;

function storedProp(keySuffix, initialValue) {
var key = 'explorer.' + keySuffix;
return function() {
if (arguments.length) lichess.storage.set(key, JSON.stringify(arguments[0]));
var ret = JSON.parse(lichess.storage.get(key));
return (ret !== null) ? ret : initialValue;
};
}

module.exports = {
controller: function(onUpdate) {
var data = {
open: m.prop(true),
db: {
available: ['lichess', 'masters'], //, 'me'],
selected: m.prop('lichess')
selected: storedProp('db', 'lichess')
},
rating: {
available: [1600, 1800, 2000, 2200, 2500],
selected: m.prop([2000, 2200, 2500])
selected: storedProp('rating', [2000, 2200, 2500])
},
speed: {
available: ['bullet', 'blitz', 'classical'],
selected: m.prop(['blitz', 'classical'])
selected: storedProp('speed', ['blitz', 'classical'])
}
};

Expand Down

0 comments on commit f5a2047

Please sign in to comment.