From d8bd57901e33a7057e26e782e295099ffcc0da89 Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Wed, 6 Sep 2017 23:04:13 -0700 Subject: Removing webapp --- webapp/components/youtube_video/index.js | 16 -- webapp/components/youtube_video/youtube_video.jsx | 245 ---------------------- 2 files changed, 261 deletions(-) delete mode 100644 webapp/components/youtube_video/index.js delete mode 100644 webapp/components/youtube_video/youtube_video.jsx (limited to 'webapp/components/youtube_video') diff --git a/webapp/components/youtube_video/index.js b/webapp/components/youtube_video/index.js deleted file mode 100644 index 592e52240..000000000 --- a/webapp/components/youtube_video/index.js +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import {connect} from 'react-redux'; -import {getCurrentChannelId} from 'mattermost-redux/selectors/entities/channels'; - -import YoutubeVideo from './youtube_video.jsx'; - -function mapStateToProps(state, ownProps) { - return { - ...ownProps, - currentChannelId: getCurrentChannelId(state) - }; -} - -export default connect(mapStateToProps)(YoutubeVideo); diff --git a/webapp/components/youtube_video/youtube_video.jsx b/webapp/components/youtube_video/youtube_video.jsx deleted file mode 100644 index c2bfa317c..000000000 --- a/webapp/components/youtube_video/youtube_video.jsx +++ /dev/null @@ -1,245 +0,0 @@ -// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import {getYoutubeVideoInfo} from 'actions/integration_actions.jsx'; -import * as Utils from 'utils/utils.jsx'; - -const ytRegex = /(?:http|https):\/\/(?:www\.|m\.)?(?:(?:youtube\.com\/(?:(?:v\/)|(?:(?:watch|embed\/watch)(?:\/|.*v=))|(?:embed\/)|(?:user\/[^/]+\/u\/[0-9]\/)))|(?:youtu\.be\/))([^#&?]*)/; - -import React from 'react'; -import PropTypes from 'prop-types'; - -export default class YoutubeVideo extends React.PureComponent { - static propTypes = { - channelId: PropTypes.string.isRequired, - currentChannelId: PropTypes.string.isRequired, - link: PropTypes.string.isRequired, - show: PropTypes.bool.isRequired, - onLinkLoaded: PropTypes.func - } - - constructor(props) { - super(props); - - this.updateStateFromProps = this.updateStateFromProps.bind(this); - this.handleReceivedMetadata = this.handleReceivedMetadata.bind(this); - this.handleMetadataError = this.handleMetadataError.bind(this); - this.loadWithoutKey = this.loadWithoutKey.bind(this); - - this.play = this.play.bind(this); - this.stop = this.stop.bind(this); - - this.state = { - loaded: false, - failed: false, - playing: false, - title: '' - }; - } - - componentWillMount() { - this.updateStateFromProps(this.props); - } - - componentWillReceiveProps(nextProps) { - this.updateStateFromProps(nextProps); - } - - updateStateFromProps(props) { - const link = props.link; - - const match = link.trim().match(ytRegex); - if (!match || match[1].length !== 11) { - return; - } - - if (props.show === false) { - this.stop(); - } - - if (props.channelId !== props.currentChannelId) { - this.stop(); - } - - this.setState({ - videoId: match[1], - time: this.handleYoutubeTime(link) - }); - } - - handleYoutubeTime(link) { - const timeRegex = /[\\?&]t=([0-9]+h)?([0-9]+m)?([0-9]+s?)/; - - const time = link.match(timeRegex); - if (!time || !time[0]) { - return ''; - } - - const hours = time[1] ? time[1].match(/([0-9]+)h/) : null; - const minutes = time[2] ? time[2].match(/([0-9]+)m/) : null; - const seconds = time[3] ? time[3].match(/([0-9]+)s?/) : null; - - let ticks = 0; - - if (hours && hours[1]) { - ticks += parseInt(hours[1], 10) * 3600; - } - - if (minutes && minutes[1]) { - ticks += parseInt(minutes[1], 10) * 60; - } - - if (seconds && seconds[1]) { - ticks += parseInt(seconds[1], 10); - } - - return '&start=' + ticks.toString(); - } - - componentDidMount() { - const key = global.window.mm_config.GoogleDeveloperKey; - if (key) { - getYoutubeVideoInfo(key, this.state.videoId, - this.handleReceivedMetadata, this.handleMetadataError); - } else { - this.loadWithoutKey(); - } - this.props.onLinkLoaded(); - } - - loadWithoutKey() { - this.setState({ - loaded: true, - thumb: 'https://i.ytimg.com/vi/' + this.state.videoId + '/hqdefault.jpg' - }); - } - - handleMetadataError() { - this.setState({ - failed: true, - loaded: true, - title: Utils.localizeMessage('youtube_video.notFound', 'Video not found') - }); - } - - handleReceivedMetadata(data) { - if (!data || !data.items || !data.items.length || !data.items[0].snippet) { - this.setState({ - failed: true, - loaded: true, - title: Utils.localizeMessage('youtube_video.notFound', 'Video not found') - }); - return null; - } - const metadata = data.items[0].snippet; - let thumb = 'https://i.ytimg.com/vi/' + this.state.videoId + '/hqdefault.jpg'; - if (metadata.liveBroadcastContent === 'live') { - thumb = 'https://i.ytimg.com/vi/' + this.state.videoId + '/hqdefault_live.jpg'; - } - - this.setState({ - loaded: true, - receivedYoutubeData: true, - title: metadata.title, - thumb - }); - return null; - } - - play() { - this.setState({playing: true}); - } - - stop() { - this.setState({playing: false}); - } - - render() { - if (!this.state.loaded) { - return ( -
-
-
- ); - } - - let header; - if (this.state.title) { - header = ( -

- {'Youtube - '} - - - {this.state.title} - - -

- ); - } - - let content; - if (this.state.failed) { - content = ( -
-
-
-
-
{Utils.localizeMessage('youtube_video.notFound', 'Video not found')}
-
-
-
- ); - } else if (this.state.playing) { - content = ( -