2016-02-25 20:40:35 -08:00
|
|
|
import React from 'react';
|
2016-06-16 19:20:36 -03:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2016-07-15 15:05:04 -03:00
|
|
|
import Bricks from 'bricks.js';
|
|
|
|
import history from '../routing/history';
|
2016-07-11 18:57:54 -03:00
|
|
|
import Cards from './Cards';
|
|
|
|
|
|
|
|
export default class EntryListing extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.bricksInstance = null;
|
|
|
|
|
|
|
|
this.bricksConfig = {
|
|
|
|
packed: 'data-packed',
|
|
|
|
sizes: [
|
2016-07-14 17:17:18 -03:00
|
|
|
{ columns: 1, gutter: 15 },
|
|
|
|
{ mq: '495px', columns: 2, gutter: 15 },
|
|
|
|
{ mq: '750px', columns: 3, gutter: 15 },
|
|
|
|
{ mq: '1005px', columns: 4, gutter: 15 },
|
|
|
|
{ mq: '1260px', columns: 5, gutter: 15 },
|
|
|
|
{ mq: '1515px', columns: 6, gutter: 15 },
|
|
|
|
{ mq: '1770px', columns: 7, gutter: 15 },
|
2016-07-11 18:57:54 -03:00
|
|
|
]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
this.bricksInstance = Bricks({
|
|
|
|
container: this._entries,
|
|
|
|
packed: this.bricksConfig.packed,
|
|
|
|
sizes: this.bricksConfig.sizes
|
|
|
|
});
|
|
|
|
|
|
|
|
this.bricksInstance.resize(true);
|
|
|
|
|
|
|
|
if (this.props.entries && this.props.entries.size > 0) {
|
|
|
|
setTimeout(() => {
|
|
|
|
this.bricksInstance.pack();
|
|
|
|
}, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate(prevProps) {
|
|
|
|
if ((prevProps.entries === undefined || prevProps.entries.size === 0) && this.props.entries.size === 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.bricksInstance.pack();
|
|
|
|
}
|
|
|
|
|
|
|
|
componengWillUnmount() {
|
|
|
|
this.bricksInstance.resize(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
cardFor(collection, entry, link) {
|
|
|
|
//const { entry, getMedia, onChange, onAddMedia, onRemoveMedia } = this.props;
|
|
|
|
const card = Cards[collection.getIn(['card', 'type'])] || Cards._unknown;
|
|
|
|
return React.createElement(card, {
|
|
|
|
key: entry.get('slug'),
|
|
|
|
collection: collection,
|
2016-07-15 15:05:04 -03:00
|
|
|
onClick: history.push.bind(this, link),
|
2016-07-12 17:25:26 -03:00
|
|
|
onImageLoaded: () => this.bricksInstance.pack(),
|
2016-07-11 18:57:54 -03:00
|
|
|
text: entry.getIn(['data', collection.getIn(['card', 'text'])]),
|
2016-07-12 17:03:39 -03:00
|
|
|
image: entry.getIn(['data', collection.getIn(['card', 'image'])]),
|
2016-07-11 18:57:54 -03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { collection, entries } = this.props;
|
|
|
|
const name = collection.get('name');
|
|
|
|
|
|
|
|
return <div>
|
2016-07-13 17:20:41 -03:00
|
|
|
<h1>Listing {name}</h1>
|
2016-07-11 18:57:54 -03:00
|
|
|
<div ref={(c) => this._entries = c}>
|
|
|
|
{entries.map((entry) => {
|
|
|
|
const path = `/collections/${name}/entries/${entry.get('slug')}`;
|
|
|
|
return this.cardFor(collection, entry, path);
|
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
</div>;
|
|
|
|
}
|
2016-02-25 20:40:35 -08:00
|
|
|
}
|
2016-06-16 19:20:36 -03:00
|
|
|
|
|
|
|
EntryListing.propTypes = {
|
|
|
|
collection: ImmutablePropTypes.map.isRequired,
|
|
|
|
entries: ImmutablePropTypes.list,
|
|
|
|
};
|