From 955523e5e93915a50e9f8f23108238b06723f661 Mon Sep 17 00:00:00 2001 From: Marcos Rodriguez Velez Date: Fri, 3 May 2024 13:18:41 -0400 Subject: [PATCH] REF: SettingsPrivacy TSX --- Navigation.tsx | 6 +- ...SettingsPrivacy.js => SettingsPrivacy.tsx} | 71 +++++++++---------- 2 files changed, 40 insertions(+), 37 deletions(-) rename screen/settings/{SettingsPrivacy.js => SettingsPrivacy.tsx} (75%) diff --git a/Navigation.tsx b/Navigation.tsx index 6f9bcb643..206c888e3 100644 --- a/Navigation.tsx +++ b/Navigation.tsx @@ -486,7 +486,11 @@ const DetailViewStackScreensStack = () => { options={LightningSettings.navigationOptions(theme)} /> - + { +enum SettingsPrivacySection { + None, + All, + ReadClipboard, + QuickActions, + Widget, +} + +const SettingsPrivacy: React.FC = () => { const { colors } = useTheme(); const { isStorageEncrypted } = useContext(BlueStorageContext); const { @@ -26,12 +32,14 @@ const SettingsPrivacy = () => { isQuickActionsEnabled, setIsQuickActionsEnabledStorage, } = useSettings(); - const sections = Object.freeze({ ALL: 0, CLIPBOARDREAD: 1, QUICKACTION: 2, WIDGETS: 3 }); - const [isLoading, setIsLoading] = useState(sections.ALL); + const [isLoading, setIsLoading] = useState(SettingsPrivacySection.All); - const [storageIsEncrypted, setStorageIsEncrypted] = useState(true); - const [isPrivacyBlurEnabledTapped, setIsPrivacyBlurEnabledTapped] = useState(0); + const [storageIsEncrypted, setStorageIsEncrypted] = useState(true); + const [isPrivacyBlurEnabledTapped, setIsPrivacyBlurEnabledTapped] = useState(0); const styleHooks = StyleSheet.create({ + root: { + backgroundColor: colors.background, + }, widgetsHeader: { color: colors.foregroundColor, }, @@ -44,49 +52,42 @@ const SettingsPrivacy = () => { } catch (e) { console.log(e); } - setIsLoading(false); + setIsLoading(SettingsPrivacySection.None); })(); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); + }, [isStorageEncrypted]); - const onDoNotTrackValueChange = async value => { - setIsLoading(sections.ALL); + const onDoNotTrackValueChange = async (value: boolean) => { + setIsLoading(SettingsPrivacySection.All); try { setDoNotTrackStorage(value); A.setOptOut(value); } catch (e) { - console.log(e); + console.debug('onDoNotTrackValueChange catch', e); } - setIsLoading(false); + setIsLoading(SettingsPrivacySection.None); }; - const onQuickActionsValueChange = async value => { - setIsLoading(sections.QUICKACTION); + const onQuickActionsValueChange = async (value: boolean) => { + setIsLoading(SettingsPrivacySection.QuickActions); try { setIsQuickActionsEnabledStorage(value); } catch (e) { - console.log(e); + console.debug('onQuickActionsValueChange catch', e); } - setIsLoading(false); + setIsLoading(SettingsPrivacySection.None); }; - const onWidgetsTotalBalanceValueChange = async value => { - setIsLoading(sections.WIDGETS); + const onWidgetsTotalBalanceValueChange = async (value: boolean) => { + setIsLoading(SettingsPrivacySection.Widget); try { await setBalanceDisplayAllowed(value); setIsWidgetBalanceDisplayAllowedStorage(value); } catch (e) { - console.log(e); + console.debug('onWidgetsTotalBalanceValueChange catch', e); } - setIsLoading(false); + setIsLoading(SettingsPrivacySection.None); }; - const stylesWithThemeHook = StyleSheet.create({ - root: { - backgroundColor: colors.background, - }, - }); - const openApplicationSettings = () => { openSettings(); }; @@ -97,8 +98,8 @@ const SettingsPrivacy = () => { }; return ( - - {Platform.OS === 'android' ? : <>} + + {Platform.OS === 'android' ? : null} { switch={{ onValueChange: setIsClipboardGetContentEnabledStorage, value: isClipboardGetContentEnabled, - disabled: isLoading === sections.ALL, + disabled: isLoading === SettingsPrivacySection.All, testID: 'ClipboardSwitch', }} /> @@ -125,7 +126,7 @@ const SettingsPrivacy = () => { switch={{ onValueChange: onQuickActionsValueChange, value: isQuickActionsEnabled, - disabled: isLoading === sections.ALL, + disabled: isLoading === SettingsPrivacySection.All, testID: 'QuickActionsSwitch', }} /> @@ -138,7 +139,7 @@ const SettingsPrivacy = () => { hideChevron title={loc.settings.privacy_do_not_track} Component={TouchableWithoutFeedback} - switch={{ onValueChange: onDoNotTrackValueChange, value: isDoNotTrackEnabled, disabled: isLoading === sections.ALL }} + switch={{ onValueChange: onDoNotTrackValueChange, value: isDoNotTrackEnabled, disabled: isLoading === SettingsPrivacySection.All }} /> {loc.settings.privacy_do_not_track_explanation} @@ -156,7 +157,7 @@ const SettingsPrivacy = () => { switch={{ onValueChange: onWidgetsTotalBalanceValueChange, value: isWidgetBalanceDisplayAllowed, - disabled: isLoading === sections.ALL, + disabled: isLoading === SettingsPrivacySection.All, }} /> @@ -184,6 +185,4 @@ const styles = StyleSheet.create({ }, }); -SettingsPrivacy.navigationOptions = navigationStyle({ headerLargeTitle: true }, opts => ({ ...opts, title: loc.settings.privacy })); - export default SettingsPrivacy;