diff --git a/src/ui/component/claimListDiscover/index.js b/src/ui/component/claimListDiscover/index.js index 7e4f7e5b1..10843d588 100644 --- a/src/ui/component/claimListDiscover/index.js +++ b/src/ui/component/claimListDiscover/index.js @@ -15,7 +15,7 @@ const select = state => ({ claimSearchByQuery: selectClaimSearchByQuery(state), loading: selectFetchingClaimSearch(state), subscribedChannels: selectSubscriptions(state), - showNsfw: makeSelectClientSetting(SETTINGS.SHOW_NSFW)(state), + showNsfw: makeSelectClientSetting(SETTINGS.SHOW_MATURE)(state), hiddenUris: selectBlockedChannels(state), }); diff --git a/src/ui/constants/settings.js b/src/ui/constants/settings.js index b01839277..8d027fed5 100644 --- a/src/ui/constants/settings.js +++ b/src/ui/constants/settings.js @@ -5,19 +5,18 @@ export const NEW_USER_ACKNOWLEDGED = 'welcome_acknowledged'; export const EMAIL_COLLECTION_ACKNOWLEDGED = 'email_collection_acknowledged'; export const INVITE_ACKNOWLEDGED = 'invite_acknowledged'; export const LANGUAGE = 'language'; -export const SHOW_NSFW = 'showNsfw'; -export const SHOW_UNAVAILABLE = 'showUnavailable'; -export const INSTANT_PURCHASE_ENABLED = 'instantPurchaseEnabled'; -export const INSTANT_PURCHASE_MAX = 'instantPurchaseMax'; +export const SHOW_MATURE = 'show_mature'; +export const SHOW_UNAVAILABLE = 'show_unavailable'; +export const INSTANT_PURCHASE_ENABLED = 'instant_purchase_enabled'; +export const INSTANT_PURCHASE_MAX = 'instant_purchase_max'; export const THEME = 'theme'; export const THEMES = 'themes'; -export const AUTOMATIC_DARK_MODE_ENABLED = 'automaticDarkModeEnabled'; +export const AUTOMATIC_DARK_MODE_ENABLED = 'automatic_dark_mode_enabled'; export const AUTOPLAY = 'autoplay'; -export const RESULT_COUNT = 'resultCount'; -export const OS_NOTIFICATIONS_ENABLED = 'osNotificationsEnabled'; -export const AUTO_DOWNLOAD = 'autoDownload'; -export const SUPPORT_OPTION = 'supportOption'; -export const HIDE_BALANCE = 'hideBalance'; -export const HIDE_SPLASH_ANIMATION = 'hideSplashAnimation'; -export const FLOATING_PLAYER = 'floatingPlayer'; -export const DARK_MODE_TIMES = 'darkModeTimes'; +export const OS_NOTIFICATIONS_ENABLED = 'os_notifications_enabled'; +export const AUTO_DOWNLOAD = 'auto_download'; +export const SUPPORT_OPTION = 'support_option'; +export const HIDE_BALANCE = 'hide_balance'; +export const HIDE_SPLASH_ANIMATION = 'hide_splash_animation'; +export const FLOATING_PLAYER = 'floating_player'; +export const DARK_MODE_TIMES = 'dark_mode_times'; diff --git a/src/ui/page/settings/index.js b/src/ui/page/settings/index.js index 892448e80..fbf7f3b10 100644 --- a/src/ui/page/settings/index.js +++ b/src/ui/page/settings/index.js @@ -1,5 +1,5 @@ import { connect } from 'react-redux'; -import * as settings from 'constants/settings'; +import * as SETTINGS from 'constants/settings'; import { doClearCache, doNotifyEncryptWallet, doNotifyDecryptWallet } from 'redux/actions/app'; import { doSetDaemonSetting, @@ -20,23 +20,23 @@ import SettingsPage from './view'; const select = state => ({ daemonSettings: selectDaemonSettings(state), - showNsfw: makeSelectClientSetting(settings.SHOW_NSFW)(state), - instantPurchaseEnabled: makeSelectClientSetting(settings.INSTANT_PURCHASE_ENABLED)(state), - instantPurchaseMax: makeSelectClientSetting(settings.INSTANT_PURCHASE_MAX)(state), - currentTheme: makeSelectClientSetting(settings.THEME)(state), - themes: makeSelectClientSetting(settings.THEMES)(state), - currentLanguage: makeSelectClientSetting(settings.LANGUAGE)(state), + showNsfw: makeSelectClientSetting(SETTINGS.SHOW_MATURE)(state), + instantPurchaseEnabled: makeSelectClientSetting(SETTINGS.INSTANT_PURCHASE_ENABLED)(state), + instantPurchaseMax: makeSelectClientSetting(SETTINGS.INSTANT_PURCHASE_MAX)(state), + currentTheme: makeSelectClientSetting(SETTINGS.THEME)(state), + themes: makeSelectClientSetting(SETTINGS.THEMES)(state), + currentLanguage: makeSelectClientSetting(SETTINGS.LANGUAGE)(state), languages: selectLanguages(state), - automaticDarkModeEnabled: makeSelectClientSetting(settings.AUTOMATIC_DARK_MODE_ENABLED)(state), - autoplay: makeSelectClientSetting(settings.AUTOPLAY)(state), + automaticDarkModeEnabled: makeSelectClientSetting(SETTINGS.AUTOMATIC_DARK_MODE_ENABLED)(state), + autoplay: makeSelectClientSetting(SETTINGS.AUTOPLAY)(state), walletEncrypted: selectWalletIsEncrypted(state), osNotificationsEnabled: selectosNotificationsEnabled(state), - autoDownload: makeSelectClientSetting(settings.AUTO_DOWNLOAD)(state), - supportOption: makeSelectClientSetting(settings.SUPPORT_OPTION)(state), + autoDownload: makeSelectClientSetting(SETTINGS.AUTO_DOWNLOAD)(state), + supportOption: makeSelectClientSetting(SETTINGS.SUPPORT_OPTION)(state), userBlockedChannelsCount: selectBlockedChannelsCount(state), - hideBalance: makeSelectClientSetting(settings.HIDE_BALANCE)(state), - floatingPlayer: makeSelectClientSetting(settings.FLOATING_PLAYER)(state), - darkModeTimes: makeSelectClientSetting(settings.DARK_MODE_TIMES)(state), + hideBalance: makeSelectClientSetting(SETTINGS.HIDE_BALANCE)(state), + floatingPlayer: makeSelectClientSetting(SETTINGS.FLOATING_PLAYER)(state), + darkModeTimes: makeSelectClientSetting(SETTINGS.DARK_MODE_TIMES)(state), }); const perform = dispatch => ({ diff --git a/src/ui/page/settings/view.jsx b/src/ui/page/settings/view.jsx index a5650c730..9e542eabd 100644 --- a/src/ui/page/settings/view.jsx +++ b/src/ui/page/settings/view.jsx @@ -368,7 +368,7 @@ class SettingsPage extends React.PureComponent { setClientSetting(SETTINGS.SHOW_NSFW, !showNsfw)} + onChange={() => setClientSetting(SETTINGS.SHOW_MATURE, !showNsfw)} checked={showNsfw} label={__('Show mature content')} helper={__( diff --git a/src/ui/redux/actions/settings.js b/src/ui/redux/actions/settings.js index 2de70846f..8d7fbc30e 100644 --- a/src/ui/redux/actions/settings.js +++ b/src/ui/redux/actions/settings.js @@ -144,7 +144,7 @@ export function doSetDarkTime(value, options) { const { fromTo, time } = options; return (dispatch, getState) => { const state = getState(); - const { darkModeTimes } = state.settings.clientSettings; + const darkModeTimes = state.settings.clientSettings[SETTINGS.DARK_MODE_TIMES]; const { hour, min } = darkModeTimes[fromTo]; const newHour = time === 'hour' ? value : hour; const newMin = time === 'min' ? value : min; diff --git a/src/ui/redux/reducers/settings.js b/src/ui/redux/reducers/settings.js index 042b712cf..be1868bd2 100644 --- a/src/ui/redux/reducers/settings.js +++ b/src/ui/redux/reducers/settings.js @@ -3,44 +3,43 @@ import LANGUAGES from 'constants/languages'; import * as SETTINGS from 'constants/settings'; import moment from 'moment'; -function getLocalStorageSetting(setting, fallback) { - const localStorageVal = localStorage.getItem(`setting_${setting}`); - return localStorageVal === null ? fallback : JSON.parse(localStorageVal); -} - const reducers = {}; const defaultState = { - clientSettings: { - [SETTINGS.INSTANT_PURCHASE_ENABLED]: getLocalStorageSetting(SETTINGS.INSTANT_PURCHASE_ENABLED, false), - [SETTINGS.INSTANT_PURCHASE_MAX]: getLocalStorageSetting(SETTINGS.INSTANT_PURCHASE_MAX, { - currency: 'LBC', - amount: 0.1, - }), - [SETTINGS.SHOW_NSFW]: getLocalStorageSetting(SETTINGS.SHOW_NSFW, false), - [SETTINGS.SHOW_UNAVAILABLE]: getLocalStorageSetting(SETTINGS.SHOW_UNAVAILABLE, true), - [SETTINGS.NEW_USER_ACKNOWLEDGED]: getLocalStorageSetting(SETTINGS.NEW_USER_ACKNOWLEDGED, false), - [SETTINGS.EMAIL_COLLECTION_ACKNOWLEDGED]: getLocalStorageSetting(SETTINGS.EMAIL_COLLECTION_ACKNOWLEDGED, false), - [SETTINGS.CREDIT_REQUIRED_ACKNOWLEDGED]: false, // this needs to be re-acknowledged every run - [SETTINGS.LANGUAGE]: getLocalStorageSetting(SETTINGS.LANGUAGE, 'en'), - [SETTINGS.THEME]: getLocalStorageSetting(SETTINGS.THEME, 'light'), - [SETTINGS.THEMES]: getLocalStorageSetting(SETTINGS.THEMES, []), - [SETTINGS.AUTOMATIC_DARK_MODE_ENABLED]: getLocalStorageSetting(SETTINGS.AUTOMATIC_DARK_MODE_ENABLED, false), - [SETTINGS.SUPPORT_OPTION]: getLocalStorageSetting(SETTINGS.SUPPORT_OPTION, false), - [SETTINGS.AUTOPLAY]: getLocalStorageSetting(SETTINGS.AUTOPLAY, true), - [SETTINGS.RESULT_COUNT]: Number(getLocalStorageSetting(SETTINGS.RESULT_COUNT, 50)), - [SETTINGS.AUTO_DOWNLOAD]: getLocalStorageSetting(SETTINGS.AUTO_DOWNLOAD, true), - [SETTINGS.OS_NOTIFICATIONS_ENABLED]: Boolean(getLocalStorageSetting(SETTINGS.OS_NOTIFICATIONS_ENABLED, true)), - [SETTINGS.HIDE_BALANCE]: Boolean(getLocalStorageSetting(SETTINGS.HIDE_BALANCE, false)), - [SETTINGS.HIDE_SPLASH_ANIMATION]: Boolean(getLocalStorageSetting(SETTINGS.HIDE_SPLASH_ANIMATION, false)), - [SETTINGS.FLOATING_PLAYER]: Boolean(getLocalStorageSetting(SETTINGS.FLOATING_PLAYER, true)), - [SETTINGS.DARK_MODE_TIMES]: getLocalStorageSetting(SETTINGS.DARK_MODE_TIMES, { - from: { hour: '21', min: '00', formattedTime: '21:00' }, - to: { hour: '8', min: '00', formattedTime: '8:00' }, - }), - }, isNight: false, languages: { en: 'English', pl: 'Polish', id: 'Bahasa Indonesia', de: 'German' }, // temporarily hard code these so we can advance i18n testing daemonSettings: {}, + clientSettings: { + // UX + [SETTINGS.NEW_USER_ACKNOWLEDGED]: false, + [SETTINGS.EMAIL_COLLECTION_ACKNOWLEDGED]: false, + + // UI + [SETTINGS.LANGUAGE]: 'en', + [SETTINGS.THEME]: 'light', + [SETTINGS.THEMES]: [], + [SETTINGS.SUPPORT_OPTION]: false, + [SETTINGS.HIDE_SPLASH_ANIMATION]: false, + [SETTINGS.HIDE_BALANCE]: false, + [SETTINGS.OS_NOTIFICATIONS_ENABLED]: true, + [SETTINGS.AUTOMATIC_DARK_MODE_ENABLED]: false, + [SETTINGS.DARK_MODE_TIMES]: { + from: { hour: '21', min: '00', formattedTime: '21:00' }, + to: { hour: '8', min: '00', formattedTime: '8:00' }, + }, + + // Purchasing + [SETTINGS.INSTANT_PURCHASE_ENABLED]: false, + [SETTINGS.INSTANT_PURCHASE_MAX]: { + currency: 'LBC', + amount: 0.1, + }, + + // Content + [SETTINGS.SHOW_MATURE]: false, + [SETTINGS.AUTOPLAY]: true, + [SETTINGS.FLOATING_PLAYER]: true, + [SETTINGS.AUTO_DOWNLOAD]: true, + }, }; reducers[ACTIONS.DAEMON_SETTINGS_RECEIVED] = (state, action) => @@ -65,7 +64,7 @@ reducers[ACTIONS.CLIENT_SETTING_CHANGED] = (state, action) => { }; reducers[ACTIONS.UPDATE_IS_NIGHT] = state => { - const { from, to } = state.clientSettings.darkModeTimes; + const { from, to } = state.clientSettings[SETTINGS.DARK_MODE_TIMES]; const momentNow = moment(); const startNightMoment = moment(from.formattedTime, 'HH:mm'); const endNightMoment = moment(to.formattedTime, 'HH:mm'); diff --git a/src/ui/redux/selectors/settings.js b/src/ui/redux/selectors/settings.js index b94fe1592..371de8602 100644 --- a/src/ui/redux/selectors/settings.js +++ b/src/ui/redux/selectors/settings.js @@ -20,7 +20,7 @@ export const makeSelectClientSetting = setting => ); // refactor me -export const selectShowMatureContent = makeSelectClientSetting(SETTINGS.SHOW_NSFW); +export const selectShowMatureContent = makeSelectClientSetting(SETTINGS.SHOW_MATURE); export const selectLanguages = createSelector( selectState, diff --git a/src/ui/store.js b/src/ui/store.js index f1b3f5e6a..371221db5 100644 --- a/src/ui/store.js +++ b/src/ui/store.js @@ -61,6 +61,7 @@ const whiteListedReducers = [ 'search', 'tags', 'blocked', + 'settings', ]; const transforms = [