2017-12-21 18:32:51 +01:00
|
|
|
import * as ACTIONS from 'constants/action_types';
|
2017-12-28 00:48:11 +01:00
|
|
|
import * as SETTINGS from 'constants/settings';
|
2019-08-16 16:57:15 +02:00
|
|
|
import moment from 'moment';
|
2019-12-02 23:57:10 +01:00
|
|
|
import SUPPORTED_LANGUAGES from 'constants/supported_languages';
|
2019-12-12 21:18:13 +01:00
|
|
|
import { ACTIONS as LBRY_REDUX_ACTIONS, SHARED_PREFERENCES } from 'lbry-redux';
|
2017-09-23 01:23:51 +02:00
|
|
|
|
2017-06-06 06:21:55 +02:00
|
|
|
const reducers = {};
|
2017-06-28 09:12:01 +02:00
|
|
|
const defaultState = {
|
2019-09-17 20:49:03 +02:00
|
|
|
isNight: false,
|
2019-11-14 00:51:23 +01:00
|
|
|
loadedLanguages: [...Object.keys(window.i18n_messages), 'en'] || ['en'],
|
2019-12-11 21:09:27 +01:00
|
|
|
customWalletServers: [],
|
2019-12-12 21:18:13 +01:00
|
|
|
sharedPreferences: {
|
2019-12-13 17:13:49 +01:00
|
|
|
[SHARED_PREFERENCES.WALLET_SERVERS]: [],
|
2019-12-11 21:09:27 +01:00
|
|
|
},
|
2019-09-17 20:49:03 +02:00
|
|
|
daemonSettings: {},
|
2019-12-12 21:18:13 +01:00
|
|
|
daemonStatus: {},
|
2017-06-28 09:12:01 +02:00
|
|
|
clientSettings: {
|
2019-09-17 20:49:03 +02:00
|
|
|
// UX
|
|
|
|
[SETTINGS.NEW_USER_ACKNOWLEDGED]: false,
|
|
|
|
[SETTINGS.EMAIL_COLLECTION_ACKNOWLEDGED]: false,
|
2019-10-24 17:48:58 +02:00
|
|
|
[SETTINGS.ENABLE_SYNC]: true,
|
2019-09-17 20:49:03 +02:00
|
|
|
|
|
|
|
// UI
|
2019-12-02 23:57:10 +01:00
|
|
|
[SETTINGS.LANGUAGE]: [
|
|
|
|
window.localStorage.getItem(SETTINGS.LANGUAGE),
|
|
|
|
window.navigator.language.slice(0, 2),
|
|
|
|
'en',
|
|
|
|
].find(language => SUPPORTED_LANGUAGES[language]),
|
2019-10-03 23:40:54 +02:00
|
|
|
[SETTINGS.THEME]: __('light'),
|
|
|
|
[SETTINGS.THEMES]: [__('light'), __('dark')],
|
2019-09-17 20:49:03 +02:00
|
|
|
[SETTINGS.SUPPORT_OPTION]: false,
|
|
|
|
[SETTINGS.HIDE_SPLASH_ANIMATION]: false,
|
|
|
|
[SETTINGS.HIDE_BALANCE]: false,
|
|
|
|
[SETTINGS.OS_NOTIFICATIONS_ENABLED]: true,
|
|
|
|
[SETTINGS.AUTOMATIC_DARK_MODE_ENABLED]: false,
|
2019-11-18 19:30:15 +01:00
|
|
|
|
2019-09-17 20:49:03 +02:00
|
|
|
[SETTINGS.DARK_MODE_TIMES]: {
|
2019-08-18 18:54:55 +02:00
|
|
|
from: { hour: '21', min: '00', formattedTime: '21:00' },
|
|
|
|
to: { hour: '8', min: '00', formattedTime: '8:00' },
|
2019-09-17 20:49:03 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// Purchasing
|
|
|
|
[SETTINGS.INSTANT_PURCHASE_ENABLED]: false,
|
|
|
|
[SETTINGS.INSTANT_PURCHASE_MAX]: {
|
|
|
|
currency: 'LBC',
|
|
|
|
amount: 0.1,
|
|
|
|
},
|
|
|
|
|
|
|
|
// Content
|
|
|
|
[SETTINGS.SHOW_MATURE]: false,
|
|
|
|
[SETTINGS.AUTOPLAY]: true,
|
|
|
|
[SETTINGS.FLOATING_PLAYER]: true,
|
|
|
|
[SETTINGS.AUTO_DOWNLOAD]: true,
|
2019-11-18 19:30:15 +01:00
|
|
|
|
|
|
|
// OS
|
|
|
|
[SETTINGS.AUTO_LAUNCH]: true,
|
2017-06-28 09:12:01 +02:00
|
|
|
},
|
|
|
|
};
|
2017-05-17 23:52:45 +02:00
|
|
|
|
2019-12-12 21:18:13 +01:00
|
|
|
reducers[LBRY_REDUX_ACTIONS.DAEMON_SETTINGS_RECEIVED] = (state, action) =>
|
2017-12-28 00:48:11 +01:00
|
|
|
Object.assign({}, state, {
|
2017-06-06 23:19:12 +02:00
|
|
|
daemonSettings: action.data.settings,
|
|
|
|
});
|
2017-05-17 23:52:45 +02:00
|
|
|
|
2019-12-12 21:18:13 +01:00
|
|
|
reducers[LBRY_REDUX_ACTIONS.DAEMON_STATUS_RECEIVED] = (state, action) =>
|
|
|
|
Object.assign({}, state, {
|
|
|
|
daemonStatus: action.data.status,
|
|
|
|
});
|
|
|
|
|
2017-12-28 00:48:11 +01:00
|
|
|
reducers[ACTIONS.CLIENT_SETTING_CHANGED] = (state, action) => {
|
2017-06-28 09:12:01 +02:00
|
|
|
const { key, value } = action.data;
|
|
|
|
const clientSettings = Object.assign({}, state.clientSettings);
|
|
|
|
|
|
|
|
clientSettings[key] = value;
|
|
|
|
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
clientSettings,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2019-08-16 16:57:15 +02:00
|
|
|
reducers[ACTIONS.UPDATE_IS_NIGHT] = state => {
|
2019-09-17 20:49:03 +02:00
|
|
|
const { from, to } = state.clientSettings[SETTINGS.DARK_MODE_TIMES];
|
2019-08-16 16:57:15 +02:00
|
|
|
const momentNow = moment();
|
2019-08-18 18:54:55 +02:00
|
|
|
const startNightMoment = moment(from.formattedTime, 'HH:mm');
|
|
|
|
const endNightMoment = moment(to.formattedTime, 'HH:mm');
|
2019-08-16 16:57:15 +02:00
|
|
|
const isNight = !(momentNow.isAfter(endNightMoment) && momentNow.isBefore(startNightMoment));
|
|
|
|
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
isNight,
|
2018-01-14 10:14:15 +01:00
|
|
|
});
|
2019-08-16 16:57:15 +02:00
|
|
|
};
|
2018-01-14 10:14:15 +01:00
|
|
|
|
2019-11-08 21:51:42 +01:00
|
|
|
reducers[ACTIONS.DOWNLOAD_LANGUAGE_SUCCESS] = (state, action) => {
|
|
|
|
const { loadedLanguages } = state;
|
|
|
|
const { language } = action.data;
|
|
|
|
|
2019-12-06 14:58:17 +01:00
|
|
|
if (language && loadedLanguages && !loadedLanguages.includes(language)) {
|
2019-11-08 21:51:42 +01:00
|
|
|
return Object.assign({}, state, {
|
|
|
|
loadedLanguages: [...loadedLanguages, language],
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-12-11 21:09:27 +01:00
|
|
|
reducers[LBRY_REDUX_ACTIONS.SHARED_PREFERENCE_SET] = (state, action) => {
|
|
|
|
const { key, value } = action.data;
|
2019-12-12 21:18:13 +01:00
|
|
|
const sharedPreferences = Object.assign({}, state.sharedPreferences);
|
|
|
|
sharedPreferences[key] = value;
|
2019-12-11 21:09:27 +01:00
|
|
|
|
|
|
|
return Object.assign({}, state, {
|
2019-12-12 21:18:13 +01:00
|
|
|
sharedPreferences,
|
2019-12-11 21:09:27 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
reducers[ACTIONS.CLIENT_SETTING_CHANGED] = (state, action) => {
|
|
|
|
const { key, value } = action.data;
|
|
|
|
const clientSettings = Object.assign({}, state.clientSettings);
|
|
|
|
|
|
|
|
clientSettings[key] = value;
|
|
|
|
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
clientSettings,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
reducers[LBRY_REDUX_ACTIONS.USER_STATE_POPULATE] = (
|
|
|
|
state,
|
|
|
|
action,
|
|
|
|
) => {
|
2019-12-12 21:18:13 +01:00
|
|
|
const { settings: sharedPreferences } = action.data;
|
2019-12-11 21:09:27 +01:00
|
|
|
|
|
|
|
// process clientSettings and daemonSettings
|
2019-12-12 21:18:13 +01:00
|
|
|
return Object.assign({}, state, { sharedPreferences });
|
2019-12-11 21:09:27 +01:00
|
|
|
};
|
|
|
|
|
2019-12-12 21:18:13 +01:00
|
|
|
reducers[LBRY_REDUX_ACTIONS.SAVE_CUSTOM_WALLET_SERVERS] = (state, action) => {
|
2019-12-11 21:09:27 +01:00
|
|
|
return Object.assign({}, state, {customWalletServers: action.data});
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|