Mailspring/internal_packages/onboarding/lib/container-view.cjsx

171 lines
7 KiB
Plaintext
Raw Normal View History

fix(drafts): Various improvements and fixes to drafts, draft state management Summary: This diff contains a few major changes: 1. Scribe is no longer used for the text editor. It's just a plain contenteditable region. The toolbar items (bold, italic, underline) still work. Scribe was causing React inconcistency issues in the following scenario: - View thread with draft, edit draft - Move to another thread - Move back to thread with draft - Move to another thread. Notice that one or more messages from thread with draft are still there. There may be a way to fix this, but I tried for hours and there are Github Issues open on it's repository asking for React compatibility, so it may be fixed soon. For now contenteditable is working great. 2. Action.saveDraft() is no longer debounced in the DraftStore. Instead, firing that action causes the save to happen immediately, and the DraftStoreProxy has a new "DraftChangeSet" class which is responsbile for batching saves as the user interacts with the ComposerView. There are a couple big wins here: - In the future, we may want to be able to call Action.saveDraft() in other situations and it should behave like a normal action. We may also want to expose the DraftStoreProxy as an easy way of backing interactive draft UI. - Previously, when you added a contact to To/CC/BCC, this happened: <input> -> Action.saveDraft -> (delay!!) -> Database -> DraftStore -> DraftStoreProxy -> View Updates Increasing the delay to something reasonable like 200msec meant there was 200msec of lag before you saw the new view state. To fix this, I created a new class called DraftChangeSet which is responsible for accumulating changes as they're made and firing Action.saveDraft. "Adding" a change to the change set also causes the Draft provided by the DraftStoreProxy to change immediately (the changes are a temporary layer on top of the database object). This means no delay while changes are being applied. There's a better explanation in the source! This diff includes a few minor fixes as well: 1. Draft.state is gone—use Message.object = draft instead 2. String model attributes should never be null 3. Pre-send checks that can cancel draft send 4. Put the entire curl history and task queue into feedback reports 5. Cache localIds for extra speed 6. Move us up to latest React Test Plan: No new tests - once we lock down this new design I'll write tests for the DraftChangeSet Reviewers: evan Reviewed By: evan Differential Revision: https://review.inboxapp.com/D1125
2015-02-04 08:24:31 +08:00
React = require 'react/addons'
ReactCSSTransitionGroup = React.addons.CSSTransitionGroup
OnboardingActions = require './onboarding-actions'
OnboardingStore = require './onboarding-store'
querystring = require 'querystring'
{EdgehillAPI} = require 'inbox-exports'
module.exports =
ContainerView = React.createClass
getInitialState: ->
@getStateFromStore()
getStateFromStore: ->
page: OnboardingStore.page()
error: OnboardingStore.error()
environment: OnboardingStore.environment()
connectType: OnboardingStore.connectType()
componentDidMount: ->
@unsubscribe = OnboardingStore.listen(@_onStateChanged, @)
# It's important that every React class explicitly stops listening to
# atom events before it unmounts. Thank you event-kit
# This can be fixed via a Reflux mixin
componentWillUnmount: ->
@unsubscribe() if @unsubscribe
componentDidUpdate: ->
webview = this.refs['connect-iframe']
if webview
node = webview.getDOMNode()
node.addEventListener 'did-finish-load', (e) ->
if node.getUrl().indexOf('/connect/complete') != -1
query = node.getUrl().split('?')[1]
token = querystring.decode(query)
OnboardingActions.finishedConnect(token)
render: ->
<div className={@state.page}>
<ReactCSSTransitionGroup transitionName="page">
{@_pageComponent()}
</ReactCSSTransitionGroup>
<div className="quit" onClick={@_fireQuit}><i className="fa fa-times"></i></div>
<button className="btn btn-default dismiss" onClick={@_fireDismiss}>Cancel</button>
<button className="btn btn-default back" onClick={@_fireMoveToPrevPage}>Back</button>
</div>
_pageComponent: ->
if @state.error
alert = <div className="alert alert-danger" role="alert">{@state.error}</div>
else
alert = <div></div>
if @state.page is 'welcome'
<div className="page" key={@state.page}>
<h2>Welcome to Edgehill</h2>
<div className="thin-container">
<button className="btn btn-primary btn-lg btn-block" onClick={=> @_fireMoveToPage('create-account')}>Create an Account</button>
<button className="btn btn-primary btn-lg btn-block" onClick={=> @_fireMoveToPage('sign-in')}>Sign In</button>
<div className="environment-selector">
<h5>Environment</h5>
<select value={@state.environment} onChange={@_fireSetEnvironment}>
<option value="development">Development (edgehill-dev, api-staging)</option>
<option value="staging">Staging (edgehill-staging, api-staging)</option>
<option value="production">Production (edgehill, api)</option>
</select>
</div>
</div>
</div>
else if @state.page is 'sign-in'
<div className="page" key={@state.page}>
<form role="form" className="thin-container native-key-bindings">
{alert}
<div className="form-group">
<input type="email" placeholder="Username" className="form-control" tabIndex="1" value={@state.username} onChange={@_onValueChange} id="username" />
</div>
<div className="form-group">
<input type="password" placeholder="Password" className="form-control" tabIndex="2" value={@state.password} onChange={@_onValueChange} id="password" />
</div>
<button className="btn btn-primary btn-lg btn-block" onClick={@_fireSignIn}>Sign In</button>
</form>
</div>
else if @state.page == 'create-account'
<div className="page" key={@state.page}>
<form role="form" className="thin-container native-key-bindings">
{alert}
<div className="form-group">
<input type="text" placeholder="First Name" className="form-control" tabIndex="1" value={@state.first_name} onChange={@_onValueChange} id="first_name" />
</div>
<div className="form-group">
<input type="text" placeholder="Last Name" className="form-control" tabIndex="2" value={@state.last_name} onChange={@_onValueChange} id="last_name" />
</div>
<div className="form-group">
<input type="text" placeholder="Email Address" className="form-control" tabIndex="3" value={@state.email} onChange={@_onValueChange} id="email" />
</div>
<div className="form-group">
<input type="email" placeholder="Username" className="form-control" tabIndex="4" value={@state.username} onChange={@_onValueChange} id="username" />
</div>
<div className="form-group">
<input type="password" placeholder="Password" className="form-control" tabIndex="5" value={@state.password} onChange={@_onValueChange} id="password" />
</div>
<button className="btn btn-primary btn-lg btn-block" onClick={@_fireCreateAccount}>Create Account</button>
</form>
</div>
else if @state.page == 'add-account'
<div className="page" key={@state.page}>
<h2>Connect an Account</h2>
<p>Link accounts from other services to supercharge your email.</p>
<div className="thin-container">
<button className="btn btn-primary btn-lg btn-block" onClick={=> @_fireAuthAccount('salesforce')}>Salesforce</button>
<button className="btn btn-primary btn-lg btn-block" onClick={=> @_fireAuthAccount('linkedin')}>LinkedIn</button>
</div>
</div>
else if @state.page == 'add-account-auth'
React.createElement('webview',{
"ref": "connect-iframe",
"key": this.state.page,
"className": "native-key-bindings",
"src": this._connectWebViewURL()
});
else if @state.page == 'add-account-success'
# http://codepen.io/stevenfabre/pen/NPWeVb
<div className="page" key={@state.page}>
<div className="check">
<svg preserveAspectRatio="xMidYMid" width="61" height="52" viewBox="0 0 61 52" className="check-icon">
<path d="M56.560,-0.010 C37.498,10.892 26.831,26.198 20.617,33.101 C20.617,33.101 5.398,23.373 5.398,23.373 C5.398,23.373 0.010,29.051 0.010,29.051 C0.010,29.051 24.973,51.981 24.973,51.981 C29.501,41.166 42.502,21.583 60.003,6.565 C60.003,6.565 56.560,-0.010 56.560,-0.010 Z" id="path-1" class="cls-2" fill-rule="evenodd"/>
</svg>
</div>
</div>
_connectWebViewURL: ->
EdgehillAPI.urlForConnecting(@state.connectType, @state.email)
_onStateChanged: ->
@setState(@getStateFromStore())
_onValueChange: (event) ->
changes = {}
changes[event.target.id] = event.target.value
@setState(changes)
_fireDismiss: ->
atom.close()
_fireQuit: ->
require('remote').require('app').quit()
_fireSetEnvironment: (event) ->
OnboardingActions.setEnvironment(event.target.value)
_fireAuthAccount: (service) ->
OnboardingActions.startConnect(service)
_fireMoveToPage: (page) ->
OnboardingActions.moveToPage(page)
_fireMoveToPrevPage: ->
OnboardingActions.moveToPreviousPage()
_fireSignIn: (e) ->
e.preventDefault()
OnboardingActions.signIn(@state)
_fireCreateAccount: (e) ->
e.preventDefault()
OnboardingActions.createAccount(@state)