mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-01-29 03:17:47 +08:00
552b66fbaf
Summary: This diff replaces "finalizeSessionBeforeSending" with a plugin hook that is bidirectional and allows us to put the draft in the "ready to send" state every time we save it, and restore it to the "ready to edit" state every time a draft session is created to edit it. This diff also significantly restructures the draft tasks: 1. SyncbackDraftUploadsTask: - ensures that `uploads` are converted to `files` and that any existing files on the draft are part of the correct account. 1. SyncbackDraftTask: - saves the draft, nothing else. 3. SendDraftTask - sends the draft, nothing else. - deletes the entire uploads directory for the draft Test Plan: WIP Reviewers: juan, evan Reviewed By: evan Differential Revision: https://phab.nylas.com/D2753
111 lines
3.2 KiB
JavaScript
111 lines
3.2 KiB
JavaScript
/** @babel */
|
|
import Rx from 'rx-lite'
|
|
import React, {Component, PropTypes} from 'react'
|
|
import {Actions, DateUtils, Message, DatabaseStore} from 'nylas-exports'
|
|
import {RetinaImg} from 'nylas-component-kit'
|
|
import SendLaterPopover from './send-later-popover'
|
|
import SendLaterActions from './send-later-actions'
|
|
import {PLUGIN_ID} from './send-later-constants'
|
|
|
|
|
|
class SendLaterButton extends Component {
|
|
static displayName = 'SendLaterButton';
|
|
|
|
static propTypes = {
|
|
draftClientId: PropTypes.string.isRequired,
|
|
};
|
|
|
|
constructor() {
|
|
super()
|
|
this.state = {
|
|
scheduledDate: null,
|
|
}
|
|
}
|
|
|
|
componentDidMount() {
|
|
this._subscription = Rx.Observable.fromQuery(
|
|
DatabaseStore.findBy(Message, {clientId: this.props.draftClientId})
|
|
).subscribe(this.onMessageChanged);
|
|
}
|
|
|
|
componentWillUnmount() {
|
|
this._subscription.dispose();
|
|
}
|
|
|
|
onSendLater = (formattedDate, dateLabel) => {
|
|
SendLaterActions.sendLater(this.props.draftClientId, formattedDate, dateLabel);
|
|
this.setState({scheduledDate: 'saving'});
|
|
};
|
|
|
|
onCancelSendLater = () => {
|
|
SendLaterActions.cancelSendLater(this.props.draftClientId);
|
|
};
|
|
|
|
onClick = () => {
|
|
const buttonRect = React.findDOMNode(this).getBoundingClientRect()
|
|
Actions.openPopover(
|
|
<SendLaterPopover
|
|
scheduledDate={this.state.scheduledDate}
|
|
onSendLater={this.onSendLater}
|
|
onCancelSendLater={this.onCancelSendLater}
|
|
/>,
|
|
{originRect: buttonRect, direction: 'up'}
|
|
)
|
|
};
|
|
|
|
onMessageChanged = (message) => {
|
|
if (!message) return;
|
|
const {scheduledDate} = this.state;
|
|
const messageMetadata = message.metadataForPluginId(PLUGIN_ID) || {}
|
|
const nextScheduledDate = messageMetadata.sendLaterDate
|
|
|
|
if (nextScheduledDate !== scheduledDate) {
|
|
const isComposer = NylasEnv.isComposerWindow()
|
|
const isFinishedSelecting = ((scheduledDate === 'saving') && (nextScheduledDate !== null));
|
|
if (isComposer && isFinishedSelecting) {
|
|
NylasEnv.close();
|
|
}
|
|
this.setState({scheduledDate: nextScheduledDate});
|
|
}
|
|
};
|
|
|
|
render() {
|
|
const {scheduledDate} = this.state;
|
|
let className = 'btn btn-toolbar btn-send-later';
|
|
|
|
if (scheduledDate === 'saving') {
|
|
return (
|
|
<button className={className} title="Saving send date...">
|
|
<RetinaImg
|
|
name="inline-loading-spinner.gif"
|
|
mode={RetinaImg.Mode.ContentDark}
|
|
style={{width: 14, height: 14}}
|
|
/>
|
|
</button>
|
|
);
|
|
}
|
|
|
|
let dateInterpretation;
|
|
if (scheduledDate) {
|
|
className += ' btn-enabled';
|
|
const momentDate = DateUtils.futureDateFromString(scheduledDate);
|
|
if (momentDate) {
|
|
dateInterpretation = <span className="at">Sending in {momentDate.fromNow(true)}</span>;
|
|
}
|
|
}
|
|
return (
|
|
<button className={className} title="Send later…" onClick={this.onClick}>
|
|
<RetinaImg name="icon-composer-sendlater.png" mode={RetinaImg.Mode.ContentIsMask} />
|
|
{dateInterpretation}
|
|
<span> </span>
|
|
<RetinaImg name="icon-composer-dropdown.png" mode={RetinaImg.Mode.ContentIsMask} />
|
|
</button>
|
|
);
|
|
}
|
|
}
|
|
|
|
SendLaterButton.containerStyles = {
|
|
order: -99,
|
|
};
|
|
|
|
export default SendLaterButton;
|