koel/resources/assets/js/stores/preference.js
An Phan f43e72355c Add thumbnails/listing view mode (close #278)
This commit adds an option to change view mode (thumbnails/listing) for
artists and albums views.
2016-03-28 19:51:49 +08:00

49 lines
1,019 B
JavaScript

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,
equalizer: {
preamp: 0,
gains: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
},
artistsViewMode: null,
albumsViewMode: null,
},
/**
* Init the store.
*
* @param {Object} user The user whose preferences we are managing.
*/
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) {
return _.has(this.state, key) ? this.state[key] : null;
},
save() {
ls.set(this.storeKey, this.state);
},
};