lbry-desktop/ui/js/reducers/settings.js

59 lines
1.4 KiB
JavaScript
Raw Normal View History

2017-06-06 23:19:12 +02:00
import * as types from "constants/action_types";
2017-06-28 09:12:01 +02:00
import lbry from "lbry";
2017-06-06 06:21:55 +02:00
const reducers = {};
2017-06-28 09:12:01 +02:00
const defaultState = {
clientSettings: {
showNsfw: lbry.getClientSetting("showNsfw"),
2017-07-07 15:15:45 +02:00
language: lbry.getClientSetting("language"),
2017-06-28 09:12:01 +02:00
},
};
reducers[types.DAEMON_SETTINGS_RECEIVED] = function(state, action) {
return Object.assign({}, state, {
2017-06-06 23:19:12 +02:00
daemonSettings: action.data.settings,
});
2017-06-06 06:21:55 +02:00
};
2017-06-28 09:12:01 +02:00
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,
});
};
2017-08-08 11:36:14 +02:00
reducers[types.DOWNLOAD_LANGUAGE_SUCCEEDED] = function(state, action) {
const localLanguages = [].concat(
state.localLanguages ? state.localLanguages : []
);
const language = action.data;
if (localLanguages.indexOf(language) === -1) {
localLanguages.push(language);
}
return Object.assign({}, state, {
localLanguages,
});
};
reducers[types.LANGUAGE_RESOLVED] = function(state, action) {
const { key, value } = action.data;
const resolvedLanguages = Object.assign({}, state.resolvedLanguages);
resolvedLanguages[key] = value;
return Object.assign({}, state, {
resolvedLanguages,
});
};
export default function reducer(state = defaultState, action) {
const handler = reducers[action.type];
if (handler) return handler(state, action);
return state;
}