2017-12-21 14:32:51 -03:00
|
|
|
import * as SETTINGS from 'constants/settings';
|
2019-12-12 15:18:13 -05:00
|
|
|
import { SHARED_PREFERENCES } from 'lbry-redux';
|
2017-12-21 14:32:51 -03:00
|
|
|
import { createSelector } from 'reselect';
|
2017-05-17 17:52:45 -04:00
|
|
|
|
2017-12-21 14:32:51 -03:00
|
|
|
const selectState = state => state.settings || {};
|
2017-05-17 17:52:45 -04:00
|
|
|
|
2019-03-04 23:46:57 -05:00
|
|
|
export const selectDaemonSettings = createSelector(
|
|
|
|
selectState,
|
|
|
|
state => state.daemonSettings
|
|
|
|
);
|
2017-05-17 17:52:45 -04:00
|
|
|
|
2019-12-12 15:18:13 -05:00
|
|
|
export const selectDaemonStatus = createSelector(
|
|
|
|
selectState,
|
|
|
|
state => state.daemonStatus
|
|
|
|
);
|
|
|
|
|
2017-05-17 17:52:45 -04:00
|
|
|
export const selectClientSettings = createSelector(
|
2017-12-21 14:32:51 -03:00
|
|
|
selectState,
|
2017-06-28 14:12:01 +07:00
|
|
|
state => state.clientSettings || {}
|
2017-06-05 21:21:55 -07:00
|
|
|
);
|
2017-05-17 17:52:45 -04:00
|
|
|
|
2019-11-08 15:51:42 -05:00
|
|
|
export const selectLoadedLanguages = createSelector(
|
2019-09-04 17:43:37 -04:00
|
|
|
selectState,
|
2019-11-08 15:51:42 -05:00
|
|
|
state => state.loadedLanguages || {}
|
2019-09-04 17:43:37 -04:00
|
|
|
);
|
|
|
|
|
2017-12-13 18:36:30 -03:00
|
|
|
export const makeSelectClientSetting = setting =>
|
2019-03-04 23:46:57 -05:00
|
|
|
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
|
2019-09-17 14:49:03 -04:00
|
|
|
export const selectShowMatureContent = makeSelectClientSetting(SETTINGS.SHOW_MATURE);
|
2017-08-08 10:36:14 +01: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);
|
2019-03-04 23:46:57 -05:00
|
|
|
export const selectIsNight = createSelector(
|
|
|
|
selectState,
|
|
|
|
state => state.isNight
|
|
|
|
);
|
2018-01-14 20:14:15 +11:00
|
|
|
|
2019-12-12 15:18:13 -05:00
|
|
|
export const selectSavedWalletServers = createSelector(
|
2019-12-11 15:09:27 -05:00
|
|
|
selectState,
|
|
|
|
state => state.customWalletServers
|
|
|
|
);
|
|
|
|
|
2019-12-12 15:18:13 -05:00
|
|
|
export const selectSharedPreferences = createSelector(
|
2019-12-11 15:09:27 -05:00
|
|
|
selectState,
|
2019-12-12 15:18:13 -05:00
|
|
|
state => state.sharedPreferences
|
2019-12-11 15:09:27 -05:00
|
|
|
);
|
|
|
|
|
2019-12-12 15:18:13 -05:00
|
|
|
export const makeSelectSharedPreferencesForKey = key =>
|
2019-12-11 15:09:27 -05:00
|
|
|
createSelector(
|
2019-12-12 15:18:13 -05:00
|
|
|
selectSharedPreferences,
|
2019-12-11 15:09:27 -05:00
|
|
|
prefs => (prefs ? prefs[key] : undefined)
|
|
|
|
);
|
|
|
|
|
2019-12-12 15:18:13 -05:00
|
|
|
export const selectHasWalletServerPrefs =
|
|
|
|
createSelector(
|
|
|
|
makeSelectSharedPreferencesForKey(SHARED_PREFERENCES.WALLET_SERVERS),
|
|
|
|
servers => {
|
|
|
|
if (servers && servers.length) return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
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
|
|
|
|
2019-05-07 17:38:29 -04:00
|
|
|
export const selectosNotificationsEnabled = makeSelectClientSetting(SETTINGS.OS_NOTIFICATIONS_ENABLED);
|