2021-10-17 10:36:14 +02:00
|
|
|
import * as SETTINGS from 'constants/settings';
|
|
|
|
import * as DAEMON_SETTINGS from 'constants/daemon_settings';
|
2022-02-15 18:36:33 +01:00
|
|
|
import SUPPORTED_BROWSER_LANGUAGES from 'constants/supported_browser_languages';
|
2021-10-17 10:36:14 +02:00
|
|
|
|
2017-12-21 18:32:51 +01:00
|
|
|
import { createSelector } from 'reselect';
|
2021-07-06 20:16:57 +02:00
|
|
|
import { ENABLE_MATURE } from 'config';
|
2021-04-06 21:15:08 +02:00
|
|
|
import { getDefaultHomepageKey, getDefaultLanguage } from 'util/default-languages';
|
2017-05-17 23:52:45 +02:00
|
|
|
|
2021-03-25 06:12:24 +01:00
|
|
|
const selectState = (state) => state.settings || {};
|
2017-05-17 23:52:45 +02:00
|
|
|
|
2021-10-23 04:41:43 +02:00
|
|
|
export const selectDaemonSettings = (state) => selectState(state).daemonSettings;
|
|
|
|
export const selectDaemonStatus = (state) => selectState(state).daemonStatus;
|
2021-03-25 06:12:24 +01:00
|
|
|
export const selectFfmpegStatus = createSelector(selectDaemonStatus, (status) => status.ffmpeg_status);
|
2021-10-23 04:41:43 +02:00
|
|
|
export const selectFindingFFmpeg = (state) => selectState(state).findingFFmpeg || false;
|
|
|
|
export const selectClientSettings = (state) => selectState(state).clientSettings || {};
|
|
|
|
export const selectLoadedLanguages = (state) => selectState(state).loadedLanguages || {};
|
2019-09-04 23:43:37 +02:00
|
|
|
|
2021-11-16 05:04:40 +01:00
|
|
|
export const selectClientSetting = (state, setting) => {
|
|
|
|
const clientSettings = selectClientSettings(state);
|
|
|
|
return clientSettings ? clientSettings[setting] : undefined;
|
|
|
|
};
|
|
|
|
|
2017-12-13 22:36:30 +01:00
|
|
|
// refactor me
|
2021-11-16 05:04:40 +01:00
|
|
|
export const selectShowMatureContent = (state) => {
|
|
|
|
return !ENABLE_MATURE ? false : selectClientSetting(state, SETTINGS.SHOW_MATURE);
|
|
|
|
};
|
2017-08-08 11:36:14 +02:00
|
|
|
|
2021-11-23 05:29:04 +01:00
|
|
|
export const selectTheme = (state) => selectClientSetting(state, SETTINGS.THEME);
|
|
|
|
export const selectAutomaticDarkModeEnabled = (state) =>
|
|
|
|
selectClientSetting(state, SETTINGS.AUTOMATIC_DARK_MODE_ENABLED);
|
2021-10-23 04:41:43 +02:00
|
|
|
export const selectIsNight = (state) => selectState(state).isNight;
|
|
|
|
export const selectSavedWalletServers = (state) => selectState(state).customWalletServers;
|
|
|
|
export const selectSharedPreferences = (state) => selectState(state).sharedPreferences;
|
2019-12-11 21:09:27 +01:00
|
|
|
|
2021-03-25 06:12:24 +01:00
|
|
|
export const makeSelectSharedPreferencesForKey = (key) =>
|
|
|
|
createSelector(selectSharedPreferences, (prefs) => (prefs ? prefs[key] : undefined));
|
2019-12-11 21:09:27 +01:00
|
|
|
|
2020-02-20 13:30:27 +01:00
|
|
|
export const selectHasWalletServerPrefs = createSelector(
|
2020-07-10 23:04:36 +02:00
|
|
|
makeSelectSharedPreferencesForKey(DAEMON_SETTINGS.LBRYUM_SERVERS),
|
2021-03-25 06:12:24 +01:00
|
|
|
(servers) => {
|
2020-03-24 18:57:17 +01:00
|
|
|
return !!(servers && servers.length);
|
2020-02-20 13:30:27 +01:00
|
|
|
}
|
|
|
|
);
|
2019-12-12 21:18:13 +01:00
|
|
|
|
2017-09-07 02:52:34 +02:00
|
|
|
export const selectThemePath = createSelector(
|
2018-01-14 10:14:15 +01:00
|
|
|
selectTheme,
|
|
|
|
selectAutomaticDarkModeEnabled,
|
|
|
|
selectIsNight,
|
|
|
|
(theme, automaticDarkModeEnabled, isNight) => {
|
|
|
|
const dynamicTheme = automaticDarkModeEnabled && isNight ? 'dark' : theme;
|
2018-10-18 18:45:24 +02:00
|
|
|
return dynamicTheme || 'light';
|
2018-01-14 10:14:15 +01:00
|
|
|
}
|
2017-09-07 02:52:34 +02:00
|
|
|
);
|
2018-07-31 02:13:57 +02:00
|
|
|
|
2021-11-23 05:29:04 +01:00
|
|
|
export const selectHomepageCode = (state) => {
|
|
|
|
const hp = selectClientSetting(state, SETTINGS.HOMEPAGE);
|
2022-03-03 15:22:59 +01:00
|
|
|
const homepages = window.homepages || {};
|
2021-11-23 05:29:04 +01:00
|
|
|
return homepages[hp] ? hp : getDefaultHomepageKey();
|
|
|
|
};
|
2020-11-20 14:21:31 +01:00
|
|
|
|
2021-11-23 05:29:04 +01:00
|
|
|
export const selectLanguage = (state) => {
|
|
|
|
const lang = selectClientSetting(state, SETTINGS.LANGUAGE);
|
|
|
|
return lang || getDefaultLanguage();
|
|
|
|
};
|
2020-11-10 17:07:00 +01:00
|
|
|
|
2022-03-03 15:22:59 +01:00
|
|
|
export const selectHomepageData = (state) => {
|
|
|
|
const homepageCode = selectHomepageCode(state);
|
|
|
|
const homepages = window.homepages;
|
|
|
|
return homepages ? homepages[homepageCode] || homepages['en'] || {} : {};
|
|
|
|
};
|
2020-11-10 17:07:00 +01:00
|
|
|
|
2022-02-15 18:36:33 +01:00
|
|
|
export const selectInRegionByCode = (state, code) => {
|
|
|
|
const hp = selectClientSetting(state, SETTINGS.HOMEPAGE);
|
|
|
|
const lang = selectLanguage(state);
|
|
|
|
|
|
|
|
return hp === code || lang === code;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const selectWildWestDisabled = (state) => {
|
2022-03-03 15:22:59 +01:00
|
|
|
return selectInRegionByCode(state, SUPPORTED_BROWSER_LANGUAGES.de);
|
2022-02-15 18:36:33 +01:00
|
|
|
};
|
|
|
|
|
2021-11-23 05:29:04 +01:00
|
|
|
export const selectosNotificationsEnabled = (state) => selectClientSetting(state, SETTINGS.OS_NOTIFICATIONS_ENABLED);
|