prevent specific settings sync in config

This commit is contained in:
jessop 2020-07-31 14:24:01 -04:00 committed by Sean Yesmunt
parent 42e989d0cc
commit ab56633eed
3 changed files with 21 additions and 9 deletions

View file

@ -29,6 +29,11 @@ SITE_CANONICAL_URL=https://lbry.tv
# LOCALE
DEFAULT_LANGUAGE=en
# Custom Settings
# Additional settings for below are found in ui/constants/settings and are for
# preventing user settings from applying to custom sites without overwriting them.
# UNSYNCED_SETTINGS='theme dark_mode_times automatic_dark_mode_enabled'
# Custom Content
# If the following is true, copy custom/homepage.example.js to custom/homepage.js and modify
CUSTOM_HOMEPAGE=false

View file

@ -22,6 +22,7 @@ const config = {
SITE_CANONICAL_URL: process.env.SITE_CANONICAL_URL,
DEFAULT_LANGUAGE: process.env.DEFAULT_LANGUAGE,
AUTO_FOLLOW_CHANNELS: process.env.AUTO_FOLLOW_CHANNELS,
UNSYNCED_SETTINGS: process.env.UNSYNCED_SETTINGS,
SIMPLE_SITE: process.env.SIMPLE_SITE === 'true',
SHOW_ADS: process.env.SHOW_ADS === 'true',
PINNED_URI_1: process.env.PINNED_URI_1,

View file

@ -3,7 +3,12 @@ import moment from 'moment';
import SUPPORTED_LANGUAGES from 'constants/supported_languages';
import { ACTIONS as LBRY_REDUX_ACTIONS, SETTINGS, SHARED_PREFERENCES } from 'lbry-redux';
import { getSubsetFromKeysArray } from 'util/sync-settings';
import { UNSYNCED_SETTINGS } from 'config';
const { CLIENT_SYNC_KEYS } = SHARED_PREFERENCES;
const settingsToIgnore = (UNSYNCED_SETTINGS && UNSYNCED_SETTINGS.trim().split(' ')) || [];
const clientSyncKeys = settingsToIgnore.length
? CLIENT_SYNC_KEYS.filter(k => !settingsToIgnore.includes(k))
: CLIENT_SYNC_KEYS;
const reducers = {};
let settingLanguage = [];
@ -72,14 +77,6 @@ reducers[ACTIONS.REHYDRATE] = (state, action) => {
return Object.assign({}, state, { clientSettings });
};
reducers[ACTIONS.SYNC_CLIENT_SETTINGS] = state => {
const { clientSettings } = state;
const sharedPreferences = Object.assign({}, state.sharedPreferences);
const selectedClientSettings = getSubsetFromKeysArray(clientSettings, CLIENT_SYNC_KEYS);
const newSharedPreferences = { ...sharedPreferences, ...selectedClientSettings };
return Object.assign({}, state, { sharedPreferences: newSharedPreferences });
};
reducers[ACTIONS.FINDING_FFMPEG_STARTED] = state =>
Object.assign({}, state, {
findingFFmpeg: true,
@ -157,11 +154,20 @@ reducers[ACTIONS.CLIENT_SETTING_CHANGED] = (state, action) => {
});
};
reducers[ACTIONS.SYNC_CLIENT_SETTINGS] = state => {
const { clientSettings } = state;
const sharedPreferences = Object.assign({}, state.sharedPreferences);
const selectedClientSettings = getSubsetFromKeysArray(clientSettings, clientSyncKeys);
const newSharedPreferences = { ...sharedPreferences, ...selectedClientSettings };
return Object.assign({}, state, { sharedPreferences: newSharedPreferences });
};
reducers[LBRY_REDUX_ACTIONS.USER_STATE_POPULATE] = (state, action) => {
const { clientSettings: currentClientSettings } = state;
const { settings: sharedPreferences } = action.data;
if (currentClientSettings[SETTINGS.ENABLE_SYNC]) {
const selectedSettings = getSubsetFromKeysArray(sharedPreferences, CLIENT_SYNC_KEYS);
const selectedSettings = getSubsetFromKeysArray(sharedPreferences, clientSyncKeys);
const mergedClientSettings = { ...currentClientSettings, ...selectedSettings };
return Object.assign({}, state, { sharedPreferences, clientSettings: mergedClientSettings });
}