// @flow
import React from 'react';
import { observable } from 'mobx';
import { observer, inject } from 'mobx-react';
import { Redirect } from 'react-router';
import { Link } from 'react-router-dom';
import _ from 'lodash';
import styled from 'styled-components';
import { newDocumentUrl } from 'utils/routeHelpers';
import CollectionsStore from 'stores/CollectionsStore';
import CenteredContent from 'components/CenteredContent';
import LoadingListPlaceholder from 'components/LoadingListPlaceholder';
import Button from 'components/Button';
import Flex from 'components/Flex';
import HelpText from 'components/HelpText';
type Props = {
collections: CollectionsStore,
match: Object,
};
@observer class Collection extends React.Component {
props: Props;
collection: ?Collection;
@observable isFetching = true;
@observable redirectUrl;
componentDidMount = () => {
this.fetchDocument();
};
fetchDocument = async () => {
const { collections } = this.props;
const { id } = this.props.match.params;
// $FlowIssue not the correct type?
this.collection = await collections.getById(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;
};
renderNewDocument() {
return (
Create a document
Publish your first document to start building your collection.
);
}
render() {
return (
{this.redirectUrl && }
{this.isFetching
?
: this.renderNewDocument()}
);
}
}
const NewDocumentContainer = styled(Flex)`
padding-top: 70px;
`;
const Action = styled(Flex)`
margin: 20px 0;
`;
export default inject('collections')(Collection);