2020-07-10 17:04:36 -04:00
|
|
|
import { SETTINGS, DAEMON_SETTINGS } from 'lbry-redux';
|
2017-12-21 14:32:51 -03:00
|
|
|
import { createSelector } from 'reselect';
|
2020-11-10 11:07:00 -05:00
|
|
|
import homepages from 'homepages';
|
2021-03-25 01:12:24 -04:00
|
|
|
import { SIMPLE_SITE } from 'config';
|
2021-04-06 15:15:08 -04:00
|
|
|
import { getDefaultHomepageKey, getDefaultLanguage } from 'util/default-languages';
|
2017-05-17 17:52:45 -04:00
|
|
|
|
2021-03-25 01:12:24 -04:00
|
|
|
const selectState = (state) => state.settings || {};
|
2017-05-17 17:52:45 -04:00
|
|
|
|
2021-03-25 01:12:24 -04:00
|
|
|
export const selectDaemonSettings = createSelector(selectState, (state) => state.daemonSettings);
|
2017-05-17 17:52:45 -04:00
|
|
|
|
2021-03-25 01:12:24 -04:00
|
|
|
export const selectDaemonStatus = createSelector(selectState, (state) => state.daemonStatus);
|
2019-12-12 15:18:13 -05:00
|
|
|
|
2021-03-25 01:12:24 -04:00
|
|
|
export const selectFfmpegStatus = createSelector(selectDaemonStatus, (status) => status.ffmpeg_status);
|
2020-03-24 13:57:17 -04:00
|
|
|
|
2021-03-25 01:12:24 -04:00
|
|
|
export const selectFindingFFmpeg = createSelector(selectState, (state) => state.findingFFmpeg || false);
|
2020-03-24 13:57:17 -04:00
|
|
|
|
2021-03-25 01:12:24 -04:00
|
|
|
export const selectClientSettings = createSelector(selectState, (state) => state.clientSettings || {});
|
2017-05-17 17:52:45 -04:00
|
|
|
|
2021-03-25 01:12:24 -04:00
|
|
|
export const selectLoadedLanguages = createSelector(selectState, (state) => state.loadedLanguages || {});
|
2019-09-04 17:43:37 -04:00
|
|
|
|
2021-03-25 01:12:24 -04:00
|
|
|
export const makeSelectClientSetting = (setting) =>
|
|
|
|
createSelector(selectClientSettings, (settings) => (settings ? settings[setting] : undefined));
|
2017-08-20 23:06:26 -04:00
|
|
|
|
2017-12-13 18:36:30 -03:00
|
|
|
// refactor me
|
2021-03-31 16:55:26 -04:00
|
|
|
export const selectShowMatureContent = SIMPLE_SITE
|
|
|
|
? createSelector(() => false)
|
|
|
|
: makeSelectClientSetting(SETTINGS.SHOW_MATURE);
|
2017-08-08 10:36:14 +01:00
|
|
|
|
2020-02-20 12:30:27 +00:00
|
|
|
// and me
|
2020-07-10 17:04:36 -04:00
|
|
|
export const selectShowRepostedContent = makeSelectClientSetting(SETTINGS.HIDE_REPOSTS);
|
2020-02-20 12:30:27 +00:00
|
|
|
|
2018-01-14 20:14:15 +11:00
|
|
|
export const selectTheme = makeSelectClientSetting(SETTINGS.THEME);
|
2019-05-07 17:38:29 -04:00
|
|
|
export const selectAutomaticDarkModeEnabled = makeSelectClientSetting(SETTINGS.AUTOMATIC_DARK_MODE_ENABLED);
|
2021-03-25 01:12:24 -04:00
|
|
|
export const selectIsNight = createSelector(selectState, (state) => state.isNight);
|
2018-01-14 20:14:15 +11:00
|
|
|
|
2021-03-25 01:12:24 -04:00
|
|
|
export const selectSavedWalletServers = createSelector(selectState, (state) => state.customWalletServers);
|
2019-12-11 15:09:27 -05:00
|
|
|
|
2021-03-25 01:12:24 -04:00
|
|
|
export const selectSharedPreferences = createSelector(selectState, (state) => state.sharedPreferences);
|
2019-12-11 15:09:27 -05:00
|
|
|
|
2021-03-25 01:12:24 -04:00
|
|
|
export const makeSelectSharedPreferencesForKey = (key) =>
|
|
|
|
createSelector(selectSharedPreferences, (prefs) => (prefs ? prefs[key] : undefined));
|
2019-12-11 15:09:27 -05:00
|
|
|
|
2020-02-20 12:30:27 +00:00
|
|
|
export const selectHasWalletServerPrefs = createSelector(
|
2020-07-10 17:04:36 -04:00
|
|
|
makeSelectSharedPreferencesForKey(DAEMON_SETTINGS.LBRYUM_SERVERS),
|
2021-03-25 01:12:24 -04:00
|
|
|
(servers) => {
|
2020-03-24 13:57:17 -04:00
|
|
|
return !!(servers && servers.length);
|
2020-02-20 12:30:27 +00:00
|
|
|
}
|
|
|
|
);
|
2019-12-12 15:18:13 -05:00
|
|
|
|
2017-09-06 20:52:34 -04:00
|
|
|
export const selectThemePath = createSelector(
|
2018-01-14 20:14:15 +11:00
|
|
|
selectTheme,
|
|
|
|
selectAutomaticDarkModeEnabled,
|
|
|
|
selectIsNight,
|
|
|
|
(theme, automaticDarkModeEnabled, isNight) => {
|
|
|
|
const dynamicTheme = automaticDarkModeEnabled && isNight ? 'dark' : theme;
|
2018-10-18 11:45:24 -05:00
|
|
|
return dynamicTheme || 'light';
|
2018-01-14 20:14:15 +11:00
|
|
|
}
|
2017-09-06 20:52:34 -04:00
|
|
|
);
|
2018-07-30 21:13:57 -03:00
|
|
|
|
2021-03-25 01:12:24 -04:00
|
|
|
export const selectHomepageCode = createSelector(makeSelectClientSetting(SETTINGS.HOMEPAGE), (setting) => {
|
2021-01-06 13:13:56 -05:00
|
|
|
return homepages[setting] ? setting : getDefaultHomepageKey();
|
2020-11-20 08:21:31 -05:00
|
|
|
});
|
|
|
|
|
2021-03-25 01:12:24 -04:00
|
|
|
export const selectLanguage = createSelector(makeSelectClientSetting(SETTINGS.LANGUAGE), (setting) => {
|
2021-04-06 15:15:08 -04:00
|
|
|
return setting || getDefaultLanguage();
|
2020-11-10 11:07:00 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
export const selectHomepageData = createSelector(
|
|
|
|
// using homepage setting,
|
|
|
|
selectHomepageCode,
|
2021-03-25 01:12:24 -04:00
|
|
|
(homepageCode) => {
|
2020-11-10 11:07:00 -05:00
|
|
|
// homepages = { 'en': homepageFile, ... }
|
2021-04-14 11:06:05 -04:00
|
|
|
return homepages[homepageCode] || homepages['en'];
|
2020-11-10 11:07:00 -05:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2019-05-07 17:38:29 -04:00
|
|
|
export const selectosNotificationsEnabled = makeSelectClientSetting(SETTINGS.OS_NOTIFICATIONS_ENABLED);
|