Mailspring/app/internal_packages/message-list/lib/thread-trash-button.jsx

51 lines
1.1 KiB
React
Raw Normal View History

import {
2017-09-27 02:33:08 +08:00
React,
PropTypes,
Actions,
DOMUtils,
TaskFactory,
FocusedPerspectiveStore,
} from 'nylas-exports';
2017-09-27 02:33:08 +08:00
import { RetinaImg } from 'nylas-component-kit';
export default class ThreadTrashButton extends React.Component {
2017-09-27 02:33:08 +08:00
static displayName = 'ThreadTrashButton';
static containerRequired = false;
static propTypes = {
2017-09-27 02:33:08 +08:00
thread: PropTypes.object.isRequired,
};
2017-09-27 02:33:08 +08:00
_onRemove = e => {
if (!DOMUtils.nodeIsVisible(e.currentTarget)) {
return;
}
const tasks = TaskFactory.tasksForMovingToTrash({
2017-09-27 02:33:08 +08:00
source: 'Toolbar Button: Thread List',
threads: [this.props.thread],
});
Actions.queueTasks(tasks);
Actions.popSheet();
e.stopPropagation();
2017-09-27 02:33:08 +08:00
};
render() {
2017-09-27 02:33:08 +08:00
const allowed = FocusedPerspectiveStore.current().canMoveThreadsTo(
[this.props.thread],
'trash'
);
if (!allowed) {
2017-09-27 02:33:08 +08:00
return <span />;
}
return (
<button
className="btn btn-toolbar"
2017-09-27 02:33:08 +08:00
style={{ order: -106 }}
title="Move to Trash"
onClick={this._onRemove}
>
<RetinaImg name="toolbar-trash.png" mode={RetinaImg.Mode.ContentIsMask} />
</button>
);
}
}