fix /expand and /collapse for link previews (#6676)

* fix /expand and /collapse for link previews

* make props.openGraphData not required for PostAttachmentOpenGraph component
This commit is contained in:
Saturnino Abril
2017-06-21 05:08:09 +08:00
committed by Joram Wilander
parent 14054a532d
commit 6e2e1c3bbb

View File

@@ -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) {