From d4bc0aaeb957fae2c705e0f5aeebf0ebe27de73c Mon Sep 17 00:00:00 2001 From: Antonella Sgarlatta Date: Tue, 16 Feb 2021 19:17:36 -0300 Subject: [PATCH] feat: separate section for protections --- .../Sections/PasscodeSection.styled.ts | 19 +------ .../Settings/Sections/PasscodeSection.tsx | 40 +------------ .../Sections/ProtectionsSection.styled.ts | 26 +++++++++ .../Settings/Sections/ProtectionsSection.tsx | 56 +++++++++++++++++++ src/screens/Settings/Settings.tsx | 4 ++ 5 files changed, 90 insertions(+), 55 deletions(-) create mode 100644 src/screens/Settings/Sections/ProtectionsSection.styled.ts create mode 100644 src/screens/Settings/Sections/ProtectionsSection.tsx diff --git a/src/screens/Settings/Sections/PasscodeSection.styled.ts b/src/screens/Settings/Sections/PasscodeSection.styled.ts index 4ee309f7..999e3977 100644 --- a/src/screens/Settings/Sections/PasscodeSection.styled.ts +++ b/src/screens/Settings/Sections/PasscodeSection.styled.ts @@ -1,21 +1,6 @@ -import { SectionedTableCell } from '@Components/SectionedTableCell'; import styled from 'styled-components/native'; -export const BaseView = styled.View``; - -export const StyledSectionedTableCell = styled(SectionedTableCell)` - padding-top: 12px; -`; - -export const Subtitle = styled.Text` +export const Title = styled.Text` color: ${({ theme }) => theme.stylekitNeutralColor}; - font-size: 14px; - margin-top: 4px; -`; - -export const Title = styled.Text<{ first?: boolean }>` - margin-top: ${({ first }) => (first ? '0px' : '8px')}; - color: ${({ theme }) => theme.stylekitForegroundColor}; - font-size: 14px; - font-weight: bold; + margin-top: 2px; `; diff --git a/src/screens/Settings/Sections/PasscodeSection.tsx b/src/screens/Settings/Sections/PasscodeSection.tsx index a09d0c96..062c2f29 100644 --- a/src/screens/Settings/Sections/PasscodeSection.tsx +++ b/src/screens/Settings/Sections/PasscodeSection.tsx @@ -7,19 +7,13 @@ import { SectionHeader } from '@Components/SectionHeader'; import { TableSection } from '@Components/TableSection'; import { UnlockTiming } from '@Lib/application_state'; import { MobileDeviceInterface } from '@Lib/interface'; -import { useProtectionSessionExpiry } from '@Lib/snjs_helper_hooks'; import { useFocusEffect, useNavigation } from '@react-navigation/native'; import { ApplicationContext } from '@Root/ApplicationContext'; import { ModalStackNavigationProp } from '@Root/ModalStack'; import { SCREEN_INPUT_MODAL_PASSCODE, SCREEN_SETTINGS } from '@Screens/screens'; import { StorageEncryptionPolicies } from '@standardnotes/snjs'; import React, { useCallback, useContext, useEffect, useState } from 'react'; -import { - BaseView, - StyledSectionedTableCell, - Subtitle, - Title, -} from './PasscodeSection.styled'; +import { Title } from './PasscodeSection.styled'; type Props = { title: string; @@ -50,7 +44,6 @@ export const PasscodeSection = (props: Props) => { encryptionPolictChangeInProgress, setEncryptionPolictChangeInProgress, ] = useState(false); - const [protectionsDisabledUntil] = useProtectionSessionExpiry(); useEffect(() => { let mounted = true; @@ -129,13 +122,6 @@ export const PasscodeSection = (props: Props) => { storageSubText = 'Applying changes...'; } - const protectionsEnabledTitle = protectionsDisabledUntil - ? `Protections are disabled until ${protectionsDisabledUntil}` - : 'Protections are enabled'; - - const protectionsEnabledSubtitle = - 'Actions like viewing protected notes, exporting decrypted backups, or revoking an active session, require additional authentication like entering your account password or application passcode.'; - const passcodeTitle = props.hasPasscode ? 'Disable Passcode Lock' : 'Enable Passcode Lock'; @@ -218,10 +204,6 @@ export const PasscodeSection = (props: Props) => { [disableBiometrics, disablePasscode] ); - const enableProtections = () => { - application?.clearProtectionSession(); - }; - let biometricTitle = hasBiometrics ? 'Disable Biometrics Lock' : 'Enable Biometrics Lock'; @@ -235,27 +217,9 @@ export const PasscodeSection = (props: Props) => { title={storageEncryptionTitle} onPress={toggleEncryptionPolicy} > - {storageSubText} + {storageSubText} - {protectionsDisabledUntil ? ( - - {protectionsEnabledTitle} - {protectionsEnabledSubtitle} - - ) : ( - - - {protectionsEnabledTitle} - {protectionsEnabledSubtitle} - - - )} - theme.stylekitNeutralColor}; + font-size: 14px; + padding: 12px 14px; +`; + +export const Subtitle = styled.Text` + color: ${({ theme }) => theme.stylekitNeutralColor}; + font-size: 14px; + margin-top: 4px; +`; + +export const Title = styled.Text` + color: ${({ theme }) => theme.stylekitForegroundColor}; + font-size: 16px; + font-weight: bold; +`; diff --git a/src/screens/Settings/Sections/ProtectionsSection.tsx b/src/screens/Settings/Sections/ProtectionsSection.tsx new file mode 100644 index 00000000..de4249af --- /dev/null +++ b/src/screens/Settings/Sections/ProtectionsSection.tsx @@ -0,0 +1,56 @@ +import { ButtonCell } from '@Components/ButtonCell'; +import { SectionHeader } from '@Components/SectionHeader'; +import { TableSection } from '@Components/TableSection'; +import { useProtectionSessionExpiry } from '@Lib/snjs_helper_hooks'; +import { ApplicationContext } from '@Root/ApplicationContext'; +import React, { useContext } from 'react'; +import { + BaseView, + StyledSectionedTableCell, + SubText, + Subtitle, + Title, +} from './ProtectionsSection.styled'; + +type Props = { + title: string; +}; + +export const ProtectionsSection = (props: Props) => { + // Context + const application = useContext(ApplicationContext); + + // State + const [protectionsDisabledUntil] = useProtectionSessionExpiry(); + + const protectionsEnabledSubtitle = protectionsDisabledUntil + ? `Disabled until ${protectionsDisabledUntil}` + : 'Enabled'; + + const protectionsEnabledSubtext = + 'Actions like viewing protected notes, exporting decrypted backups, or revoking an active session, require additional authentication like entering your account password or application passcode.'; + + const enableProtections = () => { + application?.clearProtectionSession(); + }; + + return ( + + + + + Status + {protectionsEnabledSubtitle} + + + {protectionsDisabledUntil && ( + + )} + {protectionsEnabledSubtext} + + ); +}; diff --git a/src/screens/Settings/Settings.tsx b/src/screens/Settings/Settings.tsx index 042ec8ec..0bad7e3a 100644 --- a/src/screens/Settings/Settings.tsx +++ b/src/screens/Settings/Settings.tsx @@ -10,6 +10,7 @@ import { EncryptionSection } from './Sections/EncryptionSection'; import { OptionsSection } from './Sections/OptionsSection'; import { PasscodeSection } from './Sections/PasscodeSection'; import { PreferencesSection } from './Sections/PreferencesSection'; +import { ProtectionsSection } from './Sections/ProtectionsSection'; import { Container } from './Settings.styled'; type Props = ModalStackNavigationProp; @@ -61,6 +62,9 @@ export const Settings = (props: Props) => { hasPasscode={hasPasscode} title="Security" /> +