Archived
Merge branch 'master' of https://bitbucket.org/sco44/tecnologiabanana
This commit is contained in:
+2
-2
@@ -16,12 +16,12 @@ class TopBar extends Component {
|
|||||||
state = {
|
state = {
|
||||||
query: ''
|
query: ''
|
||||||
};
|
};
|
||||||
handleChange(event) {
|
handleChange = event => {
|
||||||
this.setState({
|
this.setState({
|
||||||
query: event.target.value
|
query: event.target.value
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
handleSubmit(event) {
|
handleSubmit = event => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.target.reset();
|
event.target.reset();
|
||||||
this.props.history.push('/search/' + this.state.query);
|
this.props.history.push('/search/' + this.state.query);
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import { Row, Col, Button, Collapse } from 'react-bootstrap';
|
|||||||
import { Switch, Route } from 'react-router';
|
import { Switch, Route } from 'react-router';
|
||||||
import Random from '../reccomenders/Random';
|
import Random from '../reccomenders/Random';
|
||||||
import Related from '../reccomenders/Related';
|
import Related from '../reccomenders/Related';
|
||||||
|
import Search from '../reccomenders/Search';
|
||||||
|
|
||||||
// and so on..
|
// and so on..
|
||||||
|
|
||||||
class Suggestion extends Component {
|
class Suggestion extends Component {
|
||||||
@@ -43,7 +45,8 @@ class Suggestion extends Component {
|
|||||||
</Col> */}
|
</Col> */}
|
||||||
<Col xs="10">
|
<Col xs="10">
|
||||||
<Switch>
|
<Switch>
|
||||||
|
|
||||||
|
<Route path='/search/:query' component={Search} />
|
||||||
<Route path='/video/:id/random' component={Random} />
|
<Route path='/video/:id/random' component={Random} />
|
||||||
{/* lasciare questo per ultimo */}
|
{/* lasciare questo per ultimo */}
|
||||||
<Route component={Related} />
|
<Route component={Related} />
|
||||||
@@ -54,8 +57,4 @@ class Suggestion extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Suggestion.propTypes = {
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Suggestion;
|
export default Suggestion;
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
class Search extends React.Component {
|
||||||
|
|
||||||
|
state = {
|
||||||
|
query: '',
|
||||||
|
res: null
|
||||||
|
}
|
||||||
|
|
||||||
|
static getDerivedStateFromProps(nextProps, prevState) {
|
||||||
|
if (nextProps.match.params.query !== prevState.query)
|
||||||
|
return { query: nextProps.match.params.query };
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
this.youtubeSearch();
|
||||||
|
}
|
||||||
|
|
||||||
|
// shouldComponentUpdate(nextProps, nextState) {
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
// componentDidUpdate(prevProps, prevState) {
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
// componentWillUnmount() {
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
youtubeSearch() {
|
||||||
|
axios.get('https://www.googleapis.com/youtube/v3/search', { //Richiesta per ottenere i commenti del video
|
||||||
|
params: {
|
||||||
|
'part': 'snippet',
|
||||||
|
'q': this.state.query,
|
||||||
|
'videoEmbeddable': 'true',
|
||||||
|
'type': 'video',
|
||||||
|
'maxResults': 30,
|
||||||
|
'topicId': '/m/04rlf, /m/02jjt',
|
||||||
|
'key': 'AIzaSyA21Odw9UdfiOJnxvA_eDfOW0OxuUfHKig' // process.env.APIKEY in production
|
||||||
|
}
|
||||||
|
}).then(
|
||||||
|
res => {
|
||||||
|
console.log(res.data)
|
||||||
|
},
|
||||||
|
error => {console.error(error)}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<span>{this.state.query} keyword</span>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Search;
|
||||||
Reference in New Issue
Block a user