diff --git a/email_app/app/actions/actionTypes.js b/email_app/app/actions/actionTypes.js index 1272290..2915ad6 100644 --- a/email_app/app/actions/actionTypes.js +++ b/email_app/app/actions/actionTypes.js @@ -5,6 +5,8 @@ const ACTION_TYPES = { REFRESH_EMAIL: 'REFRESH_EMAIL', SET_INITIALIZER_TASK: 'SET_INITIALIZER_TASK', STORE_NEW_ACCOUNT: 'STORE_NEW_ACCOUNT', + NET_STATUS_CHANGED: 'NET_STATUS_CHANGED', + RECONNECT_APP: 'RECONNECT_APP', // Create Account CREATE_ACCOUNT: 'CREATE_ACCOUNT', diff --git a/email_app/app/actions/initializer_actions.js b/email_app/app/actions/initializer_actions.js index 48dc2ef..466a159 100644 --- a/email_app/app/actions/initializer_actions.js +++ b/email_app/app/actions/initializer_actions.js @@ -1,5 +1,5 @@ import ACTION_TYPES from './actionTypes'; -import { authApp, connect, readConfig, writeConfig, +import { authApp, connect, reconnect, readConfig, writeConfig, readInboxEmails, readArchivedEmails } from '../safenet_comm'; export const setInitializerTask = (task) => ({ @@ -14,11 +14,20 @@ export const onAuthFailure = (err) => { }; }; +const newNetStatusCallback = (dispatch) => { + return function (state) { + dispatch({ + type: ACTION_TYPES.NET_STATUS_CHANGED, + payload: state + }); + } +}; + export const receiveResponse = (uri) => { return function (dispatch) { return dispatch({ type: ACTION_TYPES.AUTHORISE_APP, - payload: connect(uri) + payload: connect(uri, newNetStatusCallback(dispatch)) }); }; }; @@ -28,7 +37,7 @@ export const authoriseApplication = () => { return dispatch({ type: ACTION_TYPES.AUTHORISE_APP, payload: new Promise((resolve, reject) => { - authApp() + authApp(newNetStatusCallback(dispatch)) .then(resolve) .catch(reject); }) @@ -37,6 +46,16 @@ export const authoriseApplication = () => { }; }; +export const reconnectApplication = () => { + return function (dispatch, getState) { + let app = getState().initializer.app; + return dispatch({ + type: ACTION_TYPES.RECONNECT_APP, + payload: reconnect(app) + }); + }; +}; + export const refreshConfig = () => { return function (dispatch, getState) { let app = getState().initializer.app; diff --git a/email_app/app/components/create_account.js b/email_app/app/components/create_account.js index e17ac9f..ff6d113 100644 --- a/email_app/app/components/create_account.js +++ b/email_app/app/components/create_account.js @@ -1,6 +1,6 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; -import { MESSAGES, CONSTANTS } from '../constants'; +import { MESSAGES, CONSTANTS, SAFE_APP_ERROR_CODES } from '../constants'; export default class CreateAccount extends Component { constructor() { @@ -32,7 +32,7 @@ export default class CreateAccount extends Component { return createAccount(emailId) .then(this.storeCreatedAccount) .catch((err) => { - if (err.code === -104) { + if (err.code === SAFE_APP_ERROR_CODES.ERR_DATA_EXISTS) { return createAccountError(new Error(MESSAGES.EMAIL_ALREADY_TAKEN)); } return createAccountError(err); diff --git a/email_app/app/components/home.js b/email_app/app/components/home.js index 25da6ad..9e10f1f 100755 --- a/email_app/app/components/home.js +++ b/email_app/app/components/home.js @@ -1,15 +1,59 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { Link, IndexLink } from 'react-router'; +import Modal from 'react-modal'; import className from 'classnames'; import pkg from '../../package.json'; +import { CONSTANTS } from '../constants'; + +const modalStyles = { + content : { + top : '50%', + left : '50%', + right : 'auto', + bottom : 'auto', + marginRight : '-50%', + transform : 'translate(-50%, -50%)' + } +}; export default class Home extends Component { + constructor() { + super(); + this.state = { + reconnecting: false + }; + + this.reconnect = this.reconnect.bind(this); + } + + reconnect() { + this.setState({reconnecting: true}); + return this.props.reconnectApplication() + .then(() => this.setState({reconnecting: false})); + } + render() { const { router } = this.context; - const { coreData, inboxSize, savedSize } = this.props; + const { coreData, inboxSize, savedSize, network_status } = this.props; + + const isNetworkDisconnected = (network_status !== CONSTANTS.NET_STATUS_CONNECTED); + return (