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

* fix /expand and /collapse for link previews

* make props.openGraphData not required for PostAttachmentOpenGraph component
Этот коммит содержится в:
Saturnino Abril
2017-06-21 05:08:09 +08:00
коммит произвёл Joram Wilander
родитель 14054a532d
Коммит 6e2e1c3bbb

Просмотреть файл

@@ -18,7 +18,7 @@ export default class PostAttachmentOpenGraph extends React.PureComponent {
/** /**
* The open graph data to render * The open graph data to render
*/ */
openGraphData: PropTypes.object.isRequired, openGraphData: PropTypes.object,
/** /**
* Set to collapse the preview * Set to collapse the preview
@@ -50,17 +50,16 @@ export default class PostAttachmentOpenGraph extends React.PureComponent {
this.smallImageContainer = null; this.smallImageContainer = null;
this.smallImageElement = null; this.smallImageElement = null;
this.IMAGE_LOADED = {
LOADING: 'loading',
YES: 'yes',
ERROR: 'error'
};
this.fetchData = this.fetchData.bind(this); this.fetchData = this.fetchData.bind(this);
this.toggleImageVisibility = this.toggleImageVisibility.bind(this); this.toggleImageVisibility = this.toggleImageVisibility.bind(this);
this.onImageLoad = this.onImageLoad.bind(this); this.onImageLoad = this.onImageLoad.bind(this);
this.onImageError = this.onImageError.bind(this); this.onImageError = this.onImageError.bind(this);
this.truncateText = this.truncateText.bind(this);
}
IMAGE_LOADED = {
LOADING: 'loading',
YES: 'yes',
ERROR: 'error'
} }
componentWillMount() { componentWillMount() {
@@ -76,6 +75,11 @@ export default class PostAttachmentOpenGraph extends React.PureComponent {
if (nextProps.link !== this.props.link) { if (nextProps.link !== this.props.link) {
this.fetchData(nextProps.link); this.fetchData(nextProps.link);
} }
if (nextProps.previewCollapsed !== this.props.previewCollapsed) {
this.setState({
imageVisible: nextProps.previewCollapsed.startsWith('false')
});
}
} }
fetchData(url) { fetchData(url) {