diff --git a/email_app/app/actions/actionTypes.js b/email_app/app/actions/actionTypes.js index 2915ad6..a156af1 100644 --- a/email_app/app/actions/actionTypes.js +++ b/email_app/app/actions/actionTypes.js @@ -15,7 +15,6 @@ const ACTION_TYPES = { // Mail Inbox PUSH_MAIL: 'PUSH_MAIL', MAIL_PROCESSING: 'MAIL_PROCESSING', - CLEAR_MAIL_PROCESSING: 'CLEAR_MAIL_PROCESSING', SET_ACTIVE_MAIL: 'SET_ACTIVE_MAIL', CANCEL_COMPOSE: 'CANCEL_COMPOSE', diff --git a/email_app/app/actions/create_account_actions.js b/email_app/app/actions/create_account_actions.js index cb920ea..37f0c35 100644 --- a/email_app/app/actions/create_account_actions.js +++ b/email_app/app/actions/create_account_actions.js @@ -12,6 +12,6 @@ export const createAccount = (emailId) => { }; export const createAccountError = (error) => ({ - type: ACTION_TYPES.CREATE_ACCOUNT_ERROR, - error + type: ACTION_TYPES.CREATE_ACCOUNT, + payload: Promise.reject(error) }); diff --git a/email_app/app/actions/mail_actions.js b/email_app/app/actions/mail_actions.js index 13fec7f..ae164b0 100644 --- a/email_app/app/actions/mail_actions.js +++ b/email_app/app/actions/mail_actions.js @@ -6,9 +6,8 @@ export const sendEmail = (email, to) => { let app = getState().initializer.app; return dispatch({ type: ACTION_TYPES.MAIL_PROCESSING, + msg: 'Sending email...', payload: storeEmail(app, email, to) - .then(() => dispatch(clearMailProcessing)) - .then(() => Promise.resolve()) }); }; }; @@ -18,9 +17,8 @@ export const saveEmail = (account, key) => { let app = getState().initializer.app; return dispatch({ type: ACTION_TYPES.MAIL_PROCESSING, + msg: 'Saving email...', payload: archiveEmail(app, account, key) - .then(() => dispatch(clearMailProcessing)) - .then(() => Promise.resolve()) }); }; }; @@ -30,17 +28,12 @@ export const deleteEmail = (container, key) => { let app = getState().initializer.app; return dispatch({ type: ACTION_TYPES.MAIL_PROCESSING, + msg: 'Deleting email...', payload: removeEmail(app, container, key) - .then(() => dispatch(clearMailProcessing)) - .then(() => Promise.resolve()) }); }; }; -export const clearMailProcessing = _ => ({ - type: ACTION_TYPES.CLEAR_MAIL_PROCESSING -}); - export const cancelCompose = _ => ({ type: ACTION_TYPES.CANCEL_COMPOSE }); diff --git a/email_app/app/components/create_account.js b/email_app/app/components/create_account.js index ff6d113..b64e571 100644 --- a/email_app/app/components/create_account.js +++ b/email_app/app/components/create_account.js @@ -41,7 +41,6 @@ export default class CreateAccount extends Component { render() { const { processing, error } = this.props; - return (
@@ -54,7 +53,7 @@ export default class CreateAccount extends Component {
Email Id must be less than {CONSTANTS.EMAIL_ID_MAX_LENGTH} characters. (This is just a restriction in this tutorial)
- +

{error.message}

diff --git a/email_app/app/components/home.js b/email_app/app/components/home.js index d73c43b..11bf3d5 100755 --- a/email_app/app/components/home.js +++ b/email_app/app/components/home.js @@ -1,59 +1,63 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { Link, IndexLink } from 'react-router'; -import Modal from 'react-modal'; +import {ModalDialog, ModalPortal, ModalBackground} from 'react-modal-dialog'; +import ReactSpinner from 'react-spinjs'; 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() - .catch((err) => 'not reconnected') - .then(() => this.setState({reconnecting: false})) + const { reconnectApplication, accounts, refreshEmail } = this.props; + return reconnectApplication() + .then(() => refreshEmail(accounts), + (err) => 'failed reconnecting'); } render() { const { router } = this.context; - const { coreData, inboxSize, savedSize, network_status } = this.props; + const { coreData, inboxSize, savedSize, network_status, processing } = this.props; - const isNetworkDisconnected = (network_status !== CONSTANTS.NET_STATUS_CONNECTED); + const isModalOpen = processing.state || (network_status !== CONSTANTS.NET_STATUS_CONNECTED); + const spinnerBackgroundStyle = { + zIndex: '5', + position: 'fixed', + height: '100%', + width: '100%', + opacity: '0.75', + backgroundColor: 'white' + } return (
- -
-
The application hast lost network connection.

-
Make sure the network link is up before trying to reconnect.

- -
-
+ { + isModalOpen && + + { + processing.state ? +
+ +
+ : + + +
+
The application hast lost network connection.

+
Make sure the network link is up before trying to reconnect.

+ +
+
+
+ } +
+ }
diff --git a/email_app/app/components/initializer.js b/email_app/app/components/initializer.js index 53c98be..a1f2e3c 100644 --- a/email_app/app/components/initializer.js +++ b/email_app/app/components/initializer.js @@ -28,6 +28,7 @@ export default class Initializer extends Component { refreshConfig() { const { setInitializerTask, refreshConfig } = this.props; setInitializerTask(MESSAGES.INITIALIZE.CHECK_CONFIGURATION); + return refreshConfig() .then((_) => { if (Object.keys(this.props.accounts).length > 0) { diff --git a/email_app/app/components/mail_list.js b/email_app/app/components/mail_list.js index c680375..8a92c55 100644 --- a/email_app/app/components/mail_list.js +++ b/email_app/app/components/mail_list.js @@ -9,27 +9,12 @@ export default class MailList extends Component { super(); this.listColors = {}; this.activeType = null; - this.goBack = this.goBack.bind(this); this.refreshEmail = this.refreshEmail.bind(this); this.handleDeleteFromInbox = this.handleDeleteFromInbox.bind(this); this.handleDeleteSaved = this.handleDeleteSaved.bind(this); this.handleSave = this.handleSave.bind(this); } - goBack() { - const { router } = this.context; - - switch (this.activeType) { - case CONSTANTS.HOME_TABS.INBOX: { - return this.props.refreshEmail(); - } - case CONSTANTS.HOME_TABS.SAVED: { - router.push('/home'); - return router.push('/saved'); - } - } - } - refreshEmail(account) { this.props.refreshEmail(account) .catch((error) => { @@ -76,87 +61,82 @@ export default class MailList extends Component { render() { const self = this; - const { processing, coreData, error, inboxSize, inbox, savedSize, saved } = this.props; + const { coreData, error, inboxSize, inbox, savedSize, saved } = this.props; let container = null; - if (processing) { - container =
  • Loading...
  • - } else if (Object.keys(error).length > 0) { - container =
  • Error in fetching emails!
  • - } else { - if (inbox) { - this.activeType = CONSTANTS.HOME_TABS.INBOX; - container = ( -
    - { - inboxSize === 0 ?
  • Inbox empty
  • : Object.keys(coreData.inbox).map((key) => { - let mail = coreData.inbox[key]; - if (!self.listColors.hasOwnProperty(mail.from)) { - self.listColors[mail.from] = `bg-color-${Object.keys(self.listColors).length % 10}` - } - return ( -
  • -
    - {mail.from[0]} -
    -
    -

    {mail.from}

    -

    {dateformat(new Date(mail.time), CONSTANTS.DATE_FORMAT)}

    -

    {mail.subject}

    -

    {mail.body}

    + if (inbox) { + this.activeType = CONSTANTS.HOME_TABS.INBOX; + container = ( +
    + { + inboxSize === 0 ?
  • Inbox empty
  • : Object.keys(coreData.inbox).map((key) => { + let mail = coreData.inbox[key]; + if (!self.listColors.hasOwnProperty(mail.from)) { + self.listColors[mail.from] = `bg-color-${Object.keys(self.listColors).length % 10}` + } + return ( +
  • +
    + {mail.from[0]} +
    +
    +

    {mail.from}

    +

    {dateformat(new Date(mail.time), CONSTANTS.DATE_FORMAT)}

    +

    {mail.subject}

    +

    {mail.body}

    +
    +
    +
    +
    -
    -
    - -
    -
    - -
    +
    +
    -
  • - ) - }) - } -
    - ); - } - if (saved) { - this.activeType = CONSTANTS.HOME_TABS.SAVED; - container = ( -
    - { - savedSize === 0 ?
  • Saved empty
  • : Object.keys(coreData.saved).map((key) => { - let mail = coreData.saved[key]; - if (!mail) { - return; - } - if (!self.listColors.hasOwnProperty(mail.from)) { - self.listColors[mail.from] = `bg-color-${Object.keys(self.listColors).length % 10}` - } - return ( -
  • -
    - {mail.from[0]} -
    -
    -

    {mail.from}

    -

    {dateformat(new Date(mail.time), CONSTANTS.DATE_FORMAT)}

    -

    {mail.subject}

    -

    {mail.body}

    -
    -
    -
    - -
    +
    +
  • + ) + }) + } +
    + ); + } + if (saved) { + this.activeType = CONSTANTS.HOME_TABS.SAVED; + container = ( +
    + { + savedSize === 0 ?
  • Saved empty
  • : Object.keys(coreData.saved).map((key) => { + let mail = coreData.saved[key]; + if (!mail) { + return; + } + if (!self.listColors.hasOwnProperty(mail.from)) { + self.listColors[mail.from] = `bg-color-${Object.keys(self.listColors).length % 10}` + } + return ( +
  • +
    + {mail.from[0]} +
    +
    +

    {mail.from}

    +

    {dateformat(new Date(mail.time), CONSTANTS.DATE_FORMAT)}

    +

    {mail.subject}

    +

    {mail.body}

    +
    +
    +
    +
    -
  • - ) - }) - } -
    - ); - } +
    + + ) + }) + } +
    + ); } + return (