Add Thumbnail component

This commit is contained in:
Alex Liebowitz 2016-11-11 07:56:55 -05:00
parent 14565ec586
commit 7c42bda244

View file

@ -113,3 +113,36 @@ var Address = React.createClass({
); );
} }
}); });
var Thumbnail = React.createClass({
_defaultImageUri: '/img/default-thumb.svg',
_maxLoadTime: 10000,
propTypes: {
src: React.PropTypes.string.isRequired,
},
handleError: function() {
if (this.state.imageUrl != this._defaultImageUri) {
this.setState({
imageUri: this._defaultImageUri,
});
}
},
getInitialState: function() {
return {
imageUri: this.props.src || this._defaultImageUri,
};
},
componentDidMount: function() {
setTimeout(() => {
if (!this.refs.img.complete) {
this.setState({
imageUri: this._defaultImageUri,
});
}
}, this._maxLoadTime);
},
render: function() {
return <img ref="img" onError={this.handleError} {... this.props} src={this.state.imageUri} />
},
});