2015-05-20 07:06:59 +08:00
|
|
|
_ = require 'underscore'
|
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'
|
2016-03-29 16:41:24 +08:00
|
|
|
ReactDOM = require 'react-dom'
|
2015-04-25 02:33:10 +08:00
|
|
|
classNames = require 'classnames'
|
2016-05-04 07:42:28 +08:00
|
|
|
FindInThread = require('./find-in-thread').default
|
2015-08-04 08:19:07 +08:00
|
|
|
MessageItemContainer = require './message-item-container'
|
|
|
|
|
2015-06-27 05:06:31 +08:00
|
|
|
{Utils,
|
|
|
|
Actions,
|
2015-07-14 07:30:02 +08:00
|
|
|
Message,
|
|
|
|
DraftStore,
|
2015-06-27 05:06:31 +08:00
|
|
|
MessageStore,
|
2016-01-29 02:46:33 +08:00
|
|
|
AccountStore,
|
2015-07-14 07:30:02 +08:00
|
|
|
DatabaseStore,
|
2015-07-24 02:18:42 +08:00
|
|
|
WorkspaceStore,
|
2015-07-22 02:50:08 +08:00
|
|
|
ChangeLabelsTask,
|
2015-11-07 03:47:06 +08:00
|
|
|
ComponentRegistry,
|
2016-03-03 06:46:27 +08:00
|
|
|
ChangeStarredTask,
|
|
|
|
SearchableComponentStore
|
|
|
|
SearchableComponentMaker} = require("nylas-exports")
|
2015-06-27 05:06:31 +08:00
|
|
|
|
2015-04-25 02:33:10 +08:00
|
|
|
{Spinner,
|
|
|
|
RetinaImg,
|
2016-03-03 02:05:17 +08:00
|
|
|
MailLabelSet,
|
2015-11-07 03:47:06 +08:00
|
|
|
ScrollRegion,
|
2015-09-09 01:53:07 +08:00
|
|
|
MailImportantIcon,
|
2015-11-07 03:47:06 +08:00
|
|
|
InjectedComponent,
|
|
|
|
KeyCommandsRegion,
|
|
|
|
InjectedComponentSet} = require('nylas-component-kit')
|
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
|
|
|
|
2015-06-06 02:50:55 +08:00
|
|
|
class MessageListScrollTooltip extends React.Component
|
|
|
|
@displayName: 'MessageListScrollTooltip'
|
|
|
|
@propTypes:
|
|
|
|
viewportCenter: React.PropTypes.number.isRequired
|
|
|
|
totalHeight: React.PropTypes.number.isRequired
|
|
|
|
|
|
|
|
componentWillMount: =>
|
|
|
|
@setupForProps(@props)
|
|
|
|
|
|
|
|
componentWillReceiveProps: (newProps) =>
|
|
|
|
@setupForProps(newProps)
|
|
|
|
|
|
|
|
shouldComponentUpdate: (newProps, newState) =>
|
|
|
|
not _.isEqual(@state,newState)
|
|
|
|
|
|
|
|
setupForProps: (props) ->
|
|
|
|
# Technically, we could have MessageList provide the currently visible
|
|
|
|
# item index, but the DOM approach is simple and self-contained.
|
|
|
|
#
|
|
|
|
els = document.querySelectorAll('.message-item-wrap')
|
|
|
|
idx = _.findIndex els, (el) -> el.offsetTop > props.viewportCenter
|
|
|
|
if idx is -1
|
|
|
|
idx = els.length
|
|
|
|
|
|
|
|
@setState
|
|
|
|
idx: idx
|
|
|
|
count: els.length
|
|
|
|
|
|
|
|
render: ->
|
|
|
|
<div className="scroll-tooltip">
|
|
|
|
{@state.idx} of {@state.count}
|
|
|
|
</div>
|
|
|
|
|
2015-04-25 02:33:10 +08:00
|
|
|
class MessageList extends React.Component
|
feat(unsafe-components): Wrap injected components, catch exceptions, clean up ComponentRegistry
Summary:
This diff gives the ComponentRegistry a cleaner, smaller API. Instead of querying by name, location or role,
it's now just location and role, and you can register components for one or more location and one or more
roles without assigning the entries in the registry separate names.
When you register with the ComponentRegistry, the syntax is also cleaner and uses the component's displayName
instead of requiring you to provide a name. You also provide the actual component when unregistering, ensuring
that you can't unregister someone else's component.
InjectedComponent and InjectedComponentSet now wrap their children in UnsafeComponent, which prevents
render/component lifecycle problems from propogating.
Existing components have been updated:
1. maxWidth / minWidth are now containerStyles.maxWidth/minWidth
2. displayName is now required to use the CR.
3. containerRequired = false can be provided to exempt a component from being wrapped in an UnsafeComponent.
This is useful because it's slightly faster and keeps DOM flat.
This diff also makes the "Show Component Regions" more awesome. It displays column regions, since they now
use the InjectedComponentSet, and also shows for InjectedComponent as well as InjectedComponentSet.
Change ComponentRegistry syntax, lots more work on safely wrapping items. See description.
Fix for inline flexbox scenarios (message actions)
Allow ~/.inbox/packages to be symlinked to a github repo
Test Plan: Run tests!
Reviewers: evan
Reviewed By: evan
Differential Revision: https://review.inboxapp.com/D1457
2015-05-01 07:10:15 +08:00
|
|
|
@displayName: 'MessageList'
|
|
|
|
@containerRequired: false
|
2015-05-08 05:42:39 +08:00
|
|
|
@containerStyles:
|
|
|
|
minWidth: 500
|
2015-09-28 16:44:36 +08:00
|
|
|
maxWidth: 999999
|
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
|
|
|
|
2015-04-25 02:33:10 +08:00
|
|
|
constructor: (@props) ->
|
|
|
|
@state = @_getStateFromStores()
|
2015-06-23 06:49:52 +08:00
|
|
|
@state.minified = true
|
2015-08-04 09:39:11 +08:00
|
|
|
@_draftScrollInProgress = false
|
2015-06-23 06:49:52 +08:00
|
|
|
@MINIFY_THRESHOLD = 3
|
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
|
|
|
|
2015-04-25 02:33:10 +08:00
|
|
|
componentDidMount: =>
|
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
|
|
|
@_unsubscribers = []
|
|
|
|
@_unsubscribers.push MessageStore.listen @_onChange
|
2016-03-23 06:47:51 +08:00
|
|
|
@_unsubscribers.push Actions.focusDraft.listen ({draftClientId}) =>
|
fix(focus): Remove focusedField in favor of imperative focus, break apart ComposerView
Summary:
- Removes controlled focus in the composer!
- No React components ever perfom focus in lifecycle methods. Never again.
- A new `Utils.schedule({action, after, timeout})` helper makes it easy to say "setState or load draft, etc. and then focus"
- The DraftStore issues a focusDraft action after creating a draft, which causes the MessageList to focus and scroll to the desired composer, which itself decides which field to focus.
- The MessageList never focuses anything automatically.
- Refactors ComposerView apart — ComposerHeader handles all top fields, DraftSessionContainer handles draft session initialization and exposes props to ComposerView
- ComposerHeader now uses a KeyCommandRegion (with focusIn and focusOut) to do the expanding and collapsing of the participants fields. May rename that container very soon.
- Removes all CommandRegistry handling of tab and shift-tab. Unless you preventDefault, the browser does it's thing.
- Removes all tabIndexes greater than 1. This is an anti-pattern—assigning everything a tabIndex of 0 tells the browser to move between them based on their order in the DOM, and is almost always what you want.
- Adds "TabGroupRegion" which allows you to create a tab/shift-tabbing group, (so tabbing does not leave the active composer). Can't believe this isn't a browser feature.
Todos:
- Occasionally, clicking out of the composer contenteditable requires two clicks. This is because atomicEdit is restoring selection within the contenteditable and breaking blur.
- Because the ComposerView does not render until it has a draft, we're back to it being white in popout composers for a brief moment. We will fix this another way - all the "return unless draft" statements were untenable.
- Clicking a row in the thread list no longer shifts focus to the message list and focuses the last draft. This will be restored soon.
Test Plan: Broken
Reviewers: juan, evan
Reviewed By: juan, evan
Differential Revision: https://phab.nylas.com/D2814
2016-04-05 06:22:01 +08:00
|
|
|
Utils.waitFor( => @_getMessageContainer(draftClientId)?).then =>
|
|
|
|
@_focusDraft(@_getMessageContainer(draftClientId))
|
|
|
|
.catch =>
|
2015-04-01 08:19:17 +08:00
|
|
|
|
2015-04-25 02:33:10 +08:00
|
|
|
componentWillUnmount: =>
|
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
|
|
|
unsubscribe() for unsubscribe in @_unsubscribers
|
2015-06-27 05:06:31 +08:00
|
|
|
|
2015-04-25 02:33:10 +08:00
|
|
|
shouldComponentUpdate: (nextProps, nextState) =>
|
2015-04-01 07:32:14 +08:00
|
|
|
not Utils.isEqualReact(nextProps, @props) or
|
|
|
|
not Utils.isEqualReact(nextState, @state)
|
2015-03-19 09:21:04 +08:00
|
|
|
|
2015-04-25 02:33:10 +08:00
|
|
|
componentDidUpdate: (prevProps, prevState) =>
|
2015-06-23 06:49:52 +08:00
|
|
|
|
2016-04-25 01:16:25 +08:00
|
|
|
_globalMenuItems: ->
|
|
|
|
toggleExpandedLabel = if @state.hasCollapsedItems then "Expand" else "Collapse"
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"label": "Thread",
|
|
|
|
"submenu": [{
|
|
|
|
"label": "#{toggleExpandedLabel} conversation",
|
|
|
|
"command": "message-list:toggle-expanded",
|
|
|
|
"position": "endof=view-actions",
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2016-03-03 06:46:27 +08:00
|
|
|
_globalKeymapHandlers: ->
|
2016-04-25 01:16:25 +08:00
|
|
|
handlers =
|
|
|
|
'core:reply': =>
|
|
|
|
Actions.composeReply({
|
|
|
|
thread: @state.currentThread,
|
|
|
|
message: @_lastMessage(),
|
|
|
|
type: 'reply',
|
|
|
|
behavior: 'prefer-existing',
|
|
|
|
})
|
|
|
|
'core:reply-all': =>
|
|
|
|
Actions.composeReply({
|
|
|
|
thread: @state.currentThread,
|
|
|
|
message: @_lastMessage(),
|
|
|
|
type: 'reply-all',
|
|
|
|
behavior: 'prefer-existing',
|
|
|
|
})
|
|
|
|
'core:forward': => @_onForward()
|
|
|
|
'core:print-thread': => @_onPrintThread()
|
|
|
|
'core:messages-page-up': => @_onScrollByPage(-1)
|
|
|
|
'core:messages-page-down': => @_onScrollByPage(1)
|
|
|
|
|
|
|
|
if @state.canCollapse
|
|
|
|
handlers['message-list:toggle-expanded'] = => @_onToggleAllMessagesExpanded()
|
|
|
|
|
|
|
|
handlers
|
2015-11-07 03:47:06 +08:00
|
|
|
|
2015-08-29 03:20:12 +08:00
|
|
|
_getMessageContainer: (clientId) =>
|
|
|
|
@refs["message-container-#{clientId}"]
|
2015-07-14 07:30:02 +08:00
|
|
|
|
2015-04-25 02:33:10 +08:00
|
|
|
_focusDraft: (draftElement) =>
|
2015-08-04 09:39:11 +08:00
|
|
|
# Note: We don't want the contenteditable view competing for scroll offset,
|
|
|
|
# so we block incoming childScrollRequests while we scroll to the new draft.
|
|
|
|
@_draftScrollInProgress = true
|
2015-06-06 02:38:30 +08:00
|
|
|
draftElement.focus()
|
2015-07-31 09:29:38 +08:00
|
|
|
@refs.messageWrap.scrollTo(draftElement, {
|
2015-08-04 09:39:11 +08:00
|
|
|
position: ScrollRegion.ScrollPosition.Top,
|
|
|
|
settle: true,
|
|
|
|
done: =>
|
|
|
|
@_draftScrollInProgress = false
|
2015-07-31 09:29:38 +08:00
|
|
|
})
|
2015-02-17 09:09:28 +08:00
|
|
|
|
2015-06-27 05:47:14 +08:00
|
|
|
_onForward: =>
|
|
|
|
return unless @state.currentThread
|
|
|
|
Actions.composeForward(thread: @state.currentThread)
|
|
|
|
|
2015-04-25 02:33:10 +08:00
|
|
|
render: =>
|
2016-01-29 03:13:59 +08:00
|
|
|
if not @state.currentThread
|
2016-03-18 00:50:30 +08:00
|
|
|
return <span />
|
2015-03-19 09:21:04 +08:00
|
|
|
|
2015-04-25 02:33:10 +08:00
|
|
|
wrapClass = classNames
|
2015-03-18 03:11:34 +08:00
|
|
|
"messages-wrap": true
|
2015-07-31 09:29:38 +08:00
|
|
|
"ready": not @state.loading
|
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
|
|
|
|
2016-03-10 07:11:55 +08:00
|
|
|
messageListClass = classNames
|
|
|
|
"message-list": true
|
|
|
|
"height-fix": SearchableComponentStore.searchTerm isnt null
|
|
|
|
|
2016-04-25 01:16:25 +08:00
|
|
|
<KeyCommandsRegion
|
|
|
|
globalHandlers={@_globalKeymapHandlers()}
|
|
|
|
globalMenuItems={@_globalMenuItems()}>
|
2016-03-03 06:46:27 +08:00
|
|
|
<FindInThread ref="findInThread" />
|
2016-03-10 07:11:55 +08:00
|
|
|
<div className={messageListClass} id="message-list">
|
2015-11-07 03:47:06 +08:00
|
|
|
<ScrollRegion tabIndex="-1"
|
|
|
|
className={wrapClass}
|
2016-03-03 06:46:27 +08:00
|
|
|
scrollbarTickProvider={SearchableComponentStore}
|
2015-11-07 03:47:06 +08:00
|
|
|
scrollTooltipComponent={MessageListScrollTooltip}
|
|
|
|
ref="messageWrap">
|
|
|
|
{@_renderSubject()}
|
|
|
|
<div className="headers" style={position:'relative'}>
|
|
|
|
<InjectedComponentSet
|
|
|
|
className="message-list-headers"
|
|
|
|
matching={role:"MessageListHeaders"}
|
2016-02-04 06:25:48 +08:00
|
|
|
exposedProps={thread: @state.currentThread}
|
|
|
|
direction="column"/>
|
2015-11-07 03:47:06 +08:00
|
|
|
</div>
|
|
|
|
{@_messageElements()}
|
|
|
|
</ScrollRegion>
|
|
|
|
<Spinner visible={@state.loading} />
|
|
|
|
</div>
|
|
|
|
</KeyCommandsRegion>
|
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
|
|
|
|
2015-06-23 06:49:52 +08:00
|
|
|
_renderSubject: ->
|
2016-01-29 03:13:59 +08:00
|
|
|
subject = @state.currentThread.subject
|
2015-09-09 01:53:07 +08:00
|
|
|
subject = "(No Subject)" if not subject or subject.length is 0
|
|
|
|
|
2015-06-23 06:49:52 +08:00
|
|
|
<div className="message-subject-wrap">
|
2016-01-29 08:44:44 +08:00
|
|
|
<MailImportantIcon thread={@state.currentThread}/>
|
2016-02-12 07:24:33 +08:00
|
|
|
<div style={flex: 1}>
|
|
|
|
<span className="message-subject">{subject}</span>
|
2016-03-11 09:08:38 +08:00
|
|
|
<MailLabelSet removable={true} thread={@state.currentThread} includeCurrentCategories={true} />
|
2016-02-12 07:24:33 +08:00
|
|
|
</div>
|
2015-12-02 06:38:52 +08:00
|
|
|
{@_renderIcons()}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
_renderIcons: =>
|
|
|
|
<div className="message-icons-wrap">
|
2015-12-08 10:01:06 +08:00
|
|
|
{@_renderExpandToggle()}
|
2015-12-04 03:52:51 +08:00
|
|
|
<div onClick={@_onPrintThread}>
|
2015-12-08 10:01:06 +08:00
|
|
|
<RetinaImg name="print.png" title="Print Thread" mode={RetinaImg.Mode.ContentIsMask}/>
|
2015-12-02 06:38:52 +08:00
|
|
|
</div>
|
2015-06-23 06:49:52 +08:00
|
|
|
</div>
|
|
|
|
|
2015-12-08 10:01:06 +08:00
|
|
|
_renderExpandToggle: =>
|
2016-04-25 01:16:25 +08:00
|
|
|
return <span/> unless @state.canCollapse
|
|
|
|
|
|
|
|
if @state.hasCollapsedItems
|
2015-12-08 10:01:06 +08:00
|
|
|
<div onClick={@_onToggleAllMessagesExpanded}>
|
|
|
|
<RetinaImg name={"expand.png"} title={"Expand All"} mode={RetinaImg.Mode.ContentIsMask}/>
|
|
|
|
</div>
|
|
|
|
else
|
|
|
|
<div onClick={@_onToggleAllMessagesExpanded}>
|
|
|
|
<RetinaImg name={"collapse.png"} title={"Collapse All"} mode={RetinaImg.Mode.ContentIsMask}/>
|
|
|
|
</div>
|
|
|
|
|
2015-08-06 08:41:15 +08:00
|
|
|
_renderReplyArea: =>
|
|
|
|
<div className="footer-reply-area-wrap" onClick={@_onClickReplyArea} key='reply-area'>
|
2015-08-04 08:05:31 +08:00
|
|
|
<div className="footer-reply-area">
|
|
|
|
<RetinaImg name="#{@_replyType()}-footer.png" mode={RetinaImg.Mode.ContentIsMask}/>
|
|
|
|
<span className="reply-text">Write a reply…</span>
|
2015-03-25 04:57:24 +08:00
|
|
|
</div>
|
2015-08-04 08:05:31 +08:00
|
|
|
</div>
|
2015-03-25 04:57:24 +08:00
|
|
|
|
2016-03-23 06:47:51 +08:00
|
|
|
_lastMessage: =>
|
|
|
|
_.last(_.filter((@state.messages ? []), (m) -> not m.draft))
|
|
|
|
|
2015-08-15 06:40:11 +08:00
|
|
|
# Returns either "reply" or "reply-all"
|
2015-04-25 02:33:10 +08:00
|
|
|
_replyType: =>
|
2015-11-12 02:25:11 +08:00
|
|
|
defaultReplyType = NylasEnv.config.get('core.sending.defaultReplyType')
|
2016-03-23 06:47:51 +08:00
|
|
|
lastMessage = @_lastMessage()
|
|
|
|
return 'reply' unless lastMessage
|
2015-08-15 06:40:11 +08:00
|
|
|
|
2016-03-23 06:47:51 +08:00
|
|
|
if lastMessage.canReplyAll()
|
2015-09-15 04:18:55 +08:00
|
|
|
if defaultReplyType is 'reply-all'
|
|
|
|
return 'reply-all'
|
|
|
|
else
|
|
|
|
return 'reply'
|
2015-07-14 07:30:02 +08:00
|
|
|
else
|
2015-08-15 06:40:11 +08:00
|
|
|
return 'reply'
|
2015-03-25 04:57:24 +08:00
|
|
|
|
2015-12-02 06:38:52 +08:00
|
|
|
_onToggleAllMessagesExpanded: ->
|
|
|
|
Actions.toggleAllMessagesExpanded()
|
|
|
|
|
2015-12-04 03:52:51 +08:00
|
|
|
_onPrintThread: =>
|
2016-03-29 16:41:24 +08:00
|
|
|
node = ReactDOM.findDOMNode(@)
|
2015-12-04 03:52:51 +08:00
|
|
|
Actions.printThread(@state.currentThread, node.innerHTML)
|
|
|
|
|
2015-04-25 02:33:10 +08:00
|
|
|
_onClickReplyArea: =>
|
2015-07-14 07:30:02 +08:00
|
|
|
return unless @state.currentThread
|
2016-03-23 06:47:51 +08:00
|
|
|
Actions.composeReply({
|
|
|
|
thread: @state.currentThread,
|
|
|
|
message: @_lastMessage(),
|
|
|
|
type: @_replyType(),
|
|
|
|
behavior: 'prefer-existing-if-pristine',
|
|
|
|
})
|
2015-03-25 04:57:24 +08:00
|
|
|
|
2015-08-04 08:19:07 +08:00
|
|
|
_messageElements: =>
|
|
|
|
elements = []
|
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
|
|
|
|
2015-08-06 08:41:15 +08:00
|
|
|
hasReplyArea = not _.last(@state.messages)?.draft
|
2015-06-23 06:49:52 +08:00
|
|
|
messages = @_messagesWithMinification(@state.messages)
|
|
|
|
messages.forEach (message, idx) =>
|
|
|
|
|
|
|
|
if message.type is "minifiedBundle"
|
2015-08-04 08:19:07 +08:00
|
|
|
elements.push(@_renderMinifiedBundle(message))
|
2015-06-23 06:49:52 +08:00
|
|
|
return
|
|
|
|
|
2015-03-26 03:41:48 +08:00
|
|
|
collapsed = !@state.messagesExpandedState[message.id]
|
2015-08-04 08:19:07 +08:00
|
|
|
isLastMsg = (messages.length - 1 is idx)
|
2015-08-06 08:41:15 +08:00
|
|
|
isBeforeReplyArea = isLastMsg and hasReplyArea
|
2015-08-04 08:19:07 +08:00
|
|
|
|
|
|
|
elements.push(
|
2016-03-03 10:13:45 +08:00
|
|
|
<MessageItemContainer key={message.clientId}
|
2015-08-29 03:20:12 +08:00
|
|
|
ref={"message-container-#{message.clientId}"}
|
2015-08-04 08:19:07 +08:00
|
|
|
thread={@state.currentThread}
|
|
|
|
message={message}
|
|
|
|
collapsed={collapsed}
|
|
|
|
isLastMsg={isLastMsg}
|
|
|
|
isBeforeReplyArea={isBeforeReplyArea}
|
feat(editor-region): Add support to register components as editors
Summary:
- The main purpose of this is to be able to properly register the editor for the markdown plugin (and any other plugins to come)
- Refactors ComposerView and Contenteditable ->
- Replaces Contenteditable with an InjectedComponent for a new region role:
"Composer:Editor"
- Creates a new component called ComposerEditor, which is the one that is
being registered by default as "Composer:Editor"
- I used this class to try to standardize the props that should be
passed to any would be editor Component:
- Renamed a bunch of the props which (I think) had a bit of
confusing names
- Added a bunch of docs for these in the source file, although
I feel like those docs should live elsewhere, like in the
ComponentRegion docs.
- In the process, I ended up pulling some stuff out of ComposerView and
some stuff out of the Contenteditable, namely:
- The scrolling logic to ensure that the composer is visible while
typing was moved outside of the Contenteditable -- this feels more
like the ComposerEditor's responsibility, especially since the
Contenteditable is meant to be used in other contexts as well.
- The ComposerExtensions state; it feels less awkward for me if this
is inside the ComposerEditor because 1) ComposerView does less
things, 2) these are actually just being passed to the
Contenteditable, 3) I feel like other plugins shouldn't need to
mess around with ComposerExtensions, so we shouldn't pass them to the
editor. If you register an editor different from our default one,
any other ComposerExtension callbacks will be disabled, which
I feel is expected behavior.
- I think there is still some more refactoring to be done, and I left some TODOS
here and there, but I think this diff is already big enough and its a minimal
set of changes to get the markdown editor working in a not so duck
tapish way.
- New props for InjectedComponent:
- `requiredMethods`: allows you to define a collection of methods that
should be implemented by any Component that registers for your
desired region.
- It will throw an error if these are not implemented
- It will automatically pass calls made on the InjectedComponent to these methods
down to the instance of the actual registered component
- Would love some comments on this approach and impl
- `fallback`: allows you to define a default component to use if none were
registered through the ComponentRegistry
- Misc:
- Added a new test case for the QuotedHTMLTransformer
- Tests:
- They were minimally updated so that they don't break, but a big TODO
is to properly refactor them. I plan to do that in an upcoming
diff.
Test Plan: - Unit tests
Reviewers: bengotow, evan
Reviewed By: evan
Differential Revision: https://phab.nylas.com/D2372
2015-12-19 03:03:58 +08:00
|
|
|
scrollTo={@_scrollTo} />
|
2015-08-04 08:19:07 +08:00
|
|
|
)
|
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
|
|
|
|
2015-08-06 08:41:15 +08:00
|
|
|
if hasReplyArea
|
|
|
|
elements.push(@_renderReplyArea())
|
2015-06-23 06:49:52 +08:00
|
|
|
|
2015-08-04 08:19:07 +08:00
|
|
|
return elements
|
2015-06-23 06:49:52 +08:00
|
|
|
|
|
|
|
_renderMinifiedBundle: (bundle) ->
|
|
|
|
BUNDLE_HEIGHT = 36
|
|
|
|
lines = bundle.messages[0...10]
|
|
|
|
h = Math.round(BUNDLE_HEIGHT / lines.length)
|
2015-03-25 04:57:24 +08:00
|
|
|
|
2015-06-23 06:49:52 +08:00
|
|
|
<div className="minified-bundle"
|
|
|
|
onClick={ => @setState minified: false }
|
|
|
|
key={Utils.generateTempId()}>
|
|
|
|
<div className="num-messages">{bundle.messages.length} older messages</div>
|
|
|
|
<div className="msg-lines" style={height: h*lines.length}>
|
|
|
|
{lines.map (msg, i) ->
|
2015-11-07 03:47:06 +08:00
|
|
|
<div key={msg.id} style={height: h*2, top: -h*i} className="msg-line"></div>}
|
2015-06-23 06:49:52 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
_messagesWithMinification: (messages=[]) =>
|
|
|
|
return messages unless @state.minified
|
|
|
|
|
|
|
|
messages = _.clone(messages)
|
|
|
|
minifyRanges = []
|
|
|
|
consecutiveCollapsed = 0
|
|
|
|
|
|
|
|
messages.forEach (message, idx) =>
|
|
|
|
return if idx is 0 # Never minify the 1st message
|
|
|
|
|
|
|
|
expandState = @state.messagesExpandedState[message.id]
|
|
|
|
|
|
|
|
if not expandState
|
|
|
|
consecutiveCollapsed += 1
|
|
|
|
else
|
|
|
|
# We add a +1 because we don't minify the last collapsed message,
|
|
|
|
# but the MINIFY_THRESHOLD refers to the smallest N that can be in
|
|
|
|
# the "N older messages" minified block.
|
|
|
|
if expandState is "default"
|
|
|
|
minifyOffset = 1
|
|
|
|
else # if expandState is "explicit"
|
|
|
|
minifyOffset = 0
|
|
|
|
|
|
|
|
if consecutiveCollapsed >= @MINIFY_THRESHOLD + minifyOffset
|
|
|
|
minifyRanges.push
|
|
|
|
start: idx - consecutiveCollapsed
|
|
|
|
length: (consecutiveCollapsed - minifyOffset)
|
|
|
|
consecutiveCollapsed = 0
|
|
|
|
|
|
|
|
indexOffset = 0
|
|
|
|
for range in minifyRanges
|
|
|
|
start = range.start - indexOffset
|
|
|
|
minified =
|
|
|
|
type: "minifiedBundle"
|
|
|
|
messages: messages[start...(start+range.length)]
|
|
|
|
messages.splice(start, range.length, minified)
|
|
|
|
|
|
|
|
# While we removed `range.length` items, we also added 1 back in.
|
|
|
|
indexOffset += (range.length - 1)
|
|
|
|
|
|
|
|
return messages
|
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
|
|
|
|
2015-06-06 02:38:30 +08:00
|
|
|
# Some child components (like the composer) might request that we scroll
|
2015-05-20 07:12:39 +08:00
|
|
|
# to a given location. If `selectionTop` is defined that means we should
|
|
|
|
# scroll to that absolute position.
|
|
|
|
#
|
|
|
|
# If messageId and location are defined, that means we want to scroll
|
|
|
|
# smoothly to the top of a particular message.
|
feat(editor-region): Add support to register components as editors
Summary:
- The main purpose of this is to be able to properly register the editor for the markdown plugin (and any other plugins to come)
- Refactors ComposerView and Contenteditable ->
- Replaces Contenteditable with an InjectedComponent for a new region role:
"Composer:Editor"
- Creates a new component called ComposerEditor, which is the one that is
being registered by default as "Composer:Editor"
- I used this class to try to standardize the props that should be
passed to any would be editor Component:
- Renamed a bunch of the props which (I think) had a bit of
confusing names
- Added a bunch of docs for these in the source file, although
I feel like those docs should live elsewhere, like in the
ComponentRegion docs.
- In the process, I ended up pulling some stuff out of ComposerView and
some stuff out of the Contenteditable, namely:
- The scrolling logic to ensure that the composer is visible while
typing was moved outside of the Contenteditable -- this feels more
like the ComposerEditor's responsibility, especially since the
Contenteditable is meant to be used in other contexts as well.
- The ComposerExtensions state; it feels less awkward for me if this
is inside the ComposerEditor because 1) ComposerView does less
things, 2) these are actually just being passed to the
Contenteditable, 3) I feel like other plugins shouldn't need to
mess around with ComposerExtensions, so we shouldn't pass them to the
editor. If you register an editor different from our default one,
any other ComposerExtension callbacks will be disabled, which
I feel is expected behavior.
- I think there is still some more refactoring to be done, and I left some TODOS
here and there, but I think this diff is already big enough and its a minimal
set of changes to get the markdown editor working in a not so duck
tapish way.
- New props for InjectedComponent:
- `requiredMethods`: allows you to define a collection of methods that
should be implemented by any Component that registers for your
desired region.
- It will throw an error if these are not implemented
- It will automatically pass calls made on the InjectedComponent to these methods
down to the instance of the actual registered component
- Would love some comments on this approach and impl
- `fallback`: allows you to define a default component to use if none were
registered through the ComponentRegistry
- Misc:
- Added a new test case for the QuotedHTMLTransformer
- Tests:
- They were minimally updated so that they don't break, but a big TODO
is to properly refactor them. I plan to do that in an upcoming
diff.
Test Plan: - Unit tests
Reviewers: bengotow, evan
Reviewed By: evan
Differential Revision: https://phab.nylas.com/D2372
2015-12-19 03:03:58 +08:00
|
|
|
_scrollTo: ({clientId, rect, position}={}) =>
|
2015-08-04 09:39:11 +08:00
|
|
|
return if @_draftScrollInProgress
|
2015-08-29 03:20:12 +08:00
|
|
|
if clientId
|
|
|
|
messageElement = @_getMessageContainer(clientId)
|
2015-08-19 01:31:18 +08:00
|
|
|
return unless messageElement
|
2015-10-03 08:14:00 +08:00
|
|
|
pos = position ? ScrollRegion.ScrollPosition.Visible
|
2015-08-19 01:31:18 +08:00
|
|
|
@refs.messageWrap.scrollTo(messageElement, {
|
2015-10-03 08:14:00 +08:00
|
|
|
position: pos
|
2015-07-31 09:29:38 +08:00
|
|
|
})
|
|
|
|
else if rect
|
|
|
|
@refs.messageWrap.scrollToRect(rect, {
|
|
|
|
position: ScrollRegion.ScrollPosition.CenterIfInvisible
|
|
|
|
})
|
2015-05-20 07:12:39 +08:00
|
|
|
else
|
2015-08-29 03:20:12 +08:00
|
|
|
throw new Error("onChildScrollRequest: expected clientId or rect")
|
2015-03-28 07:35:27 +08:00
|
|
|
|
2015-10-30 11:34:43 +08:00
|
|
|
_onScrollByPage: (direction) =>
|
2016-03-29 16:41:24 +08:00
|
|
|
height = ReactDOM.findDOMNode(@refs.messageWrap).clientHeight
|
2015-10-30 11:34:43 +08:00
|
|
|
@refs.messageWrap.scrollTop += height * direction
|
|
|
|
|
2015-04-25 02:33:10 +08:00
|
|
|
_onChange: =>
|
2015-06-23 06:49:52 +08:00
|
|
|
newState = @_getStateFromStores()
|
2016-02-16 04:46:33 +08:00
|
|
|
if @state.currentThread?.id isnt newState.currentThread?.id
|
2015-06-23 06:49:52 +08:00
|
|
|
newState.minified = true
|
|
|
|
@setState(newState)
|
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
|
|
|
|
2015-04-25 02:33:10 +08:00
|
|
|
_getStateFromStores: =>
|
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
|
|
|
messages: (MessageStore.items() ? [])
|
2015-03-26 03:41:48 +08:00
|
|
|
messagesExpandedState: MessageStore.itemsExpandedState()
|
2016-04-25 01:16:25 +08:00
|
|
|
canCollapse: MessageStore.items().length > 1
|
|
|
|
hasCollapsedItems: MessageStore.hasCollapsedItems()
|
2015-04-01 08:19:17 +08:00
|
|
|
currentThread: MessageStore.thread()
|
2015-04-01 08:22:47 +08:00
|
|
|
loading: MessageStore.itemsLoading()
|
2015-04-25 02:33:10 +08:00
|
|
|
|
2016-03-03 06:46:27 +08:00
|
|
|
module.exports = SearchableComponentMaker.extend(MessageList)
|