// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. export default class PostAttachmentOEmbed extends React.Component { constructor(props) { super(props); this.fetchData = this.fetchData.bind(this); this.isLoading = false; } componentWillMount() { this.setState({data: {}}); } componentWillReceiveProps(nextProps) { this.fetchData(nextProps.link); } fetchData(link) { if (!this.isLoading) { this.isLoading = true; return $.ajax({ url: 'https://noembed.com/embed?nowrap=on&url=' + encodeURIComponent(link), dataType: 'jsonp', success: (result) => { this.isLoading = false; if (result.error) { this.setState({data: {}}); } else { this.setState({data: result}); } }, error: () => { this.setState({data: {}}); } }); } } render() { if ($.isEmptyObject(this.state.data)) { return
; } return ( ); } } PostAttachmentOEmbed.propTypes = { link: React.PropTypes.string.isRequired };