2017-12-21 18:32:51 +01:00
|
|
|
import * as SETTINGS from 'constants/settings';
|
|
|
|
import { createSelector } from 'reselect';
|
2017-05-17 23:52:45 +02:00
|
|
|
|
2017-12-21 18:32:51 +01:00
|
|
|
const selectState = state => state.settings || {};
|
2017-05-17 23:52:45 +02:00
|
|
|
|
2017-12-21 18:32:51 +01:00
|
|
|
export const selectDaemonSettings = createSelector(selectState, state => state.daemonSettings);
|
2017-05-17 23:52:45 +02:00
|
|
|
|
|
|
|
export const selectClientSettings = createSelector(
|
2017-12-21 18:32:51 +01:00
|
|
|
selectState,
|
2017-06-28 09:12:01 +02:00
|
|
|
state => state.clientSettings || {}
|
2017-06-06 06:21:55 +02:00
|
|
|
);
|
2017-05-17 23:52:45 +02:00
|
|
|
|
2017-12-13 22:36:30 +01:00
|
|
|
export const makeSelectClientSetting = setting =>
|
2017-12-21 18:32:51 +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
|
2017-12-21 18:32:51 +01:00
|
|
|
export const selectShowNsfw = makeSelectClientSetting(SETTINGS.SHOW_NSFW);
|
2017-08-08 11:36:14 +02:00
|
|
|
|
2017-12-21 18:32:51 +01:00
|
|
|
export const selectLanguages = createSelector(selectState, state => state.languages || {});
|
2017-09-07 02:52:34 +02:00
|
|
|
|
2018-01-14 10:14:15 +01:00
|
|
|
export const selectTheme = makeSelectClientSetting(SETTINGS.THEME);
|
|
|
|
export const selectAutomaticDarkModeEnabled = makeSelectClientSetting(
|
|
|
|
SETTINGS.AUTOMATIC_DARK_MODE_ENABLED
|
|
|
|
);
|
|
|
|
export const selectIsNight = createSelector(selectState, state => state.isNight);
|
|
|
|
|
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-03-22 19:52:07 +01:00
|
|
|
return `${staticResourcesPath}/themes/${dynamicTheme || 'light'}.css`;
|
2018-01-14 10:14:15 +01:00
|
|
|
}
|
2017-09-07 02:52:34 +02:00
|
|
|
);
|