2016-03-18 00:50:30 +08:00
|
|
|
import Rx from 'rx-lite'
|
2016-05-07 07:06:16 +08:00
|
|
|
import React, {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
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2016-05-07 07:06:16 +08:00
|
|
|
const MessageListToolbar = ({items, injectedButtons}) => {
|
|
|
|
const shouldRender = items.length > 0
|
2016-03-18 00:50:30 +08:00
|
|
|
|
2016-05-07 07:06:16 +08:00
|
|
|
return (
|
|
|
|
<ReactCSSTransitionGroup
|
|
|
|
className="message-toolbar-items"
|
|
|
|
transitionLeaveTimeout={125}
|
|
|
|
transitionEnterTimeout={125}
|
|
|
|
transitionName="opacity-125ms"
|
|
|
|
>
|
|
|
|
{shouldRender ? injectedButtons : undefined}
|
|
|
|
</ReactCSSTransitionGroup>
|
|
|
|
)
|
2016-03-18 00:50:30 +08:00
|
|
|
}
|
2016-05-10 04:18:07 +08:00
|
|
|
MessageListToolbar.displayName = 'MessageListToolbar';
|
2016-05-07 07:06:16 +08:00
|
|
|
MessageListToolbar.propTypes = {
|
|
|
|
items: PropTypes.array,
|
|
|
|
injectedButtons: PropTypes.element,
|
|
|
|
};
|
|
|
|
|
2016-03-18 00:50:30 +08:00
|
|
|
const toolbarProps = {
|
|
|
|
getObservable,
|
|
|
|
extraRoles: [`MessageList:${ToolbarRole}`],
|
|
|
|
}
|
|
|
|
|
|
|
|
export default InjectsToolbarButtons(MessageListToolbar, toolbarProps)
|