Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-2258: Preserve user onboarding settings #681

Merged
merged 10 commits into from Mar 15, 2021

Update recommended choices check

  • Loading branch information
leuryr committed Mar 10, 2021
commit ebbab4714c731f49ceedc8f89f13314e1f3ccb00
@@ -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 {
<div className="BlockSettingsView_checkboxBlock">
<ToggleCheckbox
className="BlockSettingsView_checkbox"
checked={recommendedChoices}
checked={this.recommendedChoicesActive()}
onChange={() => this.toggleRecommendedChoices(!recommendedChoices)}
/>
<div className="BlockSettingsView_checkboxLabel" onClick={() => this.toggleRecommendedChoices(!recommendedChoices)}>{t('ghostery_dawn_onboarding_recommended_choices')}</div>
This conversation was marked as resolved by leuryr
Comment on lines +228 to 231

This comment has been minimized.

@wlycdgr

wlycdgr Mar 11, 2021
Member

(Sorry if this wasn't initially clear) - let's follow through on this idea throughout the component and get rid of recommendedChoices completely. We can call this.recommendedChoicesActive() one time at the beginning of render and save the result to avoid repeating the calculation three times

This comment has been minimized.

@leuryr

leuryr Mar 11, 2021
Author Contributor

Ah ok, yea that makes sense!

ProTip! Use n and p to navigate between commits in a pull request.