Archived
bobbe malle
This commit is contained in:
+73
-71
@@ -3,92 +3,94 @@ import React, { Component } from 'react';
|
||||
import wikijs from 'wikijs';
|
||||
|
||||
class Wikipedia extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
data: {},
|
||||
infobox: {},
|
||||
error: null,
|
||||
isLoaded: false
|
||||
};
|
||||
this.getWikiBox = this.getWikiBox.bind(this);
|
||||
this.raffina = this.raffina.bind(this);
|
||||
}
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
data: {},
|
||||
infobox: {},
|
||||
error: null,
|
||||
isLoaded: false
|
||||
};
|
||||
this.getWikiBox = this.getWikiBox.bind(this);
|
||||
this.raffina = this.raffina.bind(this);
|
||||
}
|
||||
|
||||
getWikiBox(name){
|
||||
wikijs()
|
||||
.page(name)
|
||||
.then(page => page.fullInfo())
|
||||
.then(infobox => console.log('infobox', infobox)
|
||||
//this.setState({ infobox })
|
||||
);
|
||||
//console.log('infobox', this.state.infobox)
|
||||
}
|
||||
getWikiBox(name) {
|
||||
wikijs()
|
||||
.page(name)
|
||||
.then(page => page.fullInfo())
|
||||
.then(
|
||||
infobox => console.log('infobox', infobox)
|
||||
//this.setState({ infobox })
|
||||
);
|
||||
//console.log('infobox', this.state.infobox)
|
||||
}
|
||||
|
||||
raffina(results){
|
||||
console.log('raffina',results);
|
||||
return results[0];
|
||||
}
|
||||
raffina(results) {
|
||||
console.log('raffina', results);
|
||||
return results[0];
|
||||
}
|
||||
|
||||
// componentWillMount() {
|
||||
// componentWillMount() {
|
||||
|
||||
// }
|
||||
// }
|
||||
|
||||
componentWillMount() {
|
||||
wikijs().find(this.props.query, this.raffina).then(data => {
|
||||
this.setState({
|
||||
data,
|
||||
isLoaded: true
|
||||
});
|
||||
console.log(data.html());
|
||||
//this.getWikiBox(data.results[0]);
|
||||
}, error => {
|
||||
console.error(error);
|
||||
this.setState({
|
||||
isLoaded: true,
|
||||
error
|
||||
});
|
||||
});
|
||||
}
|
||||
componentWillMount() {
|
||||
wikijs()
|
||||
.find(this.props.query, this.raffina)
|
||||
.then(
|
||||
data => {
|
||||
this.setState({
|
||||
data,
|
||||
isLoaded: true
|
||||
});
|
||||
console.log(data.html());
|
||||
//this.getWikiBox(data.results[0]);
|
||||
},
|
||||
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() {
|
||||
const { data, error, isLoaded } = this.state;
|
||||
if (error) {
|
||||
return (
|
||||
<React.Fragment>
|
||||
Error: {error.message} -- Cannot get {error.config.url}
|
||||
</React.Fragment>
|
||||
);
|
||||
} else if (!isLoaded) {
|
||||
return <React.Fragment>Loading...</React.Fragment>;
|
||||
} else {
|
||||
return (
|
||||
<div>
|
||||
{/* <p>risultato ricerca wikipedia: { data.results[0] }</p> */}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
render() {
|
||||
const { data, error, isLoaded } = this.state;
|
||||
if (error) {
|
||||
return <React.Fragment>Error: {error.message}</React.Fragment>;
|
||||
} else if (!isLoaded) {
|
||||
return <React.Fragment>Loading...</React.Fragment>;
|
||||
} else {
|
||||
return (
|
||||
<div>
|
||||
{/* <p>risultato ricerca wikipedia: { data.results[0] }</p> */}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default Wikipedia;
|
||||
export default Wikipedia;
|
||||
|
||||
Reference in New Issue
Block a user