2017-06-06 23:19:12 +02:00
|
|
|
import * as types from "constants/action_types";
|
2017-08-21 05:06:26 +02:00
|
|
|
import * as settings from "constants/settings";
|
2017-08-22 23:19:33 +02:00
|
|
|
import LANGUAGES from "constants/languages";
|
2017-06-28 09:12:01 +02:00
|
|
|
import lbry from "lbry";
|
2017-05-17 23:52:45 +02:00
|
|
|
|
2017-06-06 06:21:55 +02:00
|
|
|
const reducers = {};
|
2017-06-28 09:12:01 +02:00
|
|
|
const defaultState = {
|
|
|
|
clientSettings: {
|
2017-09-08 07:03:37 +02:00
|
|
|
instantPurchaseEnabled: lbry.getClientSetting(
|
|
|
|
settings.INSTANT_PURCHASE_ENABLED
|
|
|
|
),
|
|
|
|
instantPurchaseMax: lbry.getClientSetting(settings.INSTANT_PURCHASE_MAX),
|
2017-09-07 03:53:42 +02:00
|
|
|
showNsfw: lbry.getClientSetting(settings.SHOW_NSFW),
|
|
|
|
showUnavailable: lbry.getClientSetting(settings.SHOW_UNAVAILABLE),
|
2017-08-21 05:06:26 +02:00
|
|
|
welcome_acknowledged: lbry.getClientSetting(settings.NEW_USER_ACKNOWLEDGED),
|
|
|
|
credit_intro_acknowledged: lbry.getClientSetting(
|
|
|
|
settings.CREDIT_INTRO_ACKNOWLEDGED
|
|
|
|
),
|
2017-08-22 23:19:33 +02:00
|
|
|
language: lbry.getClientSetting(settings.LANGUAGE),
|
2017-08-20 01:59:48 +02:00
|
|
|
theme: lbry.getClientSetting(settings.THEME),
|
|
|
|
themes: lbry.getClientSetting(settings.THEMES),
|
2017-06-28 09:12:01 +02:00
|
|
|
},
|
2017-08-19 20:03:51 +02:00
|
|
|
languages: {},
|
2017-06-28 09:12:01 +02:00
|
|
|
};
|
2017-05-17 23:52:45 +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-05-17 23:52:45 +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) {
|
2017-08-19 20:03:51 +02:00
|
|
|
const languages = Object.assign({}, state.languages);
|
|
|
|
const language = action.data.language;
|
2017-08-08 11:36:14 +02:00
|
|
|
|
2017-08-19 20:03:51 +02:00
|
|
|
const langCode = language.substring(0, 2);
|
2017-08-08 11:36:14 +02:00
|
|
|
|
2017-08-19 20:03:51 +02:00
|
|
|
if (LANGUAGES[langCode]) {
|
2017-08-23 01:50:59 +02:00
|
|
|
languages[language] =
|
2017-08-19 20:03:51 +02:00
|
|
|
LANGUAGES[langCode][0] + " (" + LANGUAGES[langCode][1] + ")";
|
|
|
|
} else {
|
|
|
|
languages[langCode] = langCode;
|
|
|
|
}
|
2017-08-08 11:36:14 +02:00
|
|
|
|
2017-08-19 20:03:51 +02:00
|
|
|
return Object.assign({}, state, { languages });
|
|
|
|
};
|
2017-08-08 11:36:14 +02:00
|
|
|
|
2017-08-19 20:03:51 +02:00
|
|
|
reducers[types.DOWNLOAD_LANGUAGE_FAILED] = function(state, action) {
|
|
|
|
const languages = Object.assign({}, state.languages);
|
|
|
|
delete languages[action.data.language];
|
|
|
|
return Object.assign({}, state, { languages });
|
2017-08-08 11:36:14 +02:00
|
|
|
};
|
|
|
|
|
2017-05-17 23:52:45 +02:00
|
|
|
export default function reducer(state = defaultState, action) {
|
|
|
|
const handler = reducers[action.type];
|
|
|
|
if (handler) return handler(state, action);
|
|
|
|
return state;
|
|
|
|
}
|