bobbe malle

This commit is contained in:
matteo
2018-12-01 03:04:08 +01:00
parent a55cc2d414
commit 2bca56b881
+73 -71
View File
@@ -3,92 +3,94 @@ import React, { Component } from 'react';
import wikijs from 'wikijs'; import wikijs from 'wikijs';
class Wikipedia extends Component { class Wikipedia extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
data: {}, data: {},
infobox: {}, infobox: {},
error: null, error: null,
isLoaded: false isLoaded: false
}; };
this.getWikiBox = this.getWikiBox.bind(this); this.getWikiBox = this.getWikiBox.bind(this);
this.raffina = this.raffina.bind(this); this.raffina = this.raffina.bind(this);
} }
getWikiBox(name){ getWikiBox(name) {
wikijs() wikijs()
.page(name) .page(name)
.then(page => page.fullInfo()) .then(page => page.fullInfo())
.then(infobox => console.log('infobox', infobox) .then(
//this.setState({ infobox }) infobox => console.log('infobox', infobox)
); //this.setState({ infobox })
//console.log('infobox', this.state.infobox) );
} //console.log('infobox', this.state.infobox)
}
raffina(results){ raffina(results) {
console.log('raffina',results); console.log('raffina', results);
return results[0]; return results[0];
} }
// componentWillMount() { // componentWillMount() {
// } // }
componentWillMount() { componentWillMount() {
wikijs().find(this.props.query, this.raffina).then(data => { wikijs()
this.setState({ .find(this.props.query, this.raffina)
data, .then(
isLoaded: true data => {
}); this.setState({
console.log(data.html()); data,
//this.getWikiBox(data.results[0]); isLoaded: true
}, error => { });
console.error(error); console.log(data.html());
this.setState({ //this.getWikiBox(data.results[0]);
isLoaded: true, },
error error => {
}); console.error(error);
}); this.setState({
} isLoaded: true,
error
});
}
);
}
// componentWillReceiveProps(nextProps) { // componentWillReceiveProps(nextProps) {
// } // }
// shouldComponentUpdate(nextProps, nextState) { // shouldComponentUpdate(nextProps, nextState) {
// } // }
// componentWillUpdate(nextProps, nextState) { // componentWillUpdate(nextProps, nextState) {
// } // }
// componentDidUpdate(prevProps, prevState) { // componentDidUpdate(prevProps, prevState) {
// } // }
// componentWillUnmount() { // componentWillUnmount() {
// } // }
render() { render() {
const { data, error, isLoaded } = this.state; const { data, error, isLoaded } = this.state;
if (error) { if (error) {
return ( return <React.Fragment>Error: {error.message}</React.Fragment>;
<React.Fragment> } else if (!isLoaded) {
Error: {error.message} -- Cannot get {error.config.url} return <React.Fragment>Loading...</React.Fragment>;
</React.Fragment> } else {
); return (
} else if (!isLoaded) { <div>
return <React.Fragment>Loading...</React.Fragment>; {/* <p>risultato ricerca wikipedia: { data.results[0] }</p> */}
} else { </div>
return ( );
<div> }
{/* <p>risultato ricerca wikipedia: { data.results[0] }</p> */} }
</div>
);
}
}
} }
export default Wikipedia; export default Wikipedia;