171 lines
4.9 KiB
JavaScript
171 lines
4.9 KiB
JavaScript
"use strict";
|
|
|
|
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");
|
|
|
|
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() {
|
|
if (!this.props.item.artwork) {
|
|
return false;
|
|
}
|
|
return (
|
|
<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 + ")"}}></div>
|
|
</Link>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
});
|
|
|
|
var SearchForm = React.createClass({
|
|
|
|
mixins: [ Router.Navigation, Router.State ],
|
|
|
|
getInitialState: function () {
|
|
return {
|
|
submitting: true,
|
|
error: false
|
|
};
|
|
},
|
|
|
|
handleSubmit: function(e) {
|
|
this.setState({
|
|
submitting: true
|
|
});
|
|
var that = this;
|
|
e.preventDefault();
|
|
var url = this.refs.url.getDOMNode().value.trim();
|
|
if (!url) {
|
|
that.setState({
|
|
submitting: false
|
|
});
|
|
return;
|
|
}
|
|
request.post("/search").send({url: url}).end(function(req, res) {
|
|
that.setState({
|
|
submitting: false
|
|
});
|
|
if (res.body.error) {
|
|
that.setState({error: res.body.error.message});
|
|
}
|
|
that.transitionTo("share", res.body);
|
|
});
|
|
},
|
|
|
|
componentDidMount: function () {
|
|
this.setState({
|
|
submitting: false,
|
|
error: false
|
|
});
|
|
},
|
|
|
|
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">
|
|
<input type="submit" className="btn btn-lg btn-custom" value="Share Music" disabled={this.state.submitting} />
|
|
</span>
|
|
</div>
|
|
<div className={this.state.error ? "alert alert-warning" : ""} role="alert">
|
|
{this.state.error}
|
|
</div>
|
|
</form>
|
|
);
|
|
}
|
|
});
|
|
|
|
module.exports = React.createClass({
|
|
|
|
getInitialState: function () {
|
|
// 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
|
|
};
|
|
}
|
|
return {
|
|
recents: []
|
|
};
|
|
},
|
|
|
|
componentDidMount: function () {
|
|
if (!this.props.recents) {
|
|
request.get("/recent").set("Accept", "application/json").end(function(err, res) {
|
|
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">
|
|
<p>Match Audio makes sharing from music services better.
|
|
What happens when you share your favourite song on Spotify with a friend, but they don"t use Spotify?
|
|
</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.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
<Recent recents={this.state.recents} />
|
|
<Faq />
|
|
<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>
|
|
</div>
|
|
</div>
|
|
<Foot page="home" />
|
|
</div>
|
|
);
|
|
}
|
|
});
|