From c53210c3d7818c6b02c7d86d78bcb61e58707605 Mon Sep 17 00:00:00 2001 From: leuryr Date: Mon, 8 Feb 2021 13:08:42 -0500 Subject: [PATCH 1/9] Preserve onboarding selections on back --- .../BlockSettingsView.jsx | 95 +++++++++++++++---- .../__tests__/BlockSettingsView.test.jsx | 5 +- .../Step2_BlockSettingsView/index.js | 5 +- .../ChooseDefaultSearchView.jsx | 21 +++- .../Step3_ChooseDefaultSearchView/index.js | 5 +- .../actions/SetupLifecycleActions.js | 18 +++- .../constants/SetupLifecycleConstants.js | 2 + app/shared-hub/reducers/AntiSuiteReducer.js | 14 ++- .../reducers/BlockingPolicyReducer.js | 6 +- .../reducers/SetupLifecycleReducer.js | 23 ++++- .../__tests__/AntiSuiteReducer.test.js | 16 ++-- .../__tests__/BlockingPolicyReducer.test.js | 12 +-- .../__tests__/SetupLifeCycleReducer.test.js | 19 +++- 13 files changed, 188 insertions(+), 53 deletions(-) diff --git a/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/BlockSettingsView.jsx b/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/BlockSettingsView.jsx index 594ab7a04..af3ed6762 100644 --- a/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/BlockSettingsView.jsx +++ b/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/BlockSettingsView.jsx @@ -30,13 +30,70 @@ class BlockSettingsView extends Component { super(props); this.state = { recommendedChoices: false, - enable_ad_block: null, kindsOfTrackers: null, + enable_ad_block: null, enable_anti_tracking: null, enable_smart_block: null }; } + componentDidMount() { + const { setupLifecycle: { blockSetupSeen } } = this.props; + if (blockSetupSeen) { + const { + antiSuite: { + enable_anti_tracking, + enable_ad_block, + enable_smart_block, + }, + blockingPolicy + } = this.props; + + const decodedPolicy = this.decodeBlockingPolicy(blockingPolicy); + + this.setState({ + kindsOfTrackers: decodedPolicy, + enable_ad_block, + enable_anti_tracking, + enable_smart_block + }); + } + } + + decodeBlockingPolicy = (blockingPolicy) => { + let decodedPolicy; + if (typeof blockingPolicy === 'number') { + switch (blockingPolicy) { + case 1: + decodedPolicy = 'BLOCKING_POLICY_EVERYTHING'; + break; + case 2: + decodedPolicy = 'BLOCKING_POLICY_RECOMMENDED'; + break; + case 3: + decodedPolicy = 'BLOCKING_POLICY_NOTHING'; + break; + default: + break; + } + } else if (typeof blockingPolicy === 'string') { + switch (blockingPolicy) { + case 'BLOCKING_POLICY_EVERYTHING': + decodedPolicy = 1; + break; + case 'BLOCKING_POLICY_RECOMMENDED': + decodedPolicy = 2; + break; + case 'BLOCKING_POLICY_NOTHING': + decodedPolicy = 3; + break; + default: + break; + } + } + return decodedPolicy; + } + toggleRecommendedChoices = (value) => { if (value === true) { this.setState({ @@ -94,7 +151,7 @@ class BlockSettingsView extends Component { }); const { - setAdBlock, setAntiTracking, setSmartBlocking, setBlockingPolicy, setSetupStep + setAdBlock, setAntiTracking, setSmartBlocking, setBlockingPolicy, setSetupStep, setBlockSetupSeen } = actions; const { history } = this.props; @@ -102,27 +159,16 @@ class BlockSettingsView extends Component { setAntiTracking({ enable_anti_tracking }); setSmartBlocking({ enable_smart_block }); - let blockingPolicy; - switch (kindsOfTrackers) { - case 1: - blockingPolicy = 'BLOCKING_POLICY_EVERYTHING'; - break; - case 2: - blockingPolicy = 'BLOCKING_POLICY_RECOMMENDED'; - break; - case 3: - blockingPolicy = 'BLOCKING_POLICY_NOTHING'; - break; - default: - break; - } - setBlockingPolicy({ blockingPolicy }); + const decodedPolicy = this.decodeBlockingPolicy(kindsOfTrackers); + + setBlockingPolicy({ blockingPolicy: decodedPolicy }); setSetupStep({ setup_step: BLOCK_SETTINGS, dawn_setup_number: this.buildSetupNumberString(), origin: ONBOARDING }); + setBlockSetupSeen(true); history.push('/onboarding/3'); } else { setToast({ @@ -231,5 +277,20 @@ BlockSettingsView.propTypes = { setBlockingPolicy: PropTypes.func.isRequired, setToast: PropTypes.func.isRequired, setSetupStep: PropTypes.func.isRequired, + setBlockSetupSeen: PropTypes.func.isRequired, + }).isRequired, + setupLifecycle: PropTypes.shape({ + blockingPolicy: PropTypes.string.isRequired, + enable_anti_tracking: PropTypes.bool.isRequired, + enable_ad_block: PropTypes.bool.isRequired, + enable_smart_block: PropTypes.bool.isRequired, + blockSetupSeen: PropTypes.bool.isRequired, + searchSetupSeen: PropTypes.bool.isRequired, + }).isRequired, + antiSuite: PropTypes.shape({ + enable_ad_block: PropTypes.bool.isRequired, + enable_anti_tracking: PropTypes.bool.isRequired, + enable_smart_block: PropTypes.bool.isRequired, }).isRequired, + blockingPolicy: PropTypes.string.isRequired }; diff --git a/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/__tests__/BlockSettingsView.test.jsx b/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/__tests__/BlockSettingsView.test.jsx index 614643426..c8c3ebdd2 100644 --- a/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/__tests__/BlockSettingsView.test.jsx +++ b/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/__tests__/BlockSettingsView.test.jsx @@ -22,6 +22,7 @@ jest.mock('../../../../../shared-components/Tooltip'); describe('app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/BlockSettingsView.test.jsx', () => { const initialState = { + setupLifecycle: noop, actions: { logout: noop, setAntiTracking: noop, @@ -30,7 +31,8 @@ describe('app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/BlockSettin setBlockingPolicy: noop, setToast: noop, setSetupStep: noop, - } + setBlockSetupSeen: noop, + }, }; describe('Snapshot tests with react-test-renderer', () => { test('BlockSettings View is rendered correctly', () => { @@ -55,6 +57,7 @@ describe('app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/BlockSettin setBlockingPolicy: jest.fn(), setToast: noop, setSetupStep: jest.fn(), + setBlockSetupSeen: jest.fn(), }, history: { push: noop diff --git a/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/index.js b/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/index.js index ec60917d4..6392f43ed 100644 --- a/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/index.js +++ b/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/index.js @@ -18,7 +18,7 @@ import { logout } from '../../../../Account/AccountActions'; import { setAntiTracking, setAdBlock, setSmartBlocking } from '../../../../shared-hub/actions/AntiSuiteActions'; import setBlockingPolicy from '../../../../shared-hub/actions/BlockingPolicyActions'; import setToast from '../../../../shared-hub/actions/ToastActions'; -import { setSetupStep } from '../../../../shared-hub/actions/SetupLifecycleActions'; +import { setSetupStep, setBlockSetupSeen } from '../../../../shared-hub/actions/SetupLifecycleActions'; const actionCreators = { logout, @@ -26,8 +26,9 @@ const actionCreators = { setAdBlock, setSmartBlocking, setBlockingPolicy, + setBlockSetupSeen, setToast, setSetupStep, }; -export default withRouter(buildReduxHOC(null, actionCreators, BlockSettingsView)); +export default withRouter(buildReduxHOC(['setupLifecycle', 'antiSuite', 'blockingPolicy'], actionCreators, BlockSettingsView)); diff --git a/app/dawn-hub/Views/OnboardingViews/Step3_ChooseDefaultSearchView/ChooseDefaultSearchView.jsx b/app/dawn-hub/Views/OnboardingViews/Step3_ChooseDefaultSearchView/ChooseDefaultSearchView.jsx index 74ad2145f..6a8460d7c 100644 --- a/app/dawn-hub/Views/OnboardingViews/Step3_ChooseDefaultSearchView/ChooseDefaultSearchView.jsx +++ b/app/dawn-hub/Views/OnboardingViews/Step3_ChooseDefaultSearchView/ChooseDefaultSearchView.jsx @@ -78,6 +78,24 @@ class ChooseDefaultSearchView extends Component { document.addEventListener('click', this.handleClickAway); this.fetchSearchEnginesAsync(); + + const { setupLifecycle: { searchSetupSeen } } = this.props; + + if (searchSetupSeen) { + const { defaultSearch } = this.props; + const searchChoices = [ + SEARCH_GHOSTERY, + SEARCH_BING, + SEARCH_YAHOO, + SEARCH_STARTPAGE, + ]; + const isOther = searchChoices.reduce((accum, choice) => { + if (accum === false) return false; + return choice !== defaultSearch; + }, false); + const prevChosenSearch = isOther ? SEARCH_OTHER : defaultSearch; + this.setState({ chosenSearch: prevChosenSearch, otherSearchSelected: isOther ? prevChosenSearch : null }); + } } componentWillUnmount() { @@ -140,7 +158,7 @@ class ChooseDefaultSearchView extends Component { handleSubmit = () => { const { chosenSearch, otherSearchSelected } = this.state; const { actions, history } = this.props; - const { setSetupStep, setDefaultSearch } = actions; + const { setSetupStep, setDefaultSearch, setSearchSetupSeen } = actions; const chosenSearchName = chosenSearch === SEARCH_OTHER ? otherSearchSelected @@ -173,6 +191,7 @@ class ChooseDefaultSearchView extends Component { dawn_setup_number, origin: ONBOARDING }); + setSearchSetupSeen(true); history.push(`/${ONBOARDING}/${CHOOSE_PLAN}`); } diff --git a/app/dawn-hub/Views/OnboardingViews/Step3_ChooseDefaultSearchView/index.js b/app/dawn-hub/Views/OnboardingViews/Step3_ChooseDefaultSearchView/index.js index bd33072be..ec5f910ad 100644 --- a/app/dawn-hub/Views/OnboardingViews/Step3_ChooseDefaultSearchView/index.js +++ b/app/dawn-hub/Views/OnboardingViews/Step3_ChooseDefaultSearchView/index.js @@ -15,11 +15,12 @@ import { withRouter } from 'react-router-dom'; import ChooseDefaultSearchView from './ChooseDefaultSearchView'; import { buildReduxHOC } from '../../../../shared-hub/utils'; import setDefaultSearch from './ChooseDefaultSearchActions'; -import { setSetupStep } from '../../../../shared-hub/actions/SetupLifecycleActions'; +import { setSetupStep, setSearchSetupSeen } from '../../../../shared-hub/actions/SetupLifecycleActions'; const actionCreators = { setDefaultSearch, setSetupStep, + setSearchSetupSeen, }; -export default withRouter(buildReduxHOC(null, actionCreators, ChooseDefaultSearchView)); +export default withRouter(buildReduxHOC(['setupLifecycle', 'defaultSearch'], actionCreators, ChooseDefaultSearchView)); diff --git a/app/shared-hub/actions/SetupLifecycleActions.js b/app/shared-hub/actions/SetupLifecycleActions.js index 3f40698e9..bb93c9c9e 100644 --- a/app/shared-hub/actions/SetupLifecycleActions.js +++ b/app/shared-hub/actions/SetupLifecycleActions.js @@ -15,7 +15,9 @@ import { makeDeferredDispatcher } from '../utils'; import { INIT_SETUP_PROPS, SET_SETUP_STEP, - SET_SETUP_COMPLETE + SET_SETUP_COMPLETE, + SET_BLOCK_SETUP_SEEN, + SET_SEARCH_SETUP_SEEN } from '../constants/SetupLifecycleConstants'; export function initSetupProps(data) { @@ -25,6 +27,20 @@ export function initSetupProps(data) { }; } +export const setBlockSetupSeen = data => ( + { + type: SET_BLOCK_SETUP_SEEN, + data, + } +); + +export const setSearchSetupSeen = data => ( + { + type: SET_SEARCH_SETUP_SEEN, + data, + } +); + export const setSetupStep = actionData => makeDeferredDispatcher(SET_SETUP_STEP, actionData); diff --git a/app/shared-hub/constants/SetupLifecycleConstants.js b/app/shared-hub/constants/SetupLifecycleConstants.js index 97c968d3e..5fe3c3fb9 100644 --- a/app/shared-hub/constants/SetupLifecycleConstants.js +++ b/app/shared-hub/constants/SetupLifecycleConstants.js @@ -14,3 +14,5 @@ export const INIT_SETUP_PROPS = 'INIT_SETUP_PROPS'; export const SET_SETUP_STEP = 'SET_SETUP_STEP'; export const SET_SETUP_COMPLETE = 'SET_SETUP_COMPLETE'; +export const SET_BLOCK_SETUP_SEEN = 'SET_BLOCK_SETUP_SEEN'; +export const SET_SEARCH_SETUP_SEEN = 'SET_SEARCH_SETUP_SEEN'; diff --git a/app/shared-hub/reducers/AntiSuiteReducer.js b/app/shared-hub/reducers/AntiSuiteReducer.js index 458ce5558..3ff6d97cd 100644 --- a/app/shared-hub/reducers/AntiSuiteReducer.js +++ b/app/shared-hub/reducers/AntiSuiteReducer.js @@ -17,21 +17,27 @@ import { SET_SMART_BLOCK } from '../constants/AntiSuiteConstants'; -const initialState = {}; +const initialState = { + antiSuite: { + enable_ad_block: false, + enable_anti_tracking: false, + enable_smart_block: false + } +}; function AntiSuiteReducer(state = initialState, action) { switch (action.type) { case SET_AD_BLOCK: { const { enable_ad_block } = action.data; - return { ...state, setup: { ...state.setup, enable_ad_block } }; + return { ...state, antiSuite: { ...state.antiSuite, enable_ad_block } }; } case SET_ANTI_TRACKING: { const { enable_anti_tracking } = action.data; - return { ...state, setup: { ...state.setup, enable_anti_tracking } }; + return { ...state, antiSuite: { ...state.antiSuite, enable_anti_tracking } }; } case SET_SMART_BLOCK: { const { enable_smart_block } = action.data; - return { ...state, setup: { ...state.setup, enable_smart_block } }; + return { ...state, antiSuite: { ...state.antiSuite, enable_smart_block } }; } default: return state; diff --git a/app/shared-hub/reducers/BlockingPolicyReducer.js b/app/shared-hub/reducers/BlockingPolicyReducer.js index 81e677584..8c2710bfa 100644 --- a/app/shared-hub/reducers/BlockingPolicyReducer.js +++ b/app/shared-hub/reducers/BlockingPolicyReducer.js @@ -13,13 +13,15 @@ import { SET_BLOCKING_POLICY } from '../constants/BlockingPolicyConstants'; -const initialState = {}; +const initialState = { + blockingPolicy: '' +}; function BlockingPolicyReducer(state = initialState, action) { switch (action.type) { case SET_BLOCKING_POLICY: { const { blockingPolicy } = action.data; - return { ...state, setup: { ...state.setup, blockingPolicy } }; + return { ...state, blockingPolicy }; } default: return state; diff --git a/app/shared-hub/reducers/SetupLifecycleReducer.js b/app/shared-hub/reducers/SetupLifecycleReducer.js index 3d30ac6c8..2e6dbc272 100644 --- a/app/shared-hub/reducers/SetupLifecycleReducer.js +++ b/app/shared-hub/reducers/SetupLifecycleReducer.js @@ -12,10 +12,19 @@ */ import { - INIT_SETUP_PROPS + INIT_SETUP_PROPS, SET_BLOCK_SETUP_SEEN, SET_SEARCH_SETUP_SEEN } from '../constants/SetupLifecycleConstants'; -const initialState = {}; +const initialState = { + setupLifecycle: { + blockingPolicy: '', + enable_anti_tracking: false, + enable_ad_block: false, + enable_smart_block: false, + blockSetupSeen: false, + searchSetupSeen: false + } +}; function SetupLifecycleReducer(state = initialState, action) { switch (action.type) { @@ -29,14 +38,22 @@ function SetupLifecycleReducer(state = initialState, action) { } = action.data; return { ...state, - setup: { + setupLifecycle: { blockingPolicy, enable_anti_tracking, enable_ad_block, enable_smart_block, + blockSetupSeen: false, + searchSetupSeen: false } }; } + case SET_BLOCK_SETUP_SEEN: { + return { ...state, setupLifecycle: { ...state.setupLifecycle, blockSetupSeen: action.data } }; + } + case SET_SEARCH_SETUP_SEEN: { + return { ...state, setupLifecycle: { ...state.setupLifecycle, searchSetupSeen: action.data } }; + } default: return state; } diff --git a/app/shared-hub/reducers/__tests__/AntiSuiteReducer.test.js b/app/shared-hub/reducers/__tests__/AntiSuiteReducer.test.js index 3bd25668f..2cd06ce43 100644 --- a/app/shared-hub/reducers/__tests__/AntiSuiteReducer.test.js +++ b/app/shared-hub/reducers/__tests__/AntiSuiteReducer.test.js @@ -16,7 +16,7 @@ import AntiSuiteReducer from '../AntiSuiteReducer'; import { SET_AD_BLOCK, SET_ANTI_TRACKING, SET_SMART_BLOCK } from '../../constants/AntiSuiteConstants'; const initialState = Immutable({ - setup: { + antiSuite: { enable_ad_block: false, enable_anti_tracking: false, enable_smart_block: false @@ -25,7 +25,7 @@ const initialState = Immutable({ describe('app/shared-hub/reducers/AntiSuiteReducer', () => { test('initial state is correct', () => { - expect(AntiSuiteReducer(undefined, {})).toEqual({}); + expect(AntiSuiteReducer(undefined, {})).toEqual({...initialState}); }); test('reducer correctly handles SET_AD_BLOCK', () => { @@ -34,10 +34,10 @@ describe('app/shared-hub/reducers/AntiSuiteReducer', () => { }; const action = { data, type: SET_AD_BLOCK }; - const updatedAntiSuiteState = Immutable.merge(initialState.setup, data); + const updatedAntiSuiteState = Immutable.merge(initialState.antiSuite, data); expect(AntiSuiteReducer(initialState, action)).toEqual({ - setup: updatedAntiSuiteState + antiSuite: updatedAntiSuiteState }); }); @@ -47,10 +47,10 @@ describe('app/shared-hub/reducers/AntiSuiteReducer', () => { }; const action = { data, type: SET_ANTI_TRACKING }; - const updatedAntiSuiteState = Immutable.merge(initialState.setup, data); + const updatedAntiSuiteState = Immutable.merge(initialState.antiSuite, data); expect(AntiSuiteReducer(initialState, action)).toEqual({ - setup: updatedAntiSuiteState + antiSuite: updatedAntiSuiteState }); }); @@ -60,10 +60,10 @@ describe('app/shared-hub/reducers/AntiSuiteReducer', () => { }; const action = { data, type: SET_SMART_BLOCK }; - const updatedAntiSuiteState = Immutable.merge(initialState.setup, data); + const updatedAntiSuiteState = Immutable.merge(initialState.antiSuite, data); expect(AntiSuiteReducer(initialState, action)).toEqual({ - setup: updatedAntiSuiteState + antiSuite: updatedAntiSuiteState }); }); }); diff --git a/app/shared-hub/reducers/__tests__/BlockingPolicyReducer.test.js b/app/shared-hub/reducers/__tests__/BlockingPolicyReducer.test.js index b97efc8b1..9aa6d0f2c 100644 --- a/app/shared-hub/reducers/__tests__/BlockingPolicyReducer.test.js +++ b/app/shared-hub/reducers/__tests__/BlockingPolicyReducer.test.js @@ -16,26 +16,24 @@ import BlockingPolicyReducer from '../BlockingPolicyReducer'; import { SET_BLOCKING_POLICY } from '../../constants/BlockingPolicyConstants'; const initialState = Immutable({ - setup: { - blockingPolicy: true - } + blockingPolicy: '' }); describe('app/shared-hub/reducers/BlockingPolicy', () => { test('initial state is correct', () => { - expect(BlockingPolicyReducer(undefined, {})).toEqual({}); + expect(BlockingPolicyReducer(undefined, {})).toEqual({...initialState}); }); test('reducer correctly handles SET_BLOCKING_POLICY', () => { const data = { - blockingPolicy: true, + blockingPolicy: 'BLOCKING_POLICY_RECOMMENDED', }; const action = { data, type: SET_BLOCKING_POLICY }; - const updatedBlockingPolicyState = Immutable.merge(initialState.setup, data); + const updatedBlockingPolicyState = Immutable.merge(initialState, data); expect(BlockingPolicyReducer(initialState, action)).toEqual({ - setup: updatedBlockingPolicyState + ...updatedBlockingPolicyState }); }); }); diff --git a/app/shared-hub/reducers/__tests__/SetupLifeCycleReducer.test.js b/app/shared-hub/reducers/__tests__/SetupLifeCycleReducer.test.js index 49659a6c1..e1772d4b9 100644 --- a/app/shared-hub/reducers/__tests__/SetupLifeCycleReducer.test.js +++ b/app/shared-hub/reducers/__tests__/SetupLifeCycleReducer.test.js @@ -16,27 +16,36 @@ import SetupLifecycleReducer from '../SetupLifecycleReducer'; import { INIT_SETUP_PROPS } from '../../constants/SetupLifecycleConstants'; const initialState = Immutable({ - setup: {} + setupLifecycle: { + blockingPolicy: '', + enable_anti_tracking: false, + enable_ad_block: false, + enable_smart_block: false, + blockSetupSeen: false, + searchSetupSeen: false + } }); describe('app/shared-hub/reducers/SetupLifecycleReducer', () => { test('initial state is correct', () => { - expect(SetupLifecycleReducer(undefined, {})).toEqual({}); + expect(SetupLifecycleReducer(undefined, {})).toEqual({...initialState}); }); test('reducer correctly handles INIT_SETUP_PROPS', () => { const data = { - blockingPolicy: true, + blockingPolicy: 'BLOCKING_POLICY_RECOMMENDED', enable_anti_tracking: true, enable_ad_block: true, enable_smart_block: true, + blockSetupSeen: false, + searchSetupSeen: false }; const action = { data, type: INIT_SETUP_PROPS }; - const updatedSetupLifecycleState = Immutable.merge(initialState.setup, data); + const updatedSetupLifecycleState = Immutable.merge(initialState.setupLifecycle, data); expect(SetupLifecycleReducer(initialState, action)).toEqual({ - setup: updatedSetupLifecycleState + setupLifecycle: updatedSetupLifecycleState }); }); }); From 45caa111532dd437b89b6902f099491ef02c7d96 Mon Sep 17 00:00:00 2001 From: leuryr Date: Fri, 19 Feb 2021 09:35:32 -0500 Subject: [PATCH 2/9] Simplify and fix default browser check --- .../ChooseDefaultSearchView.jsx | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/app/dawn-hub/Views/OnboardingViews/Step3_ChooseDefaultSearchView/ChooseDefaultSearchView.jsx b/app/dawn-hub/Views/OnboardingViews/Step3_ChooseDefaultSearchView/ChooseDefaultSearchView.jsx index 6a8460d7c..4c1e74a32 100644 --- a/app/dawn-hub/Views/OnboardingViews/Step3_ChooseDefaultSearchView/ChooseDefaultSearchView.jsx +++ b/app/dawn-hub/Views/OnboardingViews/Step3_ChooseDefaultSearchView/ChooseDefaultSearchView.jsx @@ -89,12 +89,9 @@ class ChooseDefaultSearchView extends Component { SEARCH_YAHOO, SEARCH_STARTPAGE, ]; - const isOther = searchChoices.reduce((accum, choice) => { - if (accum === false) return false; - return choice !== defaultSearch; - }, false); + const isOther = !searchChoices.includes(defaultSearch); const prevChosenSearch = isOther ? SEARCH_OTHER : defaultSearch; - this.setState({ chosenSearch: prevChosenSearch, otherSearchSelected: isOther ? prevChosenSearch : null }); + this.setState({ chosenSearch: prevChosenSearch, otherSearchSelected: isOther ? defaultSearch : null }); } } From ccfb5dcfecb78bfbe434049527ac6f9a172ba848 Mon Sep 17 00:00:00 2001 From: leuryr Date: Fri, 19 Feb 2021 09:36:35 -0500 Subject: [PATCH 3/9] Remove antiSuite wrapper, update checkbox --- .../BlockSettingsView.jsx | 27 +++++++++++++++---- app/shared-hub/reducers/AntiSuiteReducer.js | 14 +++++----- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/BlockSettingsView.jsx b/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/BlockSettingsView.jsx index af3ed6762..b65439401 100644 --- a/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/BlockSettingsView.jsx +++ b/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/BlockSettingsView.jsx @@ -39,13 +39,12 @@ class BlockSettingsView extends Component { componentDidMount() { const { setupLifecycle: { blockSetupSeen } } = this.props; + if (blockSetupSeen) { const { - antiSuite: { - enable_anti_tracking, - enable_ad_block, - enable_smart_block, - }, + enable_anti_tracking, + enable_ad_block, + enable_smart_block, blockingPolicy } = this.props; @@ -60,6 +59,24 @@ class BlockSettingsView extends Component { } } + componentDidUpdate() { + const { + recommendedChoices, + enable_anti_tracking, + enable_ad_block, + enable_smart_block, + kindsOfTrackers + } = this.state; + + if (!recommendedChoices && kindsOfTrackers === 2 && enable_ad_block === true && enable_anti_tracking === true && enable_smart_block === true) { + // eslint-disable-next-line react/no-did-update-set-state + this.setState({ recommendedChoices: true }); + } else if (recommendedChoices && (kindsOfTrackers !== 2 || enable_ad_block !== true || enable_anti_tracking !== true || enable_smart_block !== true)) { + // eslint-disable-next-line react/no-did-update-set-state + this.setState({ recommendedChoices: false }); + } + } + decodeBlockingPolicy = (blockingPolicy) => { let decodedPolicy; if (typeof blockingPolicy === 'number') { diff --git a/app/shared-hub/reducers/AntiSuiteReducer.js b/app/shared-hub/reducers/AntiSuiteReducer.js index 3ff6d97cd..eb184e603 100644 --- a/app/shared-hub/reducers/AntiSuiteReducer.js +++ b/app/shared-hub/reducers/AntiSuiteReducer.js @@ -18,26 +18,24 @@ import { } from '../constants/AntiSuiteConstants'; const initialState = { - antiSuite: { - enable_ad_block: false, - enable_anti_tracking: false, - enable_smart_block: false - } + enable_ad_block: false, + enable_anti_tracking: false, + enable_smart_block: false }; function AntiSuiteReducer(state = initialState, action) { switch (action.type) { case SET_AD_BLOCK: { const { enable_ad_block } = action.data; - return { ...state, antiSuite: { ...state.antiSuite, enable_ad_block } }; + return { ...state, enable_ad_block }; } case SET_ANTI_TRACKING: { const { enable_anti_tracking } = action.data; - return { ...state, antiSuite: { ...state.antiSuite, enable_anti_tracking } }; + return { ...state, enable_anti_tracking }; } case SET_SMART_BLOCK: { const { enable_smart_block } = action.data; - return { ...state, antiSuite: { ...state.antiSuite, enable_smart_block } }; + return { ...state, enable_smart_block }; } default: return state; From a3c31a13f185100fb3d96fa963c0f323df2d166d Mon Sep 17 00:00:00 2001 From: leuryr Date: Mon, 22 Feb 2021 09:41:29 -0500 Subject: [PATCH 4/9] Refactor question blocks --- .../BlockSettingsView.jsx | 47 +++++++++---------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/BlockSettingsView.jsx b/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/BlockSettingsView.jsx index b65439401..f2a51c45e 100644 --- a/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/BlockSettingsView.jsx +++ b/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/BlockSettingsView.jsx @@ -195,6 +195,24 @@ class BlockSettingsView extends Component { } } + renderQuestion = (question, tooltip = null) => { + if (tooltip) { + return ( +
  • +
    + {question} +
    + +
    +
    +
  • + ); + } + return ( +
  • {question}
  • + ); + } + renderAnswerBlock = (checked, category, answer, label) => (
    this.handleAnswerChange(category, answer)}>
    @@ -233,38 +251,17 @@ class BlockSettingsView extends Component {
    this.toggleRecommendedChoices(!recommendedChoices)}>{t('ghostery_dawn_onboarding_recommended_choices')}
      -
    1. {t('ghostery_dawn_onboarding_question_block_ads')}
    2. + {this.renderQuestion(t('ghostery_dawn_onboarding_question_block_ads'))} {this.renderAnswerBlock((enable_ad_block === true), 'enable_ad_block', true, t('hub_setup_modal_button_yes'))} {this.renderAnswerBlock((enable_ad_block === false), 'enable_ad_block', false, t('hub_setup_modal_button_no'))} -
    3. -
      - {t('ghostery_dawn_onboarding_question_kinds_of_trackers')} -
      - -
      -
      -
    4. + {this.renderQuestion(t('ghostery_dawn_onboarding_question_kinds_of_trackers'), t('ghostery_dawn_onboarding_info_blocking_all'))} {this.renderAnswerBlock((kindsOfTrackers === 1), 'kindsOfTrackers', 1, t('ghostery_dawn_onboarding_kinds_of_trackers_all'))} {this.renderAnswerBlock((kindsOfTrackers === 2), 'kindsOfTrackers', 2, t('ghostery_dawn_onboarding_kinds_of_trackers_ad_and_analytics'))} {this.renderAnswerBlock((kindsOfTrackers === 3), 'kindsOfTrackers', 3, t('ghostery_dawn_onboarding_kinds_of_trackers_none'))} -
    5. -
      - {t('ghostery_dawn_onboarding_question_anti_tracking')} -
      - -
      -
      -
    6. + {this.renderQuestion(t('ghostery_dawn_onboarding_question_anti_tracking'), t('ghostery_dawn_onboarding_info_anti_tracking'))} {this.renderAnswerBlock((enable_anti_tracking === true), 'enable_anti_tracking', true, t('hub_setup_modal_button_yes'))} {this.renderAnswerBlock((enable_anti_tracking === false), 'enable_anti_tracking', false, t('hub_setup_modal_button_no'))} -
    7. -
      - {t('ghostery_dawn_onboarding_question_smart_browsing')} -
      - -
      -
      -
    8. + {this.renderQuestion(t('ghostery_dawn_onboarding_question_smart_browsing'), t('ghostery_dawn_onboarding_info_smart_browsing'))} {this.renderAnswerBlock((enable_smart_block === true), 'enable_smart_block', true, t('hub_setup_modal_button_yes'))} {this.renderAnswerBlock((enable_smart_block === false), 'enable_smart_block', false, t('hub_setup_modal_button_no'))}
    From 1cadc463b300abb7dd7e9aefb725c27a938ee073 Mon Sep 17 00:00:00 2001 From: leuryr Date: Mon, 22 Feb 2021 09:50:36 -0500 Subject: [PATCH 5/9] Use Blocking Policy constants --- .../BlockSettingsView.jsx | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/BlockSettingsView.jsx b/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/BlockSettingsView.jsx index f2a51c45e..35595fc62 100644 --- a/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/BlockSettingsView.jsx +++ b/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/BlockSettingsView.jsx @@ -19,6 +19,11 @@ import Tooltip from '../../../../shared-components/Tooltip'; import RadioButton from '../../../../shared-components/RadioButton/RadioButton'; import ToggleCheckbox from '../../../../shared-components/ToggleCheckbox/ToggleCheckbox'; import { BLOCK_SETTINGS, ONBOARDING } from '../../OnboardingView/OnboardingConstants'; +import { + BLOCKING_POLICY_RECOMMENDED, + BLOCKING_POLICY_NOTHING, + BLOCKING_POLICY_EVERYTHING +} from '../../../../shared-hub/constants/BlockingPolicyConstants'; /** * @class Implement the Block Settings View for the Dawn Hub onboarding flow @@ -82,26 +87,26 @@ class BlockSettingsView extends Component { if (typeof blockingPolicy === 'number') { switch (blockingPolicy) { case 1: - decodedPolicy = 'BLOCKING_POLICY_EVERYTHING'; + decodedPolicy = BLOCKING_POLICY_EVERYTHING; break; case 2: - decodedPolicy = 'BLOCKING_POLICY_RECOMMENDED'; + decodedPolicy = BLOCKING_POLICY_RECOMMENDED; break; case 3: - decodedPolicy = 'BLOCKING_POLICY_NOTHING'; + decodedPolicy = BLOCKING_POLICY_NOTHING; break; default: break; } } else if (typeof blockingPolicy === 'string') { switch (blockingPolicy) { - case 'BLOCKING_POLICY_EVERYTHING': + case BLOCKING_POLICY_EVERYTHING: decodedPolicy = 1; break; - case 'BLOCKING_POLICY_RECOMMENDED': + case BLOCKING_POLICY_RECOMMENDED: decodedPolicy = 2; break; - case 'BLOCKING_POLICY_NOTHING': + case BLOCKING_POLICY_NOTHING: decodedPolicy = 3; break; default: From 04e7348d4b0c7d33f1c80d0d4d502d379de89348 Mon Sep 17 00:00:00 2001 From: leuryr Date: Mon, 22 Feb 2021 11:33:27 -0500 Subject: [PATCH 6/9] Update tests and PropTypes --- .../BlockSettingsView.jsx | 13 +++--------- .../__tests__/BlockSettingsView.test.jsx | 8 +++++++- .../__tests__/AntiSuiteReducer.test.js | 20 +++++++++---------- 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/BlockSettingsView.jsx b/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/BlockSettingsView.jsx index 35595fc62..ce2f4794b 100644 --- a/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/BlockSettingsView.jsx +++ b/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/BlockSettingsView.jsx @@ -299,17 +299,10 @@ BlockSettingsView.propTypes = { setBlockSetupSeen: PropTypes.func.isRequired, }).isRequired, setupLifecycle: PropTypes.shape({ - blockingPolicy: PropTypes.string.isRequired, - enable_anti_tracking: PropTypes.bool.isRequired, - enable_ad_block: PropTypes.bool.isRequired, - enable_smart_block: PropTypes.bool.isRequired, blockSetupSeen: PropTypes.bool.isRequired, - searchSetupSeen: PropTypes.bool.isRequired, - }).isRequired, - antiSuite: PropTypes.shape({ - enable_ad_block: PropTypes.bool.isRequired, - enable_anti_tracking: PropTypes.bool.isRequired, - enable_smart_block: PropTypes.bool.isRequired, }).isRequired, + enable_ad_block: PropTypes.bool.isRequired, + enable_anti_tracking: PropTypes.bool.isRequired, + enable_smart_block: PropTypes.bool.isRequired, blockingPolicy: PropTypes.string.isRequired }; diff --git a/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/__tests__/BlockSettingsView.test.jsx b/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/__tests__/BlockSettingsView.test.jsx index c8c3ebdd2..d6461f51b 100644 --- a/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/__tests__/BlockSettingsView.test.jsx +++ b/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/__tests__/BlockSettingsView.test.jsx @@ -22,7 +22,13 @@ jest.mock('../../../../../shared-components/Tooltip'); describe('app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/BlockSettingsView.test.jsx', () => { const initialState = { - setupLifecycle: noop, + setupLifecycle: { + blockSetupSeen: false + }, + blockingPolicy: '', + enable_ad_block: false, + enable_anti_tracking: false, + enable_smart_block: false, actions: { logout: noop, setAntiTracking: noop, diff --git a/app/shared-hub/reducers/__tests__/AntiSuiteReducer.test.js b/app/shared-hub/reducers/__tests__/AntiSuiteReducer.test.js index 2cd06ce43..869898144 100644 --- a/app/shared-hub/reducers/__tests__/AntiSuiteReducer.test.js +++ b/app/shared-hub/reducers/__tests__/AntiSuiteReducer.test.js @@ -16,11 +16,9 @@ import AntiSuiteReducer from '../AntiSuiteReducer'; import { SET_AD_BLOCK, SET_ANTI_TRACKING, SET_SMART_BLOCK } from '../../constants/AntiSuiteConstants'; const initialState = Immutable({ - antiSuite: { - enable_ad_block: false, - enable_anti_tracking: false, - enable_smart_block: false - } + enable_ad_block: false, + enable_anti_tracking: false, + enable_smart_block: false }); describe('app/shared-hub/reducers/AntiSuiteReducer', () => { @@ -34,10 +32,10 @@ describe('app/shared-hub/reducers/AntiSuiteReducer', () => { }; const action = { data, type: SET_AD_BLOCK }; - const updatedAntiSuiteState = Immutable.merge(initialState.antiSuite, data); + const updatedAntiSuiteState = Immutable.merge(initialState, data); expect(AntiSuiteReducer(initialState, action)).toEqual({ - antiSuite: updatedAntiSuiteState + ...updatedAntiSuiteState }); }); @@ -47,10 +45,10 @@ describe('app/shared-hub/reducers/AntiSuiteReducer', () => { }; const action = { data, type: SET_ANTI_TRACKING }; - const updatedAntiSuiteState = Immutable.merge(initialState.antiSuite, data); + const updatedAntiSuiteState = Immutable.merge(initialState, data); expect(AntiSuiteReducer(initialState, action)).toEqual({ - antiSuite: updatedAntiSuiteState + ...updatedAntiSuiteState }); }); @@ -60,10 +58,10 @@ describe('app/shared-hub/reducers/AntiSuiteReducer', () => { }; const action = { data, type: SET_SMART_BLOCK }; - const updatedAntiSuiteState = Immutable.merge(initialState.antiSuite, data); + const updatedAntiSuiteState = Immutable.merge(initialState, data); expect(AntiSuiteReducer(initialState, action)).toEqual({ - antiSuite: updatedAntiSuiteState + ...updatedAntiSuiteState }); }); }); From 06aa58ebb7d07ac819777f0ad9c6856a6c6ae938 Mon Sep 17 00:00:00 2001 From: leuryr Date: Mon, 22 Feb 2021 16:45:02 -0500 Subject: [PATCH 7/9] Refactor blocking policy handling --- .../BlockSettingsView.jsx | 64 +++++++------------ .../__tests__/BlockSettingsView.test.jsx | 5 +- 2 files changed, 26 insertions(+), 43 deletions(-) diff --git a/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/BlockSettingsView.jsx b/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/BlockSettingsView.jsx index ce2f4794b..d040197c6 100644 --- a/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/BlockSettingsView.jsx +++ b/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/BlockSettingsView.jsx @@ -53,10 +53,8 @@ class BlockSettingsView extends Component { blockingPolicy } = this.props; - const decodedPolicy = this.decodeBlockingPolicy(blockingPolicy); - this.setState({ - kindsOfTrackers: decodedPolicy, + kindsOfTrackers: blockingPolicy, enable_ad_block, enable_anti_tracking, enable_smart_block @@ -73,45 +71,29 @@ class BlockSettingsView extends Component { kindsOfTrackers } = this.state; - if (!recommendedChoices && kindsOfTrackers === 2 && enable_ad_block === true && enable_anti_tracking === true && enable_smart_block === true) { + if (!recommendedChoices && kindsOfTrackers === BLOCKING_POLICY_RECOMMENDED && enable_ad_block === true && enable_anti_tracking === true && enable_smart_block === true) { // eslint-disable-next-line react/no-did-update-set-state this.setState({ recommendedChoices: true }); - } else if (recommendedChoices && (kindsOfTrackers !== 2 || enable_ad_block !== true || enable_anti_tracking !== true || enable_smart_block !== true)) { + } else if (recommendedChoices && (kindsOfTrackers !== BLOCKING_POLICY_RECOMMENDED || enable_ad_block !== true || enable_anti_tracking !== true || enable_smart_block !== true)) { // eslint-disable-next-line react/no-did-update-set-state this.setState({ recommendedChoices: false }); } } - decodeBlockingPolicy = (blockingPolicy) => { + enumerateBlockingPolicy = (blockingPolicy) => { let decodedPolicy; - if (typeof blockingPolicy === 'number') { - switch (blockingPolicy) { - case 1: - decodedPolicy = BLOCKING_POLICY_EVERYTHING; - break; - case 2: - decodedPolicy = BLOCKING_POLICY_RECOMMENDED; - break; - case 3: - decodedPolicy = BLOCKING_POLICY_NOTHING; - break; - default: - break; - } - } else if (typeof blockingPolicy === 'string') { - switch (blockingPolicy) { - case BLOCKING_POLICY_EVERYTHING: - decodedPolicy = 1; - break; - case BLOCKING_POLICY_RECOMMENDED: - decodedPolicy = 2; - break; - case BLOCKING_POLICY_NOTHING: - decodedPolicy = 3; - break; - default: - break; - } + switch (blockingPolicy) { + case BLOCKING_POLICY_EVERYTHING: + decodedPolicy = 1; + break; + case BLOCKING_POLICY_RECOMMENDED: + decodedPolicy = 2; + break; + case BLOCKING_POLICY_NOTHING: + decodedPolicy = 3; + break; + default: + break; } return decodedPolicy; } @@ -121,7 +103,7 @@ class BlockSettingsView extends Component { this.setState({ recommendedChoices: true, enable_ad_block: true, - kindsOfTrackers: 2, + kindsOfTrackers: BLOCKING_POLICY_RECOMMENDED, enable_anti_tracking: true, enable_smart_block: true }); @@ -150,7 +132,7 @@ class BlockSettingsView extends Component { } = this.state; const partOne = (enable_ad_block) ? '1' : '2'; - const partTwo = kindsOfTrackers.toString(); + const partTwo = this.enumerateBlockingPolicy(kindsOfTrackers); const partThree = (enable_anti_tracking) ? '1' : '2'; const partFour = (enable_smart_block) ? '1' : '2'; @@ -181,9 +163,7 @@ class BlockSettingsView extends Component { setAntiTracking({ enable_anti_tracking }); setSmartBlocking({ enable_smart_block }); - const decodedPolicy = this.decodeBlockingPolicy(kindsOfTrackers); - - setBlockingPolicy({ blockingPolicy: decodedPolicy }); + setBlockingPolicy({ blockingPolicy: kindsOfTrackers }); setSetupStep({ setup_step: BLOCK_SETTINGS, @@ -260,9 +240,9 @@ class BlockSettingsView extends Component { {this.renderAnswerBlock((enable_ad_block === true), 'enable_ad_block', true, t('hub_setup_modal_button_yes'))} {this.renderAnswerBlock((enable_ad_block === false), 'enable_ad_block', false, t('hub_setup_modal_button_no'))} {this.renderQuestion(t('ghostery_dawn_onboarding_question_kinds_of_trackers'), t('ghostery_dawn_onboarding_info_blocking_all'))} - {this.renderAnswerBlock((kindsOfTrackers === 1), 'kindsOfTrackers', 1, t('ghostery_dawn_onboarding_kinds_of_trackers_all'))} - {this.renderAnswerBlock((kindsOfTrackers === 2), 'kindsOfTrackers', 2, t('ghostery_dawn_onboarding_kinds_of_trackers_ad_and_analytics'))} - {this.renderAnswerBlock((kindsOfTrackers === 3), 'kindsOfTrackers', 3, t('ghostery_dawn_onboarding_kinds_of_trackers_none'))} + {this.renderAnswerBlock((kindsOfTrackers === BLOCKING_POLICY_EVERYTHING), 'kindsOfTrackers', BLOCKING_POLICY_EVERYTHING, t('ghostery_dawn_onboarding_kinds_of_trackers_all'))} + {this.renderAnswerBlock((kindsOfTrackers === BLOCKING_POLICY_RECOMMENDED), 'kindsOfTrackers', BLOCKING_POLICY_RECOMMENDED, t('ghostery_dawn_onboarding_kinds_of_trackers_ad_and_analytics'))} + {this.renderAnswerBlock((kindsOfTrackers === BLOCKING_POLICY_NOTHING), 'kindsOfTrackers', BLOCKING_POLICY_NOTHING, t('ghostery_dawn_onboarding_kinds_of_trackers_none'))} {this.renderQuestion(t('ghostery_dawn_onboarding_question_anti_tracking'), t('ghostery_dawn_onboarding_info_anti_tracking'))} {this.renderAnswerBlock((enable_anti_tracking === true), 'enable_anti_tracking', true, t('hub_setup_modal_button_yes'))} {this.renderAnswerBlock((enable_anti_tracking === false), 'enable_anti_tracking', false, t('hub_setup_modal_button_no'))} diff --git a/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/__tests__/BlockSettingsView.test.jsx b/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/__tests__/BlockSettingsView.test.jsx index d6461f51b..673862770 100644 --- a/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/__tests__/BlockSettingsView.test.jsx +++ b/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/__tests__/BlockSettingsView.test.jsx @@ -16,6 +16,9 @@ import renderer from 'react-test-renderer'; import { shallow } from 'enzyme'; import { MemoryRouter } from 'react-router'; import BlockSettingsView from '../BlockSettingsView'; +import { + BLOCKING_POLICY_RECOMMENDED, +} from '../../../../../shared-hub/constants/BlockingPolicyConstants'; const noop = () => {}; jest.mock('../../../../../shared-components/Tooltip'); @@ -75,7 +78,7 @@ describe('app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/BlockSettin instance.toggleRecommendedChoices(true); expect(component.state('enable_ad_block')).toBe(true); - expect(component.state('kindsOfTrackers')).toBe(2); + expect(component.state('kindsOfTrackers')).toBe(BLOCKING_POLICY_RECOMMENDED); expect(component.state('enable_anti_tracking')).toBe(true); expect(component.state('enable_smart_block')).toBe(true); From ebbab4714c731f49ceedc8f89f13314e1f3ccb00 Mon Sep 17 00:00:00 2001 From: leuryr Date: Wed, 10 Mar 2021 15:10:09 -0500 Subject: [PATCH 8/9] Update recommended choices check --- .../BlockSettingsView.jsx | 33 ++++++++----------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/BlockSettingsView.jsx b/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/BlockSettingsView.jsx index d040197c6..a0f8d877d 100644 --- a/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/BlockSettingsView.jsx +++ b/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/BlockSettingsView.jsx @@ -62,24 +62,6 @@ class BlockSettingsView extends Component { } } - componentDidUpdate() { - const { - recommendedChoices, - enable_anti_tracking, - enable_ad_block, - enable_smart_block, - kindsOfTrackers - } = this.state; - - if (!recommendedChoices && kindsOfTrackers === BLOCKING_POLICY_RECOMMENDED && enable_ad_block === true && enable_anti_tracking === true && enable_smart_block === true) { - // eslint-disable-next-line react/no-did-update-set-state - this.setState({ recommendedChoices: true }); - } else if (recommendedChoices && (kindsOfTrackers !== BLOCKING_POLICY_RECOMMENDED || enable_ad_block !== true || enable_anti_tracking !== true || enable_smart_block !== true)) { - // eslint-disable-next-line react/no-did-update-set-state - this.setState({ recommendedChoices: false }); - } - } - enumerateBlockingPolicy = (blockingPolicy) => { let decodedPolicy; switch (blockingPolicy) { @@ -118,6 +100,19 @@ class BlockSettingsView extends Component { } } + recommendedChoicesActive = () => { + const { + enable_anti_tracking, + enable_ad_block, + enable_smart_block, + kindsOfTrackers + } = this.state; + if (kindsOfTrackers === BLOCKING_POLICY_RECOMMENDED && enable_ad_block === true && enable_anti_tracking === true && enable_smart_block === true) { + return true; + } + return false; + } + handleAnswerChange = (category, answer) => { this.setState({ [category]: answer }); } @@ -230,7 +225,7 @@ class BlockSettingsView extends Component {
    this.toggleRecommendedChoices(!recommendedChoices)} />
    this.toggleRecommendedChoices(!recommendedChoices)}>{t('ghostery_dawn_onboarding_recommended_choices')}
    From fe4c852fd5bbc44609cd1c2959dfb3f9a6384f74 Mon Sep 17 00:00:00 2001 From: leuryr Date: Thu, 11 Mar 2021 13:11:39 -0500 Subject: [PATCH 9/9] Remove recommendedChoices --- .../Step2_BlockSettingsView/BlockSettingsView.jsx | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/BlockSettingsView.jsx b/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/BlockSettingsView.jsx index a0f8d877d..2fd7f1ba4 100644 --- a/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/BlockSettingsView.jsx +++ b/app/dawn-hub/Views/OnboardingViews/Step2_BlockSettingsView/BlockSettingsView.jsx @@ -34,7 +34,6 @@ class BlockSettingsView extends Component { constructor(props) { super(props); this.state = { - recommendedChoices: false, kindsOfTrackers: null, enable_ad_block: null, enable_anti_tracking: null, @@ -83,7 +82,6 @@ class BlockSettingsView extends Component { toggleRecommendedChoices = (value) => { if (value === true) { this.setState({ - recommendedChoices: true, enable_ad_block: true, kindsOfTrackers: BLOCKING_POLICY_RECOMMENDED, enable_anti_tracking: true, @@ -91,7 +89,6 @@ class BlockSettingsView extends Component { }); } else { this.setState({ - recommendedChoices: false, enable_ad_block: null, kindsOfTrackers: null, enable_anti_tracking: null, @@ -204,10 +201,12 @@ class BlockSettingsView extends Component { render() { const { - recommendedChoices, enable_ad_block, kindsOfTrackers, enable_anti_tracking, enable_smart_block + enable_ad_block, kindsOfTrackers, enable_anti_tracking, enable_smart_block } = this.state; const { actions } = this.props; const { logout } = actions; + + const recommendedChoicesActive = this.recommendedChoicesActive(); return (
    @@ -225,10 +224,10 @@ class BlockSettingsView extends Component {
    this.toggleRecommendedChoices(!recommendedChoices)} + checked={recommendedChoicesActive} + onChange={() => this.toggleRecommendedChoices(!recommendedChoicesActive)} /> -
    this.toggleRecommendedChoices(!recommendedChoices)}>{t('ghostery_dawn_onboarding_recommended_choices')}
    +
    this.toggleRecommendedChoices(!recommendedChoicesActive)}>{t('ghostery_dawn_onboarding_recommended_choices')}
      {this.renderQuestion(t('ghostery_dawn_onboarding_question_block_ads'))}