From 6e2e1c3bbb12be059426d895dc1f6d4062d10532 Mon Sep 17 00:00:00 2001 From: Saturnino Abril Date: Wed, 21 Jun 2017 05:08:09 +0800 Subject: [PATCH] fix /expand and /collapse for link previews (#6676) * fix /expand and /collapse for link previews * make props.openGraphData not required for PostAttachmentOpenGraph component --- .../post_attachment_opengraph.jsx | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/webapp/components/post_view/post_attachment_opengraph/post_attachment_opengraph.jsx b/webapp/components/post_view/post_attachment_opengraph/post_attachment_opengraph.jsx index dbf8f60494..e3ddcc6d5a 100644 --- a/webapp/components/post_view/post_attachment_opengraph/post_attachment_opengraph.jsx +++ b/webapp/components/post_view/post_attachment_opengraph/post_attachment_opengraph.jsx @@ -18,7 +18,7 @@ export default class PostAttachmentOpenGraph extends React.PureComponent { /** * The open graph data to render */ - openGraphData: PropTypes.object.isRequired, + openGraphData: PropTypes.object, /** * Set to collapse the preview @@ -50,17 +50,16 @@ export default class PostAttachmentOpenGraph extends React.PureComponent { this.smallImageContainer = null; this.smallImageElement = null; + this.IMAGE_LOADED = { + LOADING: 'loading', + YES: 'yes', + ERROR: 'error' + }; + this.fetchData = this.fetchData.bind(this); this.toggleImageVisibility = this.toggleImageVisibility.bind(this); this.onImageLoad = this.onImageLoad.bind(this); this.onImageError = this.onImageError.bind(this); - this.truncateText = this.truncateText.bind(this); - } - - IMAGE_LOADED = { - LOADING: 'loading', - YES: 'yes', - ERROR: 'error' } componentWillMount() { @@ -76,6 +75,11 @@ export default class PostAttachmentOpenGraph extends React.PureComponent { if (nextProps.link !== this.props.link) { this.fetchData(nextProps.link); } + if (nextProps.previewCollapsed !== this.props.previewCollapsed) { + this.setState({ + imageVisible: nextProps.previewCollapsed.startsWith('false') + }); + } } fetchData(url) {