Sidebar work

This commit is contained in:
Jori Lallo
2017-06-15 20:39:08 -07:00
parent 42e54a3a54
commit aa0ddd94bf
21 changed files with 250 additions and 368 deletions

View File

@ -3,9 +3,9 @@ import React from 'react';
import { observer, inject } from 'mobx-react';
import { Redirect } from 'react-router';
import _ from 'lodash';
import { notFoundUrl } from 'utils/routeHelpers';
import CollectionsStore from 'stores/CollectionsStore';
import CollectionStore from './CollectionStore';
import Layout from 'components/Layout';
import CenteredContent from 'components/CenteredContent';
@ -16,48 +16,28 @@ type Props = {
match: Object,
};
type State = {
redirectUrl: ?string,
};
@observer class Collection extends React.Component {
props: Props;
state: State;
store: CollectionStore;
constructor(props) {
super(props);
this.state = {
redirectUrl: null,
};
this.store = new CollectionStore();
}
componentDidMount = () => {
const { id } = this.props.match.params;
this.props.collections
.getById(id)
.then(collection => {
if (collection.type !== 'atlas')
throw new Error('TODO code up non-atlas collections');
this.setState({
redirectUrl: collection.documents[0].url,
});
})
.catch(() => {
this.setState({
redirectUrl: notFoundUrl(),
});
});
this.store.fetchCollection(id);
};
render() {
return (
<Layout>
{this.state.redirectUrl && <Redirect to={this.state.redirectUrl} />}
<CenteredContent>
<PreviewLoading />
</CenteredContent>
{this.store.redirectUrl
? <Redirect to={this.store.redirectUrl} />
: <CenteredContent>
<PreviewLoading />
</CenteredContent>}
</Layout>
);
}