lbry-desktop/ui/redux/selectors/settings.js

76 lines
2.9 KiB
JavaScript
Raw Normal View History

import * as SETTINGS from 'constants/settings';
import * as DAEMON_SETTINGS from 'constants/daemon_settings';
import { createSelector } from 'reselect';
2021-07-06 14:16:57 -04:00
import { ENABLE_MATURE } from 'config';
import { getDefaultHomepageKey, getDefaultLanguage } from 'util/default-languages';
const homepages = require('homepages');
2021-03-25 01:12:24 -04:00
const selectState = (state) => state.settings || {};
export const selectDaemonSettings = (state) => selectState(state).daemonSettings;
export const selectDaemonStatus = (state) => selectState(state).daemonStatus;
2021-03-25 01:12:24 -04:00
export const selectFfmpegStatus = createSelector(selectDaemonStatus, (status) => status.ffmpeg_status);
export const selectFindingFFmpeg = (state) => selectState(state).findingFFmpeg || false;
export const selectClientSettings = (state) => selectState(state).clientSettings || {};
export const selectLoadedLanguages = (state) => selectState(state).loadedLanguages || {};
2021-11-16 12:04:40 +08:00
export const selectClientSetting = (state, setting) => {
const clientSettings = selectClientSettings(state);
return clientSettings ? clientSettings[setting] : undefined;
};
2017-12-13 18:36:30 -03:00
// refactor me
2021-11-16 12:04:40 +08:00
export const selectShowMatureContent = (state) => {
return !ENABLE_MATURE ? false : selectClientSetting(state, SETTINGS.SHOW_MATURE);
};
2017-08-08 10:36:14 +01:00
export const selectTheme = (state) => selectClientSetting(state, SETTINGS.THEME);
export const selectAutomaticDarkModeEnabled = (state) =>
selectClientSetting(state, SETTINGS.AUTOMATIC_DARK_MODE_ENABLED);
export const selectIsNight = (state) => selectState(state).isNight;
export const selectSavedWalletServers = (state) => selectState(state).customWalletServers;
export const selectSharedPreferences = (state) => selectState(state).sharedPreferences;
2021-03-25 01:12:24 -04:00
export const makeSelectSharedPreferencesForKey = (key) =>
createSelector(selectSharedPreferences, (prefs) => (prefs ? prefs[key] : undefined));
2020-02-20 12:30:27 +00:00
export const selectHasWalletServerPrefs = createSelector(
makeSelectSharedPreferencesForKey(DAEMON_SETTINGS.LBRYUM_SERVERS),
2021-03-25 01:12:24 -04:00
(servers) => {
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
);
export const selectHomepageCode = (state) => {
const hp = selectClientSetting(state, SETTINGS.HOMEPAGE);
return homepages[hp] ? hp : getDefaultHomepageKey();
};
export const selectLanguage = (state) => {
const lang = selectClientSetting(state, SETTINGS.LANGUAGE);
return lang || getDefaultLanguage();
};
export const selectHomepageData = createSelector(
// using homepage setting,
selectHomepageCode,
(homepageCode) => {
// homepages = { 'en': homepageFile, ... }
// mixin Homepages here
return homepages[homepageCode] || homepages['en'] || {};
}
);
export const selectosNotificationsEnabled = (state) => selectClientSetting(state, SETTINGS.OS_NOTIFICATIONS_ENABLED);