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

86 lines
3.3 KiB
JavaScript
Raw Permalink Normal View History

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