Skip to content

Commit

Permalink
fix /expand and /collapse for link previews (mattermost#6676)
Browse files Browse the repository at this point in the history
* fix /expand and /collapse for link previews

* make props.openGraphData not required for PostAttachmentOpenGraph component
  • Loading branch information
saturninoabril authored and jwilander committed Jun 20, 2017
1 parent fbea55a commit e2524b5
Showing 1 changed file with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand All @@ -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) {
Expand Down

0 comments on commit e2524b5

Please sign in to comment.