2015-06-15 02:34:39 +01:00
import React from 'react' ;
import request from 'superagent' ;
2015-08-20 23:22:57 +01:00
import { Navigation , State , Link } from 'react-router' ;
2015-06-15 02:34:39 +01:00
import Faq from './faq' ;
import Foot from './foot' ;
2014-12-22 22:38:08 +00:00
2015-08-20 23:22:57 +01:00
const Recent = React . createClass ( {
2014-12-22 22:38:08 +00:00
render : function ( ) {
2015-06-15 02:34:39 +01:00
return ( < div className = 'row' >
< div className = 'col-md-6 col-md-offset-3' >
2014-12-22 22:38:08 +00:00
< h2 > Recently Shared < / h 2 >
2015-06-15 02:34:39 +01:00
< div className = 'row recent' >
2014-12-22 22:38:08 +00:00
{ this . props . recents . map ( function ( item , i ) {
return ( < RecentItem item = { item } key = { i } / > ) ;
} ) }
< / d i v >
< / d i v >
< / d i v > ) ;
}
} ) ;
2015-08-20 23:22:57 +01:00
const RecentItem = React . createClass ( {
2014-12-22 22:38:08 +00:00
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 (
2015-06-15 02:34:39 +01:00
< div className = 'col-sm-4 col-xs-6' >
< Link to = 'share' params = { this . props . item } >
< div className = { this . props . item . service === 'youtube' ? 'artwork-youtube artwork' : 'artwork' } style = { { backgroundImage : 'url(' + this . props . item . artwork . small + ')' } } > < / d i v >
2015-01-10 19:39:54 +00:00
< / L i n k >
2014-12-22 22:38:08 +00:00
< / d i v >
) ;
}
} ) ;
2015-08-20 23:22:57 +01:00
const SearchForm = React . createClass ( {
2014-12-22 22:38:08 +00:00
2015-06-15 02:34:39 +01:00
mixins : [ Navigation , State ] ,
2014-12-22 22:38:08 +00:00
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-08-20 23:22:57 +01:00
e . preventDefault ( ) ;
2015-01-06 12:58:57 +00:00
this . setState ( {
submitting : true
} ) ;
2015-08-20 23:22:57 +01:00
const url = this . refs . url . getDOMNode ( ) . value . trim ( ) ;
2014-12-22 22:38:08 +00:00
if ( ! url ) {
2015-08-20 23:22:57 +01:00
this . setState ( {
2015-01-06 12:58:57 +00:00
submitting : false
} ) ;
2014-12-22 22:38:08 +00:00
return ;
}
2015-08-20 23:22:57 +01:00
request . post ( '/search' ) . send ( { url : url } ) . end ( ( req , res ) => {
this . setState ( {
2015-01-06 12:58:57 +00:00
submitting : false
} ) ;
if ( res . body . error ) {
2015-08-20 23:22:57 +01:00
this . setState ( { error : res . body . error . message } ) ;
2015-01-06 12:58:57 +00:00
}
2015-08-20 23:22:57 +01:00
this . 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 (
2015-06-15 02:34:39 +01:00
< 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' >
< input type = 'submit' className = 'btn btn-lg btn-custom' value = 'Share Music' disabled = { this . state . submitting } / >
2014-12-22 22:38:08 +00:00
< / s p a n >
< / d i v >
2015-06-15 02:34:39 +01:00
< div className = { this . state . error ? 'alert alert-warning' : '' } role = 'alert' >
2015-01-12 17:38:42 +00:00
{ this . state . error }
< / d i v >
2014-12-22 22:38:08 +00:00
< / f o r m >
) ;
}
} ) ;
2015-06-15 02:34:39 +01:00
export default React . createClass ( {
2014-12-22 22:38:08 +00:00
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 ) {
2015-08-20 23:22:57 +01:00
const recents = this . props . recents ;
2014-12-23 00:35:17 +00:00
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-08-20 23:22:57 +01:00
request . get ( '/recent' ) . set ( 'Accept' , 'application/json' ) . end ( ( err , res ) => {
2014-12-22 22:38:08 +00:00
this . setState ( {
recents : res . body . recents
} ) ;
2015-08-20 23:22:57 +01:00
} ) ;
2014-12-22 22:38:08 +00:00
}
} ,
render : function ( ) {
return (
< div >
2015-06-15 02:34:39 +01:00
< div className = 'page-wrap' >
2014-12-22 22:38:08 +00:00
< header >
2015-06-15 02:34:39 +01:00
< h1 > < Link to = 'home' > match < span className = 'audio-lighten' > . audio < / s p a n > < / L i n k > < / h 1 >
2014-12-22 22:38:08 +00:00
< / h e a d e r >
2015-06-15 02:34:39 +01:00
< div className = 'container' >
< div className = 'row share-form' >
< div className = 'col-md-6 col-md-offset-3' >
2014-12-22 22:38:08 +00:00
< SearchForm / >
< / d i v >
< / d i v >
2015-06-15 02:34:39 +01:00
< 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-06-15 02:34:39 +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 > W e m a t c h a l b u m a n d t r a c k l i n k s f r o m Y o u t u b e , R d i o , S p o t i f y , D e e z e r , G o o g l e M u s i c , X b o x M u s i c , B e a t s M u s i c , a n d i T u n e s a n d g i v e y o u b a c k o n e l i n k w i t h m a t c h e s w e f i n d o n a l l o f t h e m .
2014-12-22 22:38:08 +00:00
< / p >
< / d i v >
< / d i v >
2014-12-23 00:35:17 +00:00
< Recent recents = { this . state . recents } / >
2015-01-11 23:03:07 +00:00
< Faq / >
2015-06-15 02:34:39 +01:00
< div className = 'row' >
< div className = 'col-md-6 col-md-offset-3' >
2015-01-11 23:20:48 +00:00
< h2 > Tools < / h 2 >
2015-06-15 02:34:39 +01:00
< div className = 'row' >
< div className = 'col-md-6' >
2015-01-11 23:20:48 +00:00
< p > Download the Chrome Extension and get Match Audio links right from your address bar . < / p >
< / d i v >
2015-06-15 02:34:39 +01:00
< 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 >
2015-01-11 23:20:48 +00:00
< / d i v >
< / d i v >
< / d i v >
< / d i v >
2014-12-22 22:38:08 +00:00
< / d i v >
< / d i v >
2015-06-15 02:34:39 +01:00
< Foot page = 'home' / >
2014-12-22 22:38:08 +00:00
< / d i v >
) ;
}
} ) ;