import React from 'react'; import request from 'superagent'; import { Link } from 'react-router'; import Foot from './foot'; const MusicItem = React.createClass({ render: function() { if (!this.props.item.matched_at) { return (
); } else if (!this.props.item.id) { return (
No Match
); } else { return (
{this.props.inc === 0 ? 'Found matches using' : ''}
0 ? 'youtube' : ''}> {this.props.item.service === 'youtube' && this.props.inc > 0 ? this.props.item.name : ''}
); } } }); export default React.createClass({ getInitialState: function () { if (this.props.shares && this.props.shares[0].id === this.props.params.id) { return { name: this.props.shares[0].name, artist: this.props.shares[0].artist.name, shares: this.props.shares, shareUrl: 'https://match.audio/' + this.props.shares[0].service + '/' + this.props.shares[0].type + '/' + this.props.shares[0].id }; } return { name: '', artist: '', shares: [], shareUrl: '' }; }, componentWillUnmount: function() { if (this.state.interval) { clearInterval(this.state.interval); } }, componentDidMount: function () { let complete = this.state.shares.length > 0; this.state.shares.forEach(function(share) { if (typeof share.matched_at === 'undefined') { complete = false; } }); const getShares = () => { request.get(this.props.location.pathname + '.json').end((err, res) => { const shares = res.body.shares; complete = true; shares.forEach(function(share) { if (typeof share.matched_at === 'undefined') { complete = false; } }); if (complete) { clearInterval(this.state.interval); } if (shares.length) { this.setState({ name: shares[0].name, artist: shares[0].artist.name, shares: shares, shareUrl: 'https://match.audio/' + shares[0].service + '/' + shares[0].type + '/' + shares[0].id }); } }); }; if (!this.state.shares.length) { getShares(); } // Temporary until websockets implementation this.state.interval = setInterval(function() { if (!complete) { getShares(); } }, 2000); // Some hacks to pop open the Twitter/Facebook/Google Plus sharing dialogs without using their code. Array.prototype.forEach.call(document.querySelectorAll('.share-dialog'), function(dialog){ dialog.addEventListener('click', function(e) { e.preventDefault(); const w = 845; const h = 670; const dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : screen.left; const dualScreenTop = window.screenTop !== undefined ? window.screenTop : screen.top; const width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width; const height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height; const left = ((width / 2) - (w / 2)) + dualScreenLeft; const top = ((height / 2) - (h / 2)) + dualScreenTop; const newWindow = window.open(dialog.href, 'Share Music', 'scrollbars=yes, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left); if (window.focus) { newWindow.focus(); } }); }); }, render: function() { return (

match.audio

Matched {this.state.shares[0] ? this.state.shares[0].type + 's' : ''} for

{this.state.name} - {this.state.artist}

  • Share this
  • Twitter
  • Facebook
  • Google+
{this.state.shares.map((item, i) => { return (); })}
); } });