koel/resources/assets/js/stores/preference.js

48 lines
959 B
JavaScript
Raw Normal View History

2015-12-13 04:42:28 +00:00
import _ from 'lodash';
import userStore from './user';
import ls from '../services/ls';
export default {
storeKey: '',
state: {
volume: 7,
notify: true,
repeatMode: 'NO_REPEAT',
showExtraPanel: true,
confirmClosing: false,
2016-01-19 11:00:23 +00:00
equalizer: {
preamp: 0,
gains: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
}
2015-12-13 04:42:28 +00:00
},
/**
2015-12-22 17:46:54 +00:00
* Init the store.
2016-03-13 17:00:32 +00:00
*
2015-12-22 17:46:54 +00:00
* @param {Object} user The user whose preferences we are managing.
2015-12-13 04:42:28 +00:00
*/
init(user = null) {
if (!user) {
user = userStore.current();
}
this.storeKey = `preferences_${user.id}`;
_.extend(this.state, ls.get(this.storeKey, this.state));
},
set(key, val) {
this.state[key] = val;
this.save();
},
get(key) {
2015-12-14 13:13:12 +00:00
return _.has(this.state, key) ? this.state[key] : null;
2015-12-13 04:42:28 +00:00
},
save() {
ls.set(this.storeKey, this.state);
},
};