summaryrefslogtreecommitdiffstats
path: root/web/react/components/post_image.jsx
diff options
context:
space:
mode:
authorhmhealey <harrisonmhealey@gmail.com>2016-02-23 16:28:16 -0500
committerhmhealey <harrisonmhealey@gmail.com>2016-02-23 17:01:24 -0500
commit9b50fb855350ea1e747ee946ab3f955430abeb75 (patch)
tree79d36f3d78d3a4ee352f224644a31754fb6b51d8 /web/react/components/post_image.jsx
parent52767d9dcdc84fca4cd7a5b5c7ece2650691b91d (diff)
downloadchat-9b50fb855350ea1e747ee946ab3f955430abeb75.tar.gz
chat-9b50fb855350ea1e747ee946ab3f955430abeb75.tar.bz2
chat-9b50fb855350ea1e747ee946ab3f955430abeb75.zip
Refactored embedded image/video code and prevented them from being displayed on deleted posts
Diffstat (limited to 'web/react/components/post_image.jsx')
-rw-r--r--web/react/components/post_image.jsx62
1 files changed, 62 insertions, 0 deletions
diff --git a/web/react/components/post_image.jsx b/web/react/components/post_image.jsx
new file mode 100644
index 000000000..b35f6d1de
--- /dev/null
+++ b/web/react/components/post_image.jsx
@@ -0,0 +1,62 @@
+// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+export default class PostImageEmbed extends React.Component {
+ constructor(props) {
+ super(props);
+
+ this.state = {
+ loaded: false
+ };
+ }
+
+ componentWillMount() {
+ this.loadImg(this.props.link);
+ }
+
+ componentWillReceiveProps(nextProps) {
+ if (nextProps.link !== this.props.link) {
+ this.setState({
+ loaded: false
+ });
+ }
+ }
+
+ componentDidUpdate(prevProps) {
+ if (!this.state.loaded && prevProps.link !== this.props.link) {
+ this.loadImg(this.props.link);
+ }
+ }
+
+ loadImg(src) {
+ const img = new Image();
+ img.onload = () => {
+ this.setState({
+ loaded: true
+ });
+ };
+ img.src = src;
+ }
+
+ render() {
+ if (!this.state.loaded) {
+ return (
+ <img
+ className='img-div placeholder'
+ height='500px'
+ />
+ );
+ }
+
+ return (
+ <img
+ className='img-div'
+ src={this.props.link}
+ />
+ );
+ }
+}
+
+PostImageEmbed.propTypes = {
+ link: React.PropTypes.string.isRequired
+};