Skip to content
This repository has been archived by the owner on Jun 18, 2019. It is now read-only.

Commit

Permalink
Reset the application state completely on back
Browse files Browse the repository at this point in the history
This is the simplest possible answer to the lingering issues
with bugs around the back button. I've replaced the back button
with a 'Home' button on Distribute and Export, and completely
wipe the state when the Home screen loads. We might want to add
a confirm step so users don't lose data accidentally.
  • Loading branch information
GabeIsman committed Apr 19, 2016
1 parent 404aabb commit 8022f9d
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 6 deletions.
16 changes: 16 additions & 0 deletions app/components/HomeButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React, { Component, PropTypes } from 'react';
import Button from './Button';


export default class HomeButton extends Component {
static contextTypes = { router: PropTypes.object }

render() {
return (
<Button className="btn-back"
onClick={() => this.context.router.push('/')}>
Home
</Button>
);
}
}
4 changes: 2 additions & 2 deletions app/containers/DistributeScreen.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux';
import Distribute from '../components/Distribute';
import BackButton from '../components/BackButton';
import HomeButton from '../components/HomeButton';
import Layout from '../components/Layout';

export class DistributeScreen extends Component {
Expand All @@ -19,7 +19,7 @@ export class DistributeScreen extends Component {
this.context.router.push('/');
return <div />;
}
const headerContent = <BackButton />;
const headerContent = <HomeButton />;

return (
<Layout header={headerContent}>
Expand Down
4 changes: 2 additions & 2 deletions app/containers/ExportScreen.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux';
import BackButton from '../components/BackButton';
import HomeButton from 'app/components/HomeButton';
import Layout from '../components/Layout';
import Export from '../components/Export';

Expand All @@ -12,7 +12,7 @@ export class ExportScreen extends Component {
}

render() {
const headerContent = <BackButton />;
const headerContent = <HomeButton />;

return (
<Layout header={headerContent}>
Expand Down
15 changes: 13 additions & 2 deletions app/containers/HomeScreen.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
import React, { Component } from 'react';
import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux';
import Home from '../components/Home';
import { reset } from 'app/ducks/global';

export class HomeScreen extends Component {
static propTypes = { dispatch: PropTypes.func };

// Reset the application state ever time the home screen is mounted
componentWillMount() {
this.props.dispatch(reset());
}

export default class HomeScreen extends Component {
render() {
return (
<Home />
);
}
}

export default connect()(HomeScreen);
9 changes: 9 additions & 0 deletions app/ducks/global.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Global actions.
*/

export const RESET = 'RESET';

export function reset() {
return { type: RESET };
}
3 changes: 3 additions & 0 deletions app/ducks/recover.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

import { parseShare, recoverFFI } from 'app/lib/crypto';
import { RESET } from 'app/ducks/global';

export const RECOVER = 'RECOVER';
export const RECOVER_SUCCESS = 'RECOVER_SUCCESS';
Expand Down Expand Up @@ -61,6 +62,8 @@ export default function reducer(state = initialState, action) {
});
case RESET_RECOVERY:
return initialState;
case RESET:
return initialState;
default:
return state;
}
Expand Down
3 changes: 3 additions & 0 deletions app/ducks/split.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

import { splitFFI } from 'app/lib/crypto';
import { RESET } from 'app/ducks/global';

export const SPLIT = 'SPLIT';
export const SPLIT_SUCCESS = 'SPLIT_SUCCESS';
Expand All @@ -27,6 +28,8 @@ export default function reducer(state = initialState, action) {
case SPLIT_FAILURE:
return Object.assign(
{}, state, { inProgress: false, error: action.error });
case RESET:
return initialState;
default:
return state;
}
Expand Down

0 comments on commit 8022f9d

Please sign in to comment.