From 7c42bda244fefd90bfb897b7bc6922b5523f15b9 Mon Sep 17 00:00:00 2001 From: Alex Liebowitz Date: Fri, 11 Nov 2016 07:56:55 -0500 Subject: [PATCH] Add Thumbnail component --- js/component/common.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/js/component/common.js b/js/component/common.js index a751d4d8c..41a10c97b 100644 --- a/js/component/common.js +++ b/js/component/common.js @@ -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 + }, +});