Refactored collections store and layout components

This commit is contained in:
Jori Lallo
2017-05-26 12:56:10 -07:00
parent 1247fd1cd2
commit 201f90030c
29 changed files with 382 additions and 348 deletions

View File

@ -0,0 +1,65 @@
// @flow
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 Layout from 'components/Layout';
import CenteredContent from 'components/CenteredContent';
import AtlasPreviewLoading from 'components/AtlasPreviewLoading';
type Props = {
collections: CollectionsStore,
match: Object,
};
type State = {
redirectUrl: ?string,
};
@observer class Collection extends React.Component {
props: Props;
state: State;
constructor(props) {
super(props);
this.state = {
redirectUrl: null,
};
}
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.navigationTree.url,
});
})
.catch(() => {
this.setState({
redirectUrl: notFoundUrl(),
});
});
};
render() {
return (
<Layout>
{this.state.redirectUrl && <Redirect to={this.state.redirectUrl} />}
<CenteredContent>
<AtlasPreviewLoading />
</CenteredContent>
</Layout>
);
}
}
export default inject('collections')(Collection);