2016-03-18 00:50:30 +08:00
|
|
|
import Rx from 'rx-lite'
|
|
|
|
import React, {Component, PropTypes} from 'react'
|
2016-03-29 16:41:24 +08:00
|
|
|
import ReactCSSTransitionGroup from 'react-addons-css-transition-group'
|
2016-03-18 00:50:30 +08:00
|
|
|
import {FocusedContentStore} from 'nylas-exports'
|
|
|
|
import ThreadListStore from './thread-list-store'
|
|
|
|
import InjectsToolbarButtons, {ToolbarRole} from './injects-toolbar-buttons'
|
|
|
|
|
|
|
|
|
|
|
|
function getObservable() {
|
|
|
|
return (
|
2016-03-23 02:28:16 +08:00
|
|
|
Rx.Observable.combineLatest(
|
2016-03-18 00:50:30 +08:00
|
|
|
Rx.Observable.fromStore(FocusedContentStore),
|
|
|
|
ThreadListStore.selectionObservable(),
|
2016-03-23 02:28:16 +08:00
|
|
|
(store, items) => ({focusedThread: store.focused('thread'), items})
|
2016-03-18 00:50:30 +08:00
|
|
|
)
|
2016-03-23 02:28:16 +08:00
|
|
|
.map(({focusedThread, items}) => {
|
|
|
|
if (focusedThread) {
|
|
|
|
return [focusedThread]
|
2016-03-18 00:50:30 +08:00
|
|
|
}
|
2016-03-23 02:28:16 +08:00
|
|
|
return items
|
2016-03-18 00:50:30 +08:00
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
class MessageListToolbar extends Component {
|
|
|
|
static displayName = 'MessageListToolbar';
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
items: PropTypes.array,
|
|
|
|
injectedButtons: PropTypes.element,
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {items, injectedButtons} = this.props
|
|
|
|
const shouldRender = items.length > 0
|
|
|
|
|
|
|
|
return (
|
2016-03-29 16:41:24 +08:00
|
|
|
<ReactCSSTransitionGroup
|
2016-03-18 00:50:30 +08:00
|
|
|
className="message-toolbar-items"
|
2016-03-29 16:41:24 +08:00
|
|
|
transitionLeaveTimeout={125}
|
|
|
|
transitionEnterTimeout={125}
|
2016-03-18 00:50:30 +08:00
|
|
|
transitionName="opacity-125ms">
|
|
|
|
{shouldRender ? injectedButtons : undefined}
|
2016-03-29 16:41:24 +08:00
|
|
|
</ReactCSSTransitionGroup>
|
2016-03-18 00:50:30 +08:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const toolbarProps = {
|
|
|
|
getObservable,
|
|
|
|
extraRoles: [`MessageList:${ToolbarRole}`],
|
|
|
|
}
|
|
|
|
|
|
|
|
export default InjectsToolbarButtons(MessageListToolbar, toolbarProps)
|