Mailspring/app/internal_packages/thread-list/lib/message-list-toolbar.jsx

49 lines
1.4 KiB
React
Raw Normal View History

2017-09-27 02:33:08 +08:00
import React from 'react';
import PropTypes from 'prop-types';
import ReactCSSTransitionGroup from 'react-addons-css-transition-group';
import { Rx, FocusedContentStore } from 'nylas-exports';
import ThreadListStore from './thread-list-store';
import InjectsToolbarButtons, { ToolbarRole } from './injects-toolbar-buttons';
function getObservable() {
2017-09-27 02:33:08 +08:00
return Rx.Observable
.combineLatest(
Rx.Observable.fromStore(FocusedContentStore),
ThreadListStore.selectionObservable(),
2017-09-27 02:33:08 +08:00
(store, items) => ({ focusedThread: store.focused('thread'), items })
)
2017-09-27 02:33:08 +08:00
.map(({ focusedThread, items }) => {
if (focusedThread) {
2017-09-27 02:33:08 +08:00
return [focusedThread];
}
2017-09-27 02:33:08 +08:00
return items;
});
}
2017-09-27 02:33:08 +08:00
const MessageListToolbar = ({ items, injectedButtons }) => {
const shouldRender = items.length > 0;
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>
2017-09-27 02:33:08 +08:00
);
};
MessageListToolbar.displayName = 'MessageListToolbar';
2016-05-07 07:06:16 +08:00
MessageListToolbar.propTypes = {
items: PropTypes.array,
injectedButtons: PropTypes.element,
};
const toolbarProps = {
getObservable,
extraRoles: [`MessageList:${ToolbarRole}`],
2017-09-27 02:33:08 +08:00
};
2017-09-27 02:33:08 +08:00
export default InjectsToolbarButtons(MessageListToolbar, toolbarProps);