From 12896bd23eeba79884245c1c29fdc568cf21a7fa Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Mon, 14 Mar 2016 08:50:46 -0400 Subject: Converting to Webpack. Stage 1. --- webapp/components/post_attachment_oembed.jsx | 107 +++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 webapp/components/post_attachment_oembed.jsx (limited to 'webapp/components/post_attachment_oembed.jsx') diff --git a/webapp/components/post_attachment_oembed.jsx b/webapp/components/post_attachment_oembed.jsx new file mode 100644 index 000000000..a4e4ce001 --- /dev/null +++ b/webapp/components/post_attachment_oembed.jsx @@ -0,0 +1,107 @@ +// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +import $ from 'jquery'; +import React from 'react'; + +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) { + if (nextProps.link !== this.props.link) { + this.isLoading = false; + this.fetchData(nextProps.link); + } + } + + componentDidMount() { + this.fetchData(this.props.link); + } + + fetchData(link) { + if (!this.isLoading) { + this.isLoading = true; + let url = 'https://noembed.com/embed?nowrap=on'; + url += '&url=' + encodeURIComponent(link); + url += '&maxheight=' + this.props.provider.height; + return $.ajax({ + url, + dataType: 'jsonp', + success: (result) => { + this.isLoading = false; + if (result.error) { + this.setState({data: {}}); + } else { + this.setState({data: result}); + } + }, + error: () => { + this.setState({data: {}}); + } + }); + } + return null; + } + + render() { + let data = {}; + let content; + if ($.isEmptyObject(this.state.data)) { + content =
; + } else { + data = this.state.data; + content = ( +
+ ); + } + + return ( +
+
+
+

+ + {data.title} + +

+
+
+ {content} +
+
+
+
+
+ ); + } +} + +PostAttachmentOEmbed.propTypes = { + link: React.PropTypes.string.isRequired, + provider: React.PropTypes.object.isRequired +}; -- cgit v1.2.3-1-g7c22