2015-05-17 19:10:30 +01:00
"use strict" ;
2014-12-22 22:38:08 +00:00
2015-05-17 19:10:30 +01:00
var React = require ( "react" ) ;
var request = require ( "superagent" ) ;
var Router = require ( "react-router" ) ;
var Link = require ( "react-router" ) . Link ;
var Faq = require ( "./faq.jsx" ) ;
var Foot = require ( "./foot.jsx" ) ;
2014-12-22 22:38:08 +00:00
var Recent = React . createClass ( {
render : function ( ) {
return ( < div className = "row" >
< div className = "col-md-6 col-md-offset-3" >
< h2 > Recently Shared < / h2 >
< div className = "row recent" >
{ this . props . recents . map ( function ( item , i ) {
return ( < RecentItem item = { item } key = { i } / > ) ;
} ) }
< / div >
< / div >
< / div > ) ;
}
} ) ;
var RecentItem = React . createClass ( {
render : function ( ) {
2015-01-07 00:14:22 +00:00
if ( ! this . props . item . artwork ) {
return false ;
}
2014-12-22 22:38:08 +00:00
return (
< div className = "col-sm-4 col-xs-6" >
2015-01-10 19:39:54 +00:00
< Link to = "share" params = { this . props . item } >
2015-05-17 19:10:30 +01:00
< div className = { this . props . item . service === "youtube" ? "artwork-youtube artwork" : "artwork" } style = { { backgroundImage : "url(" + this . props . item . artwork . small + ")" } } > < / div >
2015-01-10 19:39:54 +00:00
< / Link >
2014-12-22 22:38:08 +00:00
< / div >
) ;
}
} ) ;
var SearchForm = React . createClass ( {
mixins : [ Router . Navigation , Router . State ] ,
2015-01-06 12:58:57 +00:00
getInitialState : function ( ) {
return {
2015-01-12 17:38:42 +00:00
submitting : true ,
error : false
2015-01-06 12:58:57 +00:00
} ;
} ,
2014-12-22 22:38:08 +00:00
handleSubmit : function ( e ) {
2015-01-06 12:58:57 +00:00
this . setState ( {
submitting : true
} ) ;
2014-12-22 22:38:08 +00:00
var that = this ;
e . preventDefault ( ) ;
var url = this . refs . url . getDOMNode ( ) . value . trim ( ) ;
if ( ! url ) {
2015-01-06 12:58:57 +00:00
that . setState ( {
submitting : false
} ) ;
2014-12-22 22:38:08 +00:00
return ;
}
2015-05-17 19:10:30 +01:00
request . post ( "/search" ) . send ( { url : url } ) . end ( function ( res ) {
2015-01-06 12:58:57 +00:00
that . setState ( {
submitting : false
} ) ;
if ( res . body . error ) {
2015-01-12 17:38:42 +00:00
that . setState ( { error : res . body . error . message } ) ;
2015-01-06 12:58:57 +00:00
}
2014-12-23 00:35:17 +00:00
that . transitionTo ( "share" , res . body ) ;
2014-12-22 22:38:08 +00:00
} ) ;
} ,
2015-01-06 12:58:57 +00:00
componentDidMount : function ( ) {
this . setState ( {
2015-01-12 17:38:42 +00:00
submitting : false ,
error : false
2015-01-06 12:58:57 +00:00
} ) ;
} ,
2014-12-22 22:38:08 +00:00
render : function ( ) {
return (
< form role = "form" method = "post" action = "/search" onSubmit = { this . handleSubmit } >
< div className = "input-group input-group-lg" >
< input type = "text" name = "url" placeholder = "Paste link here" className = "form-control" autofocus ref = "url" / >
< span className = "input-group-btn" >
2015-01-06 12:58:57 +00:00
< input type = "submit" className = "btn btn-lg btn-custom" value = "Share Music" disabled = { this . state . submitting } / >
2014-12-22 22:38:08 +00:00
< / span >
< / div >
2015-01-12 17:38:42 +00:00
< div className = { this . state . error ? "alert alert-warning" : "" } role = "alert" >
{ this . state . error }
< / div >
2014-12-22 22:38:08 +00:00
< / form >
) ;
}
} ) ;
module . exports = React . createClass ( {
getInitialState : function ( ) {
2014-12-23 00:35:17 +00:00
// Use this only on first page load, refresh whenever we navigate back.
if ( this . props . recents ) {
var recents = this . props . recents ;
delete this . props . recents ;
return {
recents : recents
} ;
}
2014-12-22 22:38:08 +00:00
return {
2014-12-23 00:35:17 +00:00
recents : [ ]
2014-12-22 22:38:08 +00:00
} ;
} ,
2015-05-17 19:10:30 +01:00
2014-12-22 22:38:08 +00:00
componentDidMount : function ( ) {
if ( ! this . props . recents ) {
2015-05-17 19:10:30 +01:00
request . get ( "/recent" ) . set ( "Accept" , "application/json" ) . end ( function ( res ) {
2014-12-22 22:38:08 +00:00
this . setState ( {
recents : res . body . recents
} ) ;
} . bind ( this ) ) ;
}
} ,
render : function ( ) {
return (
< div >
< div className = "page-wrap" >
< header >
< h1 > < Link to = "home" > match < span className = "audio-lighten" > . audio < / span > < / Link > < / h1 >
< / header >
< div className = "container" >
< div className = "row share-form" >
< div className = "col-md-6 col-md-offset-3" >
< SearchForm / >
< / div >
< / div >
< div className = "row blurb" >
< div className = "col-md-6 col-md-offset-3" >
2015-01-25 22:21:45 +00:00
< p > Match Audio makes sharing from music services better .
2015-05-17 19:10:30 +01:00
What happens when you share your favourite song on Spotify with a friend , but they don " t use Spotify ?
2015-01-25 22:21:45 +00:00
< / p > < p > We match album and track links from Youtube , Rdio , Spotify , Deezer , Google Music , Xbox Music , Beats Music , and iTunes and give you back one link with matches we find on all of them .
2014-12-22 22:38:08 +00:00
< / p >
< / div >
< / div >
2014-12-23 00:35:17 +00:00
< Recent recents = { this . state . recents } / >
2015-01-11 23:03:07 +00:00
< Faq / >
2015-01-11 23:20:48 +00:00
< div className = "row" >
< div className = "col-md-6 col-md-offset-3" >
< h2 > Tools < / h2 >
< div className = "row" >
< div className = "col-md-6" >
< p > Download the Chrome Extension and get Match Audio links right from your address bar . < / p >
< / div >
< div className = "col-md-6" >
< p > < a href = "https://chrome.google.com/webstore/detail/kjfpkmfgcflggjaldcfnoppjlpnidolk" > < img src = "/images/chrome-web-store.png" alt = "Download the Chrome Extension" height = "75" / > < / a > < / p >
< / div >
< / div >
< / div >
< / div >
2014-12-22 22:38:08 +00:00
< / div >
< / div >
< Foot page = "home" / >
< / div >
) ;
}
} ) ;