Reset app state without closing/restarting it
This commit is contained in:
@@ -34,7 +34,11 @@ export default class CreatePassword extends Component {
|
||||
</Button>
|
||||
)
|
||||
} else {
|
||||
return <EnterNewPassword />
|
||||
return (
|
||||
<EnterNewPassword
|
||||
changeEncryptionAndRestart={this.props.changeEncryptionAndRestart}
|
||||
/>
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,13 +4,12 @@ import PropTypes from 'prop-types'
|
||||
import Button from '../../common/button'
|
||||
import ConfirmWithPassword from '../common/confirm-with-password'
|
||||
|
||||
import { changeEncryptionAndRestartApp } from '../../../db'
|
||||
import labels from '../../../i18n/en/settings'
|
||||
|
||||
export default class DeletePassword extends Component {
|
||||
static propTypes = {
|
||||
onStartDelete: PropTypes.func,
|
||||
onCancelDelete: PropTypes.func
|
||||
onCancelDelete: PropTypes.func,
|
||||
}
|
||||
|
||||
constructor() {
|
||||
@@ -24,10 +23,6 @@ export default class DeletePassword extends Component {
|
||||
this.props.onStartDelete()
|
||||
}
|
||||
|
||||
startDeletePassword = async () => {
|
||||
await changeEncryptionAndRestartApp()
|
||||
}
|
||||
|
||||
cancelConfirmationWithPassword = () => {
|
||||
this.setState({ enteringCurrentPassword: false })
|
||||
this.props.onCancelDelete()
|
||||
@@ -39,7 +34,7 @@ export default class DeletePassword extends Component {
|
||||
if (enteringCurrentPassword) {
|
||||
return (
|
||||
<ConfirmWithPassword
|
||||
onSuccess={this.startDeletePassword}
|
||||
onSuccess={this.props.changeEncryptionAndRestart}
|
||||
onCancel={this.cancelConfirmationWithPassword}
|
||||
/>
|
||||
)
|
||||
@@ -51,4 +46,4 @@ export default class DeletePassword extends Component {
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,14 +6,14 @@ import AppText from '../../common/app-text'
|
||||
import AppTextInput from '../../common/app-text-input'
|
||||
import Button from '../../common/button'
|
||||
|
||||
import { requestHash, changeEncryptionAndRestartApp } from '../../../db'
|
||||
import { requestHash } from '../../../db'
|
||||
import { Colors, Spacing } from '../../../styles'
|
||||
import settings from '../../../i18n/en/settings'
|
||||
|
||||
const LISTENER_TYPE = 'create-or-change-pw'
|
||||
|
||||
export default class EnterNewPassword extends Component {
|
||||
constructor() {
|
||||
constructor(props) {
|
||||
super()
|
||||
this.state = {
|
||||
password: '',
|
||||
@@ -22,13 +22,16 @@ export default class EnterNewPassword extends Component {
|
||||
}
|
||||
nodejs.channel.addListener(
|
||||
LISTENER_TYPE,
|
||||
changeEncryptionAndRestartApp,
|
||||
props.changeEncryptionAndRestart,
|
||||
this
|
||||
)
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
nodejs.channel.removeListener(LISTENER_TYPE, changeEncryptionAndRestartApp)
|
||||
nodejs.channel.removeListener(
|
||||
LISTENER_TYPE,
|
||||
this.props.changeEncryptionAndRestart
|
||||
)
|
||||
}
|
||||
|
||||
savePassword = () => {
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import React, { Component } from 'react'
|
||||
import { connect } from 'react-redux'
|
||||
|
||||
import { navigate } from '../../../slices/navigation'
|
||||
|
||||
import { changeDbEncryption } from '../../../db'
|
||||
|
||||
import AppPage from '../../common/app-page'
|
||||
import AppText from '../../common/app-text'
|
||||
@@ -11,7 +16,7 @@ import DeletePassword from './delete'
|
||||
import { hasEncryptionObservable } from '../../../local-storage'
|
||||
import labels from '../../../i18n/en/settings'
|
||||
|
||||
export default class PasswordSetting extends Component {
|
||||
class PasswordSetting extends Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
@@ -38,6 +43,12 @@ export default class PasswordSetting extends Component {
|
||||
this.setState({ isDeletingPassword: false })
|
||||
}
|
||||
|
||||
changeEncryptionAndRestart = async (hash) => {
|
||||
await changeDbEncryption(hash)
|
||||
await this.props.restartApp()
|
||||
this.props.navigate('Home')
|
||||
}
|
||||
|
||||
render() {
|
||||
const { isPasswordSet, isChangingPassword, isDeletingPassword } = this.state
|
||||
|
||||
@@ -51,12 +62,17 @@ export default class PasswordSetting extends Component {
|
||||
{isPasswordSet ? explainerEnabled : explainerDisabled}
|
||||
</AppText>
|
||||
|
||||
{!isPasswordSet && <CreatePassword />}
|
||||
{!isPasswordSet && (
|
||||
<CreatePassword
|
||||
changeEncryptionAndRestart={this.changeEncryptionAndRestart}
|
||||
/>
|
||||
)}
|
||||
|
||||
{isPasswordSet && !isDeletingPassword && (
|
||||
<ChangePassword
|
||||
onStartChange={this.onChangingPassword}
|
||||
onCancelChange={this.onCancelChangingPassword}
|
||||
changeEncryptionAndRestart={this.changeEncryptionAndRestart}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -64,6 +80,7 @@ export default class PasswordSetting extends Component {
|
||||
<DeletePassword
|
||||
onStartDelete={this.onDeletingPassword}
|
||||
onCancelDelete={this.onCancelDeletingPassword}
|
||||
changeEncryptionAndRestart={this.changeEncryptionAndRestart}
|
||||
/>
|
||||
)}
|
||||
</Segment>
|
||||
@@ -71,3 +88,11 @@ export default class PasswordSetting extends Component {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
const mapDispatchToProps = (dispatch) => {
|
||||
return {
|
||||
navigate: (page) => dispatch(navigate(page)),
|
||||
}
|
||||
}
|
||||
|
||||
export default connect(null, mapDispatchToProps)(PasswordSetting)
|
||||
|
||||
@@ -70,7 +70,11 @@ export default class ChangePassword extends Component {
|
||||
}
|
||||
|
||||
if (enteringNewPassword) {
|
||||
return <EnterNewPassword />
|
||||
return (
|
||||
<EnterNewPassword
|
||||
changeEncryptionAndRestart={this.props.changeEncryptionAndRestart}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user