Added: New document icon / menu to Dashboard screen

This commit is contained in:
Tom Moor
2018-06-30 14:01:21 -07:00
parent c599bb70ca
commit 5c7a182897
3 changed files with 95 additions and 21 deletions

View File

@@ -0,0 +1,53 @@
// @flow
import * as React from 'react';
import { withRouter } from 'react-router-dom';
import { inject } from 'mobx-react';
import { MoreIcon, CollectionIcon } from 'outline-icons';
import { newDocumentUrl } from 'utils/routeHelpers';
import CollectionsStore from 'stores/CollectionsStore';
import { DropdownMenu, DropdownMenuItem } from 'components/DropdownMenu';
type Props = {
label?: React.Node,
history: Object,
collections: CollectionsStore,
};
class NewDocumentMenu extends React.Component<Props> {
handleNewDocument = collection => {
this.props.history.push(newDocumentUrl(collection));
};
onOpen = () => {
const { collections } = this.props;
if (collections.orderedData.length === 1) {
this.handleNewDocument(collections.orderedData[0]);
}
};
render() {
const { collections, label, history, ...rest } = this.props;
return (
<DropdownMenu
label={label || <MoreIcon />}
onOpen={this.onOpen}
{...rest}
>
<DropdownMenuItem disabled>Choose a collection</DropdownMenuItem>
{collections.orderedData.map(collection => (
<DropdownMenuItem
key={collection.id}
onClick={() => this.handleNewDocument(collection)}
>
<CollectionIcon color={collection.color} /> {collection.name}
</DropdownMenuItem>
))}
</DropdownMenu>
);
}
}
export default withRouter(inject('collections')(NewDocumentMenu));