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

90 lines
2.4 KiB
JavaScript
Raw Normal View History

import * as SETTINGS from 'constants/settings';
import { SHARED_PREFERENCES, SETTINGS as LBRY_REDUX_SETTINGS } from 'lbry-redux';
import { createSelector } from 'reselect';
const selectState = state => state.settings || {};
2019-03-05 05:46:57 +01:00
export const selectDaemonSettings = createSelector(
selectState,
state => state.daemonSettings
);
2019-12-12 21:18:13 +01:00
export const selectDaemonStatus = createSelector(
selectState,
state => state.daemonStatus
);
export const selectFfmpegStatus = createSelector(
selectDaemonStatus,
status => status.ffmpeg_status
);
export const selectFindingFFmpeg = createSelector(
selectState,
state => state.findingFFmpeg || false
);
export const selectClientSettings = createSelector(
selectState,
2017-06-28 09:12:01 +02:00
state => state.clientSettings || {}
2017-06-06 06:21:55 +02:00
);
2019-11-08 21:51:42 +01:00
export const selectLoadedLanguages = createSelector(
selectState,
2019-11-08 21:51:42 +01:00
state => state.loadedLanguages || {}
);
2017-12-13 22:36:30 +01:00
export const makeSelectClientSetting = setting =>
2019-03-05 05:46:57 +01:00
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
export const selectShowMatureContent = makeSelectClientSetting(LBRY_REDUX_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(LBRY_REDUX_SETTINGS.SHOW_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);
2019-03-05 05:46:57 +01:00
export const selectIsNight = createSelector(
selectState,
state => state.isNight
);
2018-01-14 10:14:15 +01:00
2019-12-12 21:18:13 +01:00
export const selectSavedWalletServers = createSelector(
selectState,
state => state.customWalletServers
);
2019-12-12 21:18:13 +01:00
export const selectSharedPreferences = createSelector(
selectState,
2019-12-12 21:18:13 +01:00
state => state.sharedPreferences
);
2019-12-12 21:18:13 +01:00
export const makeSelectSharedPreferencesForKey = key =>
createSelector(
2019-12-12 21:18:13 +01:00
selectSharedPreferences,
prefs => (prefs ? prefs[key] : undefined)
);
2020-02-20 13:30:27 +01:00
export const selectHasWalletServerPrefs = createSelector(
makeSelectSharedPreferencesForKey(SHARED_PREFERENCES.WALLET_SERVERS),
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
);
2019-05-07 23:38:29 +02:00
export const selectosNotificationsEnabled = makeSelectClientSetting(SETTINGS.OS_NOTIFICATIONS_ENABLED);