2016-02-25 06:45:47 +08:00
|
|
|
// import {DraftStore, React, Actions, NylasAPI, DatabaseStore, Message, Rx} from 'nylas-exports'
|
2016-02-25 08:05:16 +08:00
|
|
|
import {React, APIError, NylasAPI} from 'nylas-exports'
|
2016-02-25 06:45:47 +08:00
|
|
|
import {MetadataComposerToggleButton} from 'nylas-component-kit'
|
2016-02-24 14:55:47 +08:00
|
|
|
import {PLUGIN_ID, PLUGIN_NAME} from './open-tracking-constants'
|
|
|
|
|
2016-02-20 04:30:24 +08:00
|
|
|
export default class OpenTrackingButton extends React.Component {
|
|
|
|
static displayName = 'OpenTrackingButton';
|
|
|
|
|
|
|
|
static propTypes = {
|
refactor(composer): Make session, draft available everywhere
Summary:
Up until now, we've been requiring that every plugin control in the composer take the draftClientId, retreive the session, listen to it, build state from the draft, etc. This is a huge pain and is hard to explain to newcomers becaus it frankly makes no sense.
In 0.3.45 we made it so that the ComposerView always has a non-null draft and session. (It isn't rendered until they're available). In this diff, I just pass those through to all the plugins and remove all the session retrieval cruft.
Almost none of the buttons have state of their own, which I think is appropriate.
They do render on every keystroke, but they were already running code (to recompute their state) on each keystroke and profiling suggests this has no impact.
Prepare for immutable
In preparation for Immutable models, make the draft store proxy returns a !== draft if any changes have been made. This means you can safely know that a draft has changed if `props.draft !== nextProps.draft`
Test Plan: Run tests
Reviewers: juan, evan
Reviewed By: juan, evan
Differential Revision: https://phab.nylas.com/D2902
2016-04-20 07:05:15 +08:00
|
|
|
draft: React.PropTypes.object.isRequired,
|
|
|
|
session: React.PropTypes.object.isRequired,
|
2016-02-20 04:30:24 +08:00
|
|
|
};
|
|
|
|
|
refactor(composer): Make session, draft available everywhere
Summary:
Up until now, we've been requiring that every plugin control in the composer take the draftClientId, retreive the session, listen to it, build state from the draft, etc. This is a huge pain and is hard to explain to newcomers becaus it frankly makes no sense.
In 0.3.45 we made it so that the ComposerView always has a non-null draft and session. (It isn't rendered until they're available). In this diff, I just pass those through to all the plugins and remove all the session retrieval cruft.
Almost none of the buttons have state of their own, which I think is appropriate.
They do render on every keystroke, but they were already running code (to recompute their state) on each keystroke and profiling suggests this has no impact.
Prepare for immutable
In preparation for Immutable models, make the draft store proxy returns a !== draft if any changes have been made. This means you can safely know that a draft has changed if `props.draft !== nextProps.draft`
Test Plan: Run tests
Reviewers: juan, evan
Reviewed By: juan, evan
Differential Revision: https://phab.nylas.com/D2902
2016-04-20 07:05:15 +08:00
|
|
|
shouldComponentUpdate(nextProps) {
|
|
|
|
return (nextProps.draft.metadataForPluginId(PLUGIN_ID) !== this.props.draft.metadataForPluginId(PLUGIN_ID));
|
|
|
|
}
|
|
|
|
|
2016-02-25 06:45:47 +08:00
|
|
|
_title(enabled) {
|
|
|
|
const dir = enabled ? "Disable" : "Enable";
|
|
|
|
return `${dir} read receipts`
|
2016-02-20 04:30:24 +08:00
|
|
|
}
|
|
|
|
|
2016-02-25 06:45:47 +08:00
|
|
|
_errorMessage(error) {
|
2016-04-05 06:05:48 +08:00
|
|
|
if (error instanceof APIError && NylasAPI.TimeoutErrorCodes.includes(error.statusCode)) {
|
2016-02-25 08:05:16 +08:00
|
|
|
return `Read receipts do not work offline. Please re-enable when you come back online.`
|
|
|
|
}
|
2016-02-25 10:21:16 +08:00
|
|
|
return `Unfortunately, read receipts are currently not available. Please try again later. Error: ${error.message}`
|
2016-02-20 04:30:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2016-02-26 04:48:05 +08:00
|
|
|
const enabledValue = {
|
refactor(composer): Make session, draft available everywhere
Summary:
Up until now, we've been requiring that every plugin control in the composer take the draftClientId, retreive the session, listen to it, build state from the draft, etc. This is a huge pain and is hard to explain to newcomers becaus it frankly makes no sense.
In 0.3.45 we made it so that the ComposerView always has a non-null draft and session. (It isn't rendered until they're available). In this diff, I just pass those through to all the plugins and remove all the session retrieval cruft.
Almost none of the buttons have state of their own, which I think is appropriate.
They do render on every keystroke, but they were already running code (to recompute their state) on each keystroke and profiling suggests this has no impact.
Prepare for immutable
In preparation for Immutable models, make the draft store proxy returns a !== draft if any changes have been made. This means you can safely know that a draft has changed if `props.draft !== nextProps.draft`
Test Plan: Run tests
Reviewers: juan, evan
Reviewed By: juan, evan
Differential Revision: https://phab.nylas.com/D2902
2016-04-20 07:05:15 +08:00
|
|
|
uid: this.props.draft.clientId,
|
2016-02-26 04:48:05 +08:00
|
|
|
open_count: 0,
|
|
|
|
open_data: [],
|
|
|
|
};
|
|
|
|
|
2016-02-25 06:45:47 +08:00
|
|
|
return (
|
|
|
|
<MetadataComposerToggleButton
|
|
|
|
title={this._title}
|
|
|
|
iconUrl="nylas://open-tracking/assets/icon-composer-eye@2x.png"
|
|
|
|
pluginId={PLUGIN_ID}
|
|
|
|
pluginName={PLUGIN_NAME}
|
2016-02-26 04:48:05 +08:00
|
|
|
metadataEnabledValue={enabledValue}
|
2016-02-25 06:45:47 +08:00
|
|
|
stickyToggle
|
|
|
|
errorMessage={this._errorMessage}
|
refactor(composer): Make session, draft available everywhere
Summary:
Up until now, we've been requiring that every plugin control in the composer take the draftClientId, retreive the session, listen to it, build state from the draft, etc. This is a huge pain and is hard to explain to newcomers becaus it frankly makes no sense.
In 0.3.45 we made it so that the ComposerView always has a non-null draft and session. (It isn't rendered until they're available). In this diff, I just pass those through to all the plugins and remove all the session retrieval cruft.
Almost none of the buttons have state of their own, which I think is appropriate.
They do render on every keystroke, but they were already running code (to recompute their state) on each keystroke and profiling suggests this has no impact.
Prepare for immutable
In preparation for Immutable models, make the draft store proxy returns a !== draft if any changes have been made. This means you can safely know that a draft has changed if `props.draft !== nextProps.draft`
Test Plan: Run tests
Reviewers: juan, evan
Reviewed By: juan, evan
Differential Revision: https://phab.nylas.com/D2902
2016-04-20 07:05:15 +08:00
|
|
|
draft={this.props.draft}
|
|
|
|
session={this.props.session} />
|
2016-02-25 06:45:47 +08:00
|
|
|
)
|
2016-02-20 04:30:24 +08:00
|
|
|
}
|
|
|
|
}
|
refactor(composer): Make session, draft available everywhere
Summary:
Up until now, we've been requiring that every plugin control in the composer take the draftClientId, retreive the session, listen to it, build state from the draft, etc. This is a huge pain and is hard to explain to newcomers becaus it frankly makes no sense.
In 0.3.45 we made it so that the ComposerView always has a non-null draft and session. (It isn't rendered until they're available). In this diff, I just pass those through to all the plugins and remove all the session retrieval cruft.
Almost none of the buttons have state of their own, which I think is appropriate.
They do render on every keystroke, but they were already running code (to recompute their state) on each keystroke and profiling suggests this has no impact.
Prepare for immutable
In preparation for Immutable models, make the draft store proxy returns a !== draft if any changes have been made. This means you can safely know that a draft has changed if `props.draft !== nextProps.draft`
Test Plan: Run tests
Reviewers: juan, evan
Reviewed By: juan, evan
Differential Revision: https://phab.nylas.com/D2902
2016-04-20 07:05:15 +08:00
|
|
|
|
|
|
|
OpenTrackingButton.containerRequired = false;
|