<commit_before>'use strict';

var React = require('react');
var Glyphicon = require('../glyphicon.jsx');
var soundCloud = require('../../utils/sound-cloud');
var vimeoApi = require('../../utils/vimeo-api');
var getVimeoId = require('../../utils/get-vimeo-id');

var MediaObjectPreview = React.createClass({

	getInitialState: function() {
		return {
			thumbImage: undefined 
		};
	},

	loadThumbImage: function(url) {
		var mo = this.props.mediaObject;
		if (! this.state.thumbImage) {
			switch(mo.type) {
				case 'audio':
					soundCloud.waveformUrl(mo.url, function(url) {
						// triggers invariant violation sometimes
						this.setState({thumbImage: url});
					}.bind(this));
					break;

				case 'video':
					vimeoApi.video(getVimeoId(mo.url), function(err, data) {
						this.setState({thumbImage: data.pictures.sizes[0].link});
					}.bind(this));
					break;		
			}
		}
	},

	componentWillMount: function() {
		this.loadThumbImage();
	},

	componentWillReceiveProps: function(nextProps) {
		this.loadThumbImage();	
	},

	render: function() {
		var type = this.props.mediaObject.type,
			extra;

		switch(type) {
		 	case 'image':
		 		extra = <img src={this.props.mediaObject.url} />;
		 		break;
		 	case 'video': 
		 		if (this.state.thumbImage) {
		 			extra = <img src={this.state.thumbImage} />;	
		 		} else {
		 			extra = <Glyphicon icon='facetime-video' />;
		 		}
		 		break;
		 	case 'audio':
		 		if (this.state.thumbImage) {
		 			extra = <img className='waveform-url' src={this.state.thumbImage} />;	
		 		} else {
		 			extra = <Glyphicon icon='volume-up' />;<commit_msg>fix rendering bug of thumbnails in media-object-preview<commit_after>'use strict';

var React = require('react');
var Glyphicon = require('../glyphicon.jsx');
var soundCloud = require('../../utils/sound-cloud');
var vimeoApi = require('../../utils/vimeo-api');
var getVimeoId = require('../../utils/get-vimeo-id');

var MediaObjectPreview = React.createClass({

	getInitialState: function() {
		return {
			thumbImage: undefined 
		};
	},

	loadThumbImage: function(mediaObject) {
		
		switch(mediaObject.type) {
			case 'audio':
				soundCloud.waveformUrl(mediaObject.url, function(url) {
					// triggers invariant violation sometimes
					this.setState({thumbImage: url});
				}.bind(this));
				break;

			case 'video':
				vimeoApi.video(getVimeoId(mediaObject.url), function(err, data) {
					this.setState({thumbImage: data.pictures.sizes[0].link});
				}.bind(this));
				break;		
		}
		
	},

	componentWillMount: function() {
		this.loadThumbImage(this.props.mediaObject);
	},

	componentWillReceiveProps: function(nextProps) {
		this.loadThumbImage(nextProps.mediaObject);	
	},

	render: function() {
		var type = this.props.mediaObject.type,
			extra;

		switch(type) {
		 	case 'image':
		 		extra = <img src={this.props.mediaObject.url} />;
		 		break;
		 	case 'video': 
		 		if (this.state.thumbImage) {
		 			extra = <img src={this.state.thumbImage} />;	
		 		} else {
		 			extra = <Glyphicon icon='facetime-video' />;
		 		}
		 		break;
		 	case 'audio':
		 		if (this.state.thumbImage) {
		 			extra = <img className='waveform-url' src={this.state.thumbImage} />;	
		 		} else {
		 			extra = <Glyphicon icon='volume-up' />;
{'fraction_non_alphanumeric': 0.16517719568567027, 'fraction_numerical': 0.0006163328197226503, 'mean_word_length': 3.1297709923664123, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5523467', 'n_tokens_mistral': 1335, 'n_tokens_neox': 1100, 'n_words': 195}