// @flow import React, { Component } from 'react'; import { observable } from 'mobx'; import { observer, inject } from 'mobx-react'; import { Link, Redirect } from 'react-router-dom'; import styled from 'styled-components'; import { newDocumentUrl } from 'utils/routeHelpers'; import CollectionsStore from 'stores/CollectionsStore'; import Collection from 'models/Collection'; import CenteredContent from 'components/CenteredContent'; import LoadingListPlaceholder from 'components/LoadingListPlaceholder'; import Button from 'components/Button'; import HelpText from 'components/HelpText'; import Flex from 'shared/components/Flex'; type Props = { collections: CollectionsStore, match: Object, }; @observer class CollectionScene extends Component { props: Props; @observable collection: ?Collection; @observable isFetching = true; @observable redirectUrl; componentDidMount = () => { this.fetchDocument(this.props.match.params.id); }; componentWillReceiveProps(nextProps) { if (nextProps.match.params.id !== this.props.match.params.id) { this.fetchDocument(nextProps.match.params.id); } } fetchDocument = async (id: string) => { const { collections } = this.props; this.collection = await collections.fetchById(id); if (!this.collection) this.redirectUrl = '/404'; if (this.collection && this.collection.documents.length > 0) { this.redirectUrl = this.collection.documents[0].url; } this.isFetching = false; }; renderEmptyCollection() { if (!this.collection) return; return (

Create a document

Publish your first document to start building the {' '} {this.collection.name} {' '} collection.
); } render() { if (this.redirectUrl) return ; return ( {this.isFetching ? : this.renderEmptyCollection()} ); } } const NewDocumentContainer = styled(Flex)` padding-top: 50%; transform: translateY(-50%); `; const Action = styled(Flex)` margin: 10px 0; `; export default inject('collections')(CollectionScene);