// @flow import * as React from 'react'; import { observable } from 'mobx'; import { observer, inject } from 'mobx-react'; import { Redirect, Link, Switch, Route } from 'react-router-dom'; import styled, { withTheme } from 'styled-components'; import { CollectionIcon, PrivateCollectionIcon, NewDocumentIcon, PlusIcon, PinIcon, } from 'outline-icons'; import RichMarkdownEditor from 'rich-markdown-editor'; import { newDocumentUrl, collectionUrl } from 'utils/routeHelpers'; import CollectionsStore from 'stores/CollectionsStore'; import DocumentsStore from 'stores/DocumentsStore'; import PoliciesStore from 'stores/PoliciesStore'; import UiStore from 'stores/UiStore'; import Collection from 'models/Collection'; import Search from 'scenes/Search'; import CollectionEdit from 'scenes/CollectionEdit'; import CollectionMenu from 'menus/CollectionMenu'; import Actions, { Action, Separator } from 'components/Actions'; import Heading from 'components/Heading'; import Tooltip from 'components/Tooltip'; import CenteredContent from 'components/CenteredContent'; import { ListPlaceholder } from 'components/LoadingPlaceholder'; import InputSearch from 'components/InputSearch'; import Mask from 'components/Mask'; import Button from 'components/Button'; import HelpText from 'components/HelpText'; import DocumentList from 'components/DocumentList'; import Subheading from 'components/Subheading'; import PageTitle from 'components/PageTitle'; import Flex from 'shared/components/Flex'; import Modal from 'components/Modal'; import CollectionMembers from 'scenes/CollectionMembers'; import Tabs from 'components/Tabs'; import Tab from 'components/Tab'; import PaginatedDocumentList from 'components/PaginatedDocumentList'; type Props = { ui: UiStore, documents: DocumentsStore, collections: CollectionsStore, policies: PoliciesStore, match: Object, theme: Object, }; @observer class CollectionScene extends React.Component { @observable collection: ?Collection; @observable isFetching: boolean = true; @observable permissionsModalOpen: boolean = false; @observable editModalOpen: boolean = false; @observable redirectTo: ?string; componentDidMount() { this.loadContent(this.props.match.params.id); } componentWillReceiveProps(nextProps) { if (nextProps.match.params.id !== this.props.match.params.id) { this.loadContent(nextProps.match.params.id); } } componentWillUnmount() { this.props.ui.clearActiveCollection(); } loadContent = async (id: string) => { const collection = await this.props.collections.fetch(id); if (collection) { this.props.ui.setActiveCollection(collection); this.collection = collection; await this.props.documents.fetchPinned({ collectionId: id, }); } this.isFetching = false; }; onNewDocument = (ev: SyntheticEvent<>) => { ev.preventDefault(); if (this.collection) { this.redirectTo = newDocumentUrl(this.collection.id); } }; onPermissions = (ev: SyntheticEvent<>) => { ev.preventDefault(); this.permissionsModalOpen = true; }; handlePermissionsModalClose = () => { this.permissionsModalOpen = false; }; handleEditModalOpen = () => { this.editModalOpen = true; }; handleEditModalClose = () => { this.editModalOpen = false; }; renderActions() { const { match, policies } = this.props; const can = policies.abilities(match.params.id); return ( {can.update && ( )} ); } render() { const { documents, theme } = this.props; if (this.redirectTo) return ; if (!this.isFetching && !this.collection) return ; const pinnedDocuments = this.collection ? documents.pinnedInCollection(this.collection.id) : []; const hasPinnedDocuments = !!pinnedDocuments.length; const collection = this.collection; return ( {collection ? ( {collection.isEmpty ? ( {collection.name} doesn’t contain any documents yet.
Get started by creating a new one!
   {collection.private && ( )}
) : ( {collection.private ? ( ) : ( )}{' '} {collection.name} {collection.description && ( )} {hasPinnedDocuments && ( Pinned )} Recently updated Recently published Least recently updated A–Z )} {this.renderActions()}
) : ( )}
); } } const Centered = styled(Flex)` text-align: center; margin: 40vh auto 0; max-width: 380px; transform: translateY(-50%); `; const TinyPinIcon = styled(PinIcon)` position: relative; top: 4px; opacity: 0.8; `; const Wrapper = styled(Flex)` justify-content: center; margin: 10px 0; `; export default inject('collections', 'policies', 'documents', 'ui')( withTheme(CollectionScene) );