clean sync_client_Settings reducer (#7402)

This commit is contained in:
jessopb 2022-01-06 15:30:08 -05:00 committed by GitHub
parent 34283f7be6
commit 220021964d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 8 deletions

View file

@ -14,9 +14,10 @@ import { doAlertWaitingForSync, doGetAndPopulatePreferences } from 'redux/action
import { selectPrefsReady } from 'redux/selectors/sync'; import { selectPrefsReady } from 'redux/selectors/sync';
import { Lbryio } from 'lbryinc'; import { Lbryio } from 'lbryinc';
import { getDefaultLanguage } from 'util/default-languages'; import { getDefaultLanguage } from 'util/default-languages';
import { getSubsetFromKeysArray } from 'util/sync-settings';
const { DEFAULT_LANGUAGE } = require('config'); const { DEFAULT_LANGUAGE } = require('config');
const { SDK_SYNC_KEYS } = SHARED_PREFERENCES; const { SDK_SYNC_KEYS, CLIENT_SYNC_KEYS } = SHARED_PREFERENCES;
export const IS_MAC = process.platform === 'darwin'; export const IS_MAC = process.platform === 'darwin';
const UPDATE_IS_NIGHT_INTERVAL = 5 * 60 * 1000; const UPDATE_IS_NIGHT_INTERVAL = 5 * 60 * 1000;
@ -230,10 +231,17 @@ export function doSetWalletSyncPreference(pref) {
} }
export function doPushSettingsToPrefs() { export function doPushSettingsToPrefs() {
return (dispatch) => { return (dispatch, getState) => {
const state = getState();
const { clientSettings } = state;
const sharedPreferences = Object.assign({}, state.sharedPreferences);
const selectedClientSettings = getSubsetFromKeysArray(clientSettings, CLIENT_SYNC_KEYS);
const newSharedPreferences = { ...sharedPreferences, ...selectedClientSettings };
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
dispatch({ dispatch({
type: ACTIONS.SYNC_CLIENT_SETTINGS, type: ACTIONS.SYNC_CLIENT_SETTINGS,
data: newSharedPreferences,
}); });
resolve(); resolve();
}); });

View file

@ -162,12 +162,9 @@ reducers[ACTIONS.SHARED_PREFERENCE_SET] = (state, action) => {
}); });
}; };
reducers[ACTIONS.SYNC_CLIENT_SETTINGS] = (state) => { reducers[ACTIONS.SYNC_CLIENT_SETTINGS] = (state, action) => {
const { clientSettings } = state; const { data } = action;
const sharedPreferences = Object.assign({}, state.sharedPreferences); return Object.assign({}, state, { sharedPreferences: data });
const selectedClientSettings = getSubsetFromKeysArray(clientSettings, clientSyncKeys);
const newSharedPreferences = { ...sharedPreferences, ...selectedClientSettings };
return Object.assign({}, state, { sharedPreferences: newSharedPreferences });
}; };
reducers[ACTIONS.USER_STATE_POPULATE] = (state, action) => { reducers[ACTIONS.USER_STATE_POPULATE] = (state, action) => {