Created
September 16, 2015 17:55
-
-
Save swaathi/71698e7846e503c97f20 to your computer and use it in GitHub Desktop.
Songs Container
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var SongsContainer = React.createClass({ | |
componentWillMount(){ | |
this.fetchSongs(); | |
}, | |
fetchSongs() { | |
$.ajax({ | |
url: this.props.songsPath, | |
dataType: 'json', | |
success: function(data) { | |
this.setState({songs: data}); | |
}.bind(this), | |
error: function(data) { | |
this.setState({songs: []}); | |
}.bind(this) | |
}); | |
}, | |
searchSongs(event) { | |
if (event.target.value) { | |
$.ajax({ | |
url: this.props.searchPath+"?query="+event.target.value, | |
dataType: 'json', | |
success: function(data) { | |
this.setState({songs: data}); | |
}.bind(this), | |
error: function(data) { | |
this.setState({songs: []}); | |
}.bind(this) | |
}); | |
} | |
else{ | |
this.fetchSongs(); | |
} | |
}, | |
getInitialState() { | |
return { songs: [] }; | |
}, | |
render() { | |
return ( | |
<div> | |
<Songs songs={this.state.songs} /> | |
<SongsSearch searchPath={this.props.searchPath} submitPath={this.searchSongs} cancelPath={this.fetchSongs}/> | |
</div> | |
); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment