On card image loaded, redistribute cards
This commit is contained in:
parent
ea9923e0c8
commit
7dcd8c3d64
@ -1,7 +1,38 @@
|
|||||||
import React, { PropTypes } from 'react';
|
import React, { PropTypes } from 'react';
|
||||||
import { Card } from '../UI';
|
import { Card } from '../UI';
|
||||||
|
|
||||||
export default function ImageCard({ onClick, image, text }) {
|
export default class ImageCard extends React.Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this._image = null;
|
||||||
|
this.fetchImage = this.fetchImage.bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
this._image = new Image();
|
||||||
|
if (this.props.image) {
|
||||||
|
this.fetchImage(this.props.image);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillReceiveProps(nextProps) {
|
||||||
|
if (this.props.image !== nextProps.image) {
|
||||||
|
this.fetchImage(nextProps.image);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
this._image.onload = null;
|
||||||
|
this._image = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
fetchImage(src) {
|
||||||
|
this._image.onload = this.props.onImageLoaded;
|
||||||
|
this._image.src = src;
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const { onClick, image, text } = this.props;
|
||||||
return (
|
return (
|
||||||
<Card onClick={onClick}>
|
<Card onClick={onClick}>
|
||||||
<img src={image} />
|
<img src={image} />
|
||||||
@ -9,14 +40,16 @@ export default function ImageCard({ onClick, image, text }) {
|
|||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ImageCard.propTypes = {
|
ImageCard.propTypes = {
|
||||||
image: PropTypes.string.isRequired,
|
image: PropTypes.string.isRequired,
|
||||||
|
|
||||||
onClick: PropTypes.func,
|
onClick: PropTypes.func,
|
||||||
|
onImageLoaded: PropTypes.func,
|
||||||
text: PropTypes.string.isRequired
|
text: PropTypes.string.isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
ImageCard.defaultProps = {
|
ImageCard.defaultProps = {
|
||||||
onClick: function() {},
|
onClick: function() {},
|
||||||
|
onImageLoaded: function() {}
|
||||||
};
|
};
|
||||||
|
@ -57,6 +57,7 @@ export default class EntryListing extends React.Component {
|
|||||||
key: entry.get('slug'),
|
key: entry.get('slug'),
|
||||||
collection: collection,
|
collection: collection,
|
||||||
onClick: browserHistory.push.bind(this, link),
|
onClick: browserHistory.push.bind(this, link),
|
||||||
|
onImageLoaded: () => this.bricksInstance.pack(),
|
||||||
text: entry.getIn(['data', collection.getIn(['card', 'text'])]),
|
text: entry.getIn(['data', collection.getIn(['card', 'text'])]),
|
||||||
image: entry.getIn(['data', collection.getIn(['card', 'image'])]),
|
image: entry.getIn(['data', collection.getIn(['card', 'image'])]),
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user