import React from "react"; import classNames from 'classnames'; import {RetinaImg} from 'nylas-component-kit'; import { Actions, TaskFactory, AccountStore, CategoryStore, FocusedContentStore, FocusedPerspectiveStore, } from "nylas-exports"; import ThreadListStore from './thread-list-store'; export class ArchiveButton extends React.Component { static displayName = 'ArchiveButton'; static containerRequired = false; static propTypes = { items: React.PropTypes.array.isRequired, } _onArchive = (event) => { const tasks = TaskFactory.tasksForArchiving({threads: this.props.items}) Actions.queueTasks(tasks); Actions.popSheet(); event.stopPropagation(); return; } render() { const allowed = FocusedPerspectiveStore.current().canArchiveThreads(this.props.items); if (!allowed) { return ; } return ( ) } } export class TrashButton extends React.Component { static displayName = 'TrashButton' static containerRequired = false; static propTypes = { items: React.PropTypes.array.isRequired, } _onRemove = (event) => { const tasks = TaskFactory.tasksForMovingToTrash({threads: this.props.items}); Actions.queueTasks(tasks); Actions.popSheet(); event.stopPropagation(); return; } render() { const allowed = FocusedPerspectiveStore.current().canMoveThreadsTo(this.props.items, 'trash') if (!allowed) { return ; } return ( ); } } export class MarkAsSpamButton extends React.Component { static displayName = 'MarkAsSpamButton'; static containerRequired = false; static propTypes = { items: React.PropTypes.array.isRequired, } _allInSpam() { return this.props.items.every(item => item.categories.map(c => c.name).includes('spam')); } _onNotSpam = (event) => { const tasks = TaskFactory.tasksForApplyingCategories({ threads: this.props.items, categoriesToAdd: (accountId) => { const account = AccountStore.accountForId(accountId) return account.usesFolders() ? [CategoryStore.getInboxCategory(accountId)] : []; }, categoriesToRemove: (accountId) => { return [CategoryStore.getSpamCategory(accountId)]; }, }) Actions.queueTasks(tasks); Actions.popSheet(); event.stopPropagation(); return; } _onMarkAsSpam = (event) => { const tasks = TaskFactory.tasksForMarkingAsSpam({threads: this.props.items}); Actions.queueTasks(tasks); Actions.popSheet(); event.stopPropagation(); return; } render() { if (this._allInSpam()) { return ( ) } const allowed = FocusedPerspectiveStore.current().canMoveThreadsTo(this.props.items, 'spam'); if (!allowed) { return ; } return ( ); } } export class ToggleStarredButton extends React.Component { static displayName = 'ToggleStarredButton'; static containerRequired = false; static propTypes = { items: React.PropTypes.array.isRequired, }; _onStar = (event) => { const task = TaskFactory.taskForInvertingStarred({threads: this.props.items}); Actions.queueTask(task); event.stopPropagation(); return; } render() { const postClickStarredState = this.props.items.every((t) => t.starred === false); const title = postClickStarredState ? "Star" : "Unstar"; const imageName = postClickStarredState ? "toolbar-star.png" : "toolbar-star-selected.png" return ( ); } } export class ToggleUnreadButton extends React.Component { static displayName = 'ToggleUnreadButton'; static containerRequired = false; static propTypes = { items: React.PropTypes.array.isRequired, } _onClick = (event) => { const task = TaskFactory.taskForInvertingUnread({threads: this.props.items}); Actions.queueTask(task); Actions.popSheet(); event.stopPropagation(); return; } render() { const postClickUnreadState = this.props.items.every(t => t.unread === false); const fragment = postClickUnreadState ? "unread" : "read"; return ( ); } } class ThreadArrowButton extends React.Component { static propTypes = { getStateFromStores: React.PropTypes.func, direction: React.PropTypes.string, command: React.PropTypes.string, title: React.PropTypes.string, } constructor(props) { super(props); this.state = this.props.getStateFromStores(); } componentDidMount() { this._unsubscribe = ThreadListStore.listen(this._onStoreChange); this._unsubscribe_focus = FocusedContentStore.listen(this._onStoreChange); } componentWillUnmount() { this._unsubscribe(); this._unsubscribe_focus(); } _onClick = () => { if (this.state.disabled) { return; } NylasEnv.commands.dispatch(this.props.command); return; } _onStoreChange = () => { this.setState(this.props.getStateFromStores()); } render() { const {direction, title} = this.props; const classes = classNames({ "btn-icon": true, "message-toolbar-arrow": true, "disabled": this.state.disabled, }); return (
); } } export const DownButton = () => { const getStateFromStores = () => { const selectedId = FocusedContentStore.focusedId('thread'); const lastIndex = ThreadListStore.dataSource().count() - 1 const lastItem = ThreadListStore.dataSource().get(lastIndex); return { disabled: (lastItem && lastItem.id === selectedId), }; } return ( ); } DownButton.displayName = 'DownButton'; DownButton.containerRequired = false; export const UpButton = () => { const getStateFromStores = () => { const selectedId = FocusedContentStore.focusedId('thread'); const item = ThreadListStore.dataSource().get(0) return { disabled: (item && item.id === selectedId), }; } return ( ); } UpButton.displayName = 'UpButton'; UpButton.containerRequired = false;