Skip to content

Instantly share code, notes, and snippets.

@swaathi
Created September 16, 2015 17:55
Show Gist options
  • Save swaathi/71698e7846e503c97f20 to your computer and use it in GitHub Desktop.
Save swaathi/71698e7846e503c97f20 to your computer and use it in GitHub Desktop.
Songs Container
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