From b337a4560ec9e57d461be9eb44fc057d3c4bd3bc Mon Sep 17 00:00:00 2001 From: Curtis ROck Date: Mon, 31 Aug 2020 22:00:11 -0500 Subject: [PATCH 1/3] Apply non-blank default BrandColor only when API and soapbox.json methods fail, and only when API and/or JSON method succeeds, but brandColor value is blank --- app/soapbox/actions/soapbox.js | 10 ++++++++-- app/soapbox/reducers/soapbox.js | 10 +++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/soapbox/actions/soapbox.js b/app/soapbox/actions/soapbox.js index eedd1787f..f975bf848 100644 --- a/app/soapbox/actions/soapbox.js +++ b/app/soapbox/actions/soapbox.js @@ -7,7 +7,7 @@ export const SOAPBOX_CONFIG_REQUEST_FAIL = 'SOAPBOX_CONFIG_REQUEST_FAIL'; export const defaultConfig = ImmutableMap({ logo: '', banner: '', - brandColor: '#0482d8', // Azure + brandColor: '', // Empty customCss: ImmutableList(), promoPanel: ImmutableMap({ items: ImmutableList(), @@ -48,7 +48,13 @@ export function fetchSoapboxJson() { }; } -export function importSoapboxConfig(soapboxConfig) { +export function importSoapboxConfig(soapboxConfig, getIn) { + if(soapboxConfig.get('brandColor') === '') { + const defaultBrandColor = ImmutableMap({ + brandColor: '#0482d8', // Azure + }); + defaultBrandColor.mergeDeep(soapboxConfig); + }; return { type: SOAPBOX_CONFIG_REQUEST_SUCCESS, soapboxConfig, diff --git a/app/soapbox/reducers/soapbox.js b/app/soapbox/reducers/soapbox.js index dd7b0bea3..c58b22ddb 100644 --- a/app/soapbox/reducers/soapbox.js +++ b/app/soapbox/reducers/soapbox.js @@ -1,5 +1,8 @@ import { ADMIN_CONFIG_UPDATE_SUCCESS } from '../actions/admin'; -import { SOAPBOX_CONFIG_REQUEST_SUCCESS } from '../actions/soapbox'; +import { + SOAPBOX_CONFIG_REQUEST_SUCCESS, + SOAPBOX_CONFIG_REQUEST_FAIL, +} from '../actions/soapbox'; import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable'; import { ConfigDB } from 'soapbox/utils/config_db'; @@ -22,6 +25,11 @@ export default function soapbox(state = initialState, action) { switch(action.type) { case SOAPBOX_CONFIG_REQUEST_SUCCESS: return fromJS(action.soapboxConfig); + case SOAPBOX_CONFIG_REQUEST_FAIL: + const defaultBrandColor = ImmutableMap({ + brandColor: '#0482d8', // Azure + }); + return defaultBrandColor.mergeDeep(state.get('soapbox')); case ADMIN_CONFIG_UPDATE_SUCCESS: return updateFromAdmin(state, fromJS(action.config)); default: From 181eef1edd0fd67693940665d82251f1efa51d55 Mon Sep 17 00:00:00 2001 From: Curtis ROck Date: Wed, 2 Sep 2020 21:47:46 -0500 Subject: [PATCH 2/3] corrected errors --- app/soapbox/actions/soapbox.js | 9 +++------ app/soapbox/reducers/soapbox.js | 9 +++++---- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/app/soapbox/actions/soapbox.js b/app/soapbox/actions/soapbox.js index f975bf848..e6cced78b 100644 --- a/app/soapbox/actions/soapbox.js +++ b/app/soapbox/actions/soapbox.js @@ -48,12 +48,9 @@ export function fetchSoapboxJson() { }; } -export function importSoapboxConfig(soapboxConfig, getIn) { - if(soapboxConfig.get('brandColor') === '') { - const defaultBrandColor = ImmutableMap({ - brandColor: '#0482d8', // Azure - }); - defaultBrandColor.mergeDeep(soapboxConfig); +export function importSoapboxConfig(soapboxConfig) { + if (!soapboxConfig.brandColor) { + soapboxConfig.brandColor = '#0482d8'; }; return { type: SOAPBOX_CONFIG_REQUEST_SUCCESS, diff --git a/app/soapbox/reducers/soapbox.js b/app/soapbox/reducers/soapbox.js index c58b22ddb..3e448add2 100644 --- a/app/soapbox/reducers/soapbox.js +++ b/app/soapbox/reducers/soapbox.js @@ -8,6 +8,10 @@ import { ConfigDB } from 'soapbox/utils/config_db'; const initialState = ImmutableMap(); +const fallbackState = ImmutableMap({ + brandColor: '#0482d8', // Azure +}); + const updateFromAdmin = (state, config) => { const configs = config.get('configs', ImmutableList()); @@ -26,10 +30,7 @@ export default function soapbox(state = initialState, action) { case SOAPBOX_CONFIG_REQUEST_SUCCESS: return fromJS(action.soapboxConfig); case SOAPBOX_CONFIG_REQUEST_FAIL: - const defaultBrandColor = ImmutableMap({ - brandColor: '#0482d8', // Azure - }); - return defaultBrandColor.mergeDeep(state.get('soapbox')); + return fallbackState.mergeDeep(state.get('soapbox')); case ADMIN_CONFIG_UPDATE_SUCCESS: return updateFromAdmin(state, fromJS(action.config)); default: From 91605d7d911f8eccbad7dae543488a98e2d0e750 Mon Sep 17 00:00:00 2001 From: crockwave Date: Thu, 3 Sep 2020 11:10:03 -0500 Subject: [PATCH 3/3] Fixed reducer error --- app/soapbox/reducers/soapbox.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/soapbox/reducers/soapbox.js b/app/soapbox/reducers/soapbox.js index 3e448add2..ecf1656f5 100644 --- a/app/soapbox/reducers/soapbox.js +++ b/app/soapbox/reducers/soapbox.js @@ -30,7 +30,7 @@ export default function soapbox(state = initialState, action) { case SOAPBOX_CONFIG_REQUEST_SUCCESS: return fromJS(action.soapboxConfig); case SOAPBOX_CONFIG_REQUEST_FAIL: - return fallbackState.mergeDeep(state.get('soapbox')); + return fallbackState.mergeDeep(state); case ADMIN_CONFIG_UPDATE_SUCCESS: return updateFromAdmin(state, fromJS(action.config)); default: