Skip to content

Instantly share code, notes, and snippets.

@scdekov
Created July 17, 2017 19:42
Show Gist options
  • Save scdekov/951514a804dd2a6003b460fec2e0a11e to your computer and use it in GitHub Desktop.
Save scdekov/951514a804dd2a6003b460fec2e0a11e to your computer and use it in GitHub Desktop.
import React from 'react';
import SearchForm from './SearchForm.jsx';
import Results from './Results.jsx';
import io from 'socket.io-client';
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = {items: [], currentlyPlaying: ''};
io().on('currently-playing', title => {
console.log(title);
this.state.currentlyPlaying = title || '';
});
}
search(query) {
if (!query) {
this.setState({items: []});
}
$.get(`api/search/?q=${query}`).done(data => this.setState({items: data}));
}
playVideo(item) {
$.post({
url: `api/play/`,
data: JSON.stringify({
'ytId': item.ytId,
'title': item.title
}),
'contentType': 'application/json'
})
}
render() {
return (
<section className="webdesigntuts-workshop">
<p>{this.state.currentlyPlaying}</p>
<SearchForm search={this.search.bind(this)}/>
<Results items={this.state.items} playVideo={this.playVideo.bind(this)}/>
</section>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment