diff --git a/app/ghostery-browser-hub/Views/OnboardingViews/Step3_ChooseDefaultSearchView/ChooseDefaultSearchConstants.js b/app/ghostery-browser-hub/Views/OnboardingViews/Step3_ChooseDefaultSearchView/ChooseDefaultSearchConstants.js index 874dfcb5e..e1cbe5caf 100644 --- a/app/ghostery-browser-hub/Views/OnboardingViews/Step3_ChooseDefaultSearchView/ChooseDefaultSearchConstants.js +++ b/app/ghostery-browser-hub/Views/OnboardingViews/Step3_ChooseDefaultSearchView/ChooseDefaultSearchConstants.js @@ -16,3 +16,4 @@ export const SEARCH_GHOSTERY = 'Ghostery'; export const SEARCH_BING = 'Bing'; export const SEARCH_YAHOO = 'Yahoo'; export const SEARCH_STARTPAGE = 'Startpage'; +export const SEARCH_OTHER = t('ghostery_dawn_onboarding_other'); diff --git a/app/ghostery-browser-hub/Views/OnboardingViews/Step3_ChooseDefaultSearchView/ChooseDefaultSearchView.jsx b/app/ghostery-browser-hub/Views/OnboardingViews/Step3_ChooseDefaultSearchView/ChooseDefaultSearchView.jsx index 70541c9c7..ac0ad7dab 100644 --- a/app/ghostery-browser-hub/Views/OnboardingViews/Step3_ChooseDefaultSearchView/ChooseDefaultSearchView.jsx +++ b/app/ghostery-browser-hub/Views/OnboardingViews/Step3_ChooseDefaultSearchView/ChooseDefaultSearchView.jsx @@ -20,7 +20,8 @@ import { SEARCH_GHOSTERY, SEARCH_YAHOO, SEARCH_STARTPAGE, - SEARCH_BING + SEARCH_BING, + SEARCH_OTHER } from './ChooseDefaultSearchConstants'; import { Modal } from '../../../../shared-components'; @@ -31,10 +32,20 @@ class ChooseDefaultSearchView extends Component { this.state = { chosenSearch: SEARCH_GHOSTERY, searchBeingConsidered: null, + otherSearchSelected: null, + otherListOpen: false, modalActive: false, }; } + componentDidMount() { + document.addEventListener('click', this.handleClickAway); + } + + componentWillUnmount() { + document.removeEventListener('click', this.handleClickAway); + } + updateSelection = () => this.setState(prevState => ( { chosenSearch: prevState.searchBeingConsidered, @@ -45,13 +56,33 @@ class ChooseDefaultSearchView extends Component { cancelSelection = () => this.setState({ modalActive: false, searchBeingConsidered: null }); + updateOtherSearchSelection = otherSelected => this.setState({ otherSearchSelected: otherSelected }); + + updateOtherListOpen = open => this.setState({ otherListOpen: open }); + triggerConfirmationModal = selection => this.setState({ modalActive: true, searchBeingConsidered: selection }); + handleClickAway = (e) => { + const { otherListOpen } = this.state; + + const closeDropdownOnClickAway = (open, key, ref) => { + if (open && !ref.contains(e.target)) { + this.setState({ [`${key}`]: false }); + } + }; + closeDropdownOnClickAway(otherListOpen, 'otherListOpen', this.otherListRef); + } + handleSubmit = () => { - const { chosenSearch } = this.state; + let { chosenSearch } = this.state; + const { otherSearchSelected } = this.state; const { actions, history } = this.props; const { setSetupStep, setDefaultSearch } = actions; + if (chosenSearch === SEARCH_OTHER && otherSearchSelected) { + chosenSearch = otherSearchSelected; + } + const payload = { type: 'setDefaultSearch', search: chosenSearch, @@ -87,7 +118,68 @@ class ChooseDefaultSearchView extends Component { renderStartpageOptionDescription = () => (