Move reusable components to separate folder, password view refactoring

This commit is contained in:
mashazyu
2019-01-07 23:28:48 +01:00
committed by Sofiya Tepikin
parent 94940238a6
commit bee0550372
20 changed files with 49 additions and 79 deletions
@@ -1,23 +0,0 @@
import { Alert } from 'react-native'
import { openDb } from '../../../db'
import { shared } from '../../../i18n/en/labels'
export default async function checkPassword({hash, onCancel, onTryAgain }) {
try {
await openDb(hash)
return true
} catch (err) {
Alert.alert(
shared.incorrectPassword,
shared.incorrectPasswordMessage,
[{
text: shared.cancel,
onPress: onCancel
}, {
text: shared.tryAgain,
onPress: onTryAgain
}]
)
return false
}
}
+1 -1
View File
@@ -2,7 +2,7 @@ import React, { Component } from 'react'
import { View } from 'react-native'
import settings from '../../../i18n/en/settings'
import EnterNewPassword from './enter-new-password'
import SettingsButton from '../settings-button'
import SettingsButton from '../common/settings-button'
import showBackUpReminder from './show-backup-reminder'
export default class CreatePassword extends Component {
+1 -1
View File
@@ -2,7 +2,7 @@ import React, { Component } from 'react'
import labels from '../../../i18n/en/settings'
import { changeEncryptionAndRestartApp } from '../../../db'
import ConfirmWithPassword from '../common/confirm-with-password'
import SettingsButton from '../settings-button'
import SettingsButton from '../common/settings-button'
export default class DeletePassword extends Component {
constructor() {
@@ -4,8 +4,8 @@ import nodejs from 'nodejs-mobile-react-native'
import { requestHash, changeEncryptionAndRestartApp } from '../../../db'
import AppText from '../../app-text'
import PasswordField from './password-field'
import SettingsButton from '../settings-button'
import PasswordField from '../common/password-field'
import SettingsButton from '../common/settings-button'
import styles from '../../../styles'
import settings from '../../../i18n/en/settings'
+25 -32
View File
@@ -1,9 +1,9 @@
import React, { Component } from 'react'
import { View, ScrollView } from 'react-native'
import { ScrollView } from 'react-native'
import CreatePassword from './create'
import ChangePassword from './update'
import DeletePassword from './delete'
import SettingsSegment from '../settings-segment'
import SettingsSegment from '../common/settings-segment'
import AppText from '../../app-text'
import {
hasEncryptionObservable
@@ -14,8 +14,7 @@ export default class PasswordSetting extends Component {
constructor(props) {
super(props)
this.state = {
showUpdateAndDelete: hasEncryptionObservable.value,
showCreate: !hasEncryptionObservable.value,
isPasswordSet: hasEncryptionObservable.value,
isChangingPassword: false,
isDeletingPassword: false
}
@@ -32,43 +31,37 @@ export default class PasswordSetting extends Component {
render() {
const {
showUpdateAndDelete,
isPasswordSet,
isChangingPassword,
isDeletingPassword,
showCreate
} = this.state
const {
title,
explainerEnabled,
explainerDisabled
} = labels.passwordSettings
return (
<ScrollView>
<SettingsSegment title={labels.passwordSettings.title}>
<SettingsSegment title={title}>
<AppText>
{ isPasswordSet ? explainerEnabled : explainerDisabled }
</AppText>
{showUpdateAndDelete ?
<AppText>{labels.passwordSettings.explainerEnabled}</AppText>
:
<AppText>{labels.passwordSettings.explainerDisabled}</AppText>
}
{ !isPasswordSet && <CreatePassword/> }
{
showUpdateAndDelete && (
<View>
{(isChangingPassword
|| !isChangingPassword && !isDeletingPassword)
&& <ChangePassword
onStartChangingPassword = {this.onChangingPassword}
/>}
{(isDeletingPassword
|| !isChangingPassword && !isDeletingPassword)
&& <DeletePassword
onStartDeletingPassword = {this.onDeletingPassword}
/>}
</View>
)
}
{showCreate &&
<CreatePassword/>
}
{ (isPasswordSet && !isDeletingPassword) && (
<ChangePassword
onStartChangingPassword = {this.onChangingPassword}
/>
)}
{ (isPasswordSet && !isChangingPassword) && (
<DeletePassword
onStartDeletingPassword = {this.onDeletingPassword}
/>
)}
</SettingsSegment>
</ScrollView>
)
@@ -1,19 +0,0 @@
import React from 'react'
import { TextInput } from 'react-native'
import styles, {secondaryColor} from '../../../styles'
export default function PasswordField(props) {
return (
<TextInput
style={styles.passwordField}
autoFocus={props.autoFocus === false ? false : true}
secureTextEntry={true}
onChangeText={props.onChangeText}
value={props.value}
placeholder={props.placeholder}
borderWidth={1}
borderColor={secondaryColor}
borderStyle={'solid'}
/>
)
}
+1 -1
View File
@@ -1,7 +1,7 @@
import React, { Component } from 'react'
import settings from '../../../i18n/en/settings'
import EnterNewPassword from './enter-new-password'
import SettingsButton from '../settings-button'
import SettingsButton from '../common/settings-button'
import showBackUpReminder from './show-backup-reminder'
import ConfirmWithPassword from '../common/confirm-with-password'