2016-06-16 22:47:45 -03:00
|
|
|
import React, { PropTypes } from 'react';
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2016-02-25 20:40:35 -08:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { loadEntries } from '../actions/entries';
|
2016-06-10 00:16:01 -03:00
|
|
|
import { selectEntries } from '../reducers';
|
2016-09-05 17:24:24 -03:00
|
|
|
import { Loader } from '../components/UI';
|
2016-02-25 20:40:35 -08:00
|
|
|
import EntryListing from '../components/EntryListing';
|
2016-09-12 11:14:21 +02:00
|
|
|
import styles from './CollectionPage.css';
|
2016-09-13 03:59:48 -03:00
|
|
|
import CollectionPageHOC from './editorialWorkflow/CollectionPageHOC';
|
2016-02-25 20:40:35 -08:00
|
|
|
|
|
|
|
class DashboardPage extends React.Component {
|
|
|
|
componentDidMount() {
|
|
|
|
const { collection, dispatch } = this.props;
|
|
|
|
if (collection) {
|
|
|
|
dispatch(loadEntries(collection));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillReceiveProps(nextProps) {
|
|
|
|
const { collection, dispatch } = this.props;
|
|
|
|
if (nextProps.collection !== collection) {
|
|
|
|
dispatch(loadEntries(nextProps.collection));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2016-06-05 01:52:18 -07:00
|
|
|
const { collections, collection, entries } = this.props;
|
2016-02-25 20:40:35 -08:00
|
|
|
if (collections == null) {
|
|
|
|
return <h1>No collections defined in your config.yml</h1>;
|
|
|
|
}
|
|
|
|
|
2016-09-12 15:35:56 +02:00
|
|
|
|
2016-09-12 11:14:21 +02:00
|
|
|
return <div className={styles.alignable}>
|
2016-09-05 17:24:24 -03:00
|
|
|
{entries ?
|
|
|
|
<EntryListing collection={collection} entries={entries}/>
|
|
|
|
:
|
|
|
|
<Loader active>{['Loading Entries', 'Caching Entries', 'This might take several minutes']}</Loader>
|
|
|
|
}
|
2016-02-25 20:40:35 -08:00
|
|
|
</div>;
|
|
|
|
}
|
|
|
|
}
|
2016-06-16 22:47:45 -03:00
|
|
|
DashboardPage.propTypes = {
|
|
|
|
collection: ImmutablePropTypes.map.isRequired,
|
|
|
|
collections: ImmutablePropTypes.orderedMap.isRequired,
|
|
|
|
dispatch: PropTypes.func.isRequired,
|
|
|
|
entries: ImmutablePropTypes.list,
|
|
|
|
};
|
|
|
|
|
2016-09-08 16:18:38 -03:00
|
|
|
/*
|
|
|
|
* Instead of checking the publish mode everywhere to dispatch & render the additional editorial workflow stuff,
|
|
|
|
* We delegate it to a Higher Order Component
|
|
|
|
*/
|
2016-09-13 03:59:48 -03:00
|
|
|
DashboardPage = CollectionPageHOC(DashboardPage);
|
2016-09-08 16:18:38 -03:00
|
|
|
|
|
|
|
|
2016-02-25 20:40:35 -08:00
|
|
|
function mapStateToProps(state, ownProps) {
|
|
|
|
const { collections } = state;
|
|
|
|
const { name, slug } = ownProps.params;
|
2016-05-30 17:13:40 -07:00
|
|
|
const collection = name ? collections.get(name) : collections.first();
|
2016-06-05 01:52:18 -07:00
|
|
|
const entries = selectEntries(state, collection.get('name'));
|
2016-02-25 20:40:35 -08:00
|
|
|
|
2016-06-16 22:47:45 -03:00
|
|
|
return { slug, collection, collections, entries };
|
2016-02-25 20:40:35 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(mapStateToProps)(DashboardPage);
|