Refactor searching
This commit is contained in:
parent
87649b5a3a
commit
bbcbe8d871
9 changed files with 155 additions and 122 deletions
|
@ -39,25 +39,49 @@ var SearchForm = React.createClass({
|
|||
|
||||
mixins: [ Router.Navigation, Router.State ],
|
||||
|
||||
getInitialState: function () {
|
||||
return {
|
||||
submitting: true
|
||||
};
|
||||
},
|
||||
|
||||
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(res) {
|
||||
that.setState({
|
||||
submitting: false
|
||||
});
|
||||
if (res.body.error) {
|
||||
return alert(res.body.error.message)
|
||||
}
|
||||
that.transitionTo("share", res.body);
|
||||
});
|
||||
},
|
||||
|
||||
componentDidMount: function () {
|
||||
this.setState({
|
||||
submitting: 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" />
|
||||
<input type="submit" className="btn btn-lg btn-custom" value="Share Music" disabled={this.state.submitting} />
|
||||
</span>
|
||||
</div>
|
||||
</form>
|
||||
|
|
|
@ -9,7 +9,7 @@ var Foot = require('./foot.jsx');
|
|||
var MusicItem = React.createClass({
|
||||
|
||||
render: function() {
|
||||
if (typeof this.props.item.id === "undefined") {
|
||||
if (!this.props.item.matched_at) {
|
||||
return (
|
||||
<div className="col-md-3 col-xs-6">
|
||||
<div className="service">
|
||||
|
@ -21,7 +21,7 @@ var MusicItem = React.createClass({
|
|||
</div>
|
||||
</div>
|
||||
);
|
||||
} else if (this.props.item.id === null) {
|
||||
} else if (!this.props.item.id) {
|
||||
return (
|
||||
<div className="col-md-3 col-xs-6">
|
||||
<div className="service">
|
||||
|
@ -102,17 +102,18 @@ module.exports = React.createClass({
|
|||
var complete = this.state.shares.length > 0;
|
||||
|
||||
this.state.shares.forEach(function(share) {
|
||||
if (typeof share.id === "undefined") {
|
||||
if (typeof share.matched_at === "undefined") {
|
||||
console.log(share)
|
||||
complete = false;
|
||||
}
|
||||
});
|
||||
|
||||
var getShares = function() {
|
||||
request.get(this.getPathname()).set('Accept', 'application/json').end(function(res) {
|
||||
request.get(this.getPathname() + ".json").end(function(res) {
|
||||
var shares = res.body.shares;
|
||||
complete = true;
|
||||
shares.forEach(function(share) {
|
||||
if (typeof share.id === "undefined") {
|
||||
if (typeof share.matched_at === "undefined") {
|
||||
complete = false;
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue