lbry-desktop/ui/js/reducers/settings.js
2017-08-19 17:59:48 -06:00

35 lines
943 B
JavaScript

import * as types from "constants/action_types";
import * as settings from "constants/settings";
import lbry from "lbry";
const reducers = {};
const defaultState = {
clientSettings: {
showNsfw: lbry.getClientSetting("showNsfw"),
theme: lbry.getClientSetting(settings.THEME),
themes: lbry.getClientSetting(settings.THEMES),
},
};
reducers[types.DAEMON_SETTINGS_RECEIVED] = function(state, action) {
return Object.assign({}, state, {
daemonSettings: action.data.settings,
});
};
reducers[types.CLIENT_SETTING_CHANGED] = function(state, action) {
const { key, value } = action.data;
const clientSettings = Object.assign({}, state.clientSettings);
clientSettings[key] = value;
return Object.assign({}, state, {
clientSettings,
});
};
export default function reducer(state = defaultState, action) {
const handler = reducers[action.type];
if (handler) return handler(state, action);
return state;
}