This repository has been archived on 2019-10-19. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
tecnologiabanana/src/areainfo/Wikipedia.js
T

118 lines
2.4 KiB
JavaScript
Raw Normal View History

2018-11-15 18:33:17 +01:00
import React, { Component } from 'react';
// import PropTypes from 'prop-types';
import wikijs from 'wikijs';
2018-12-11 03:56:13 +01:00
import wdk from 'wikidata-sdk';
import axios from 'axios';
2018-11-15 18:33:17 +01:00
class Wikipedia extends Component {
2018-12-01 03:04:08 +01:00
constructor(props) {
super(props);
this.state = {
2018-12-11 03:56:13 +01:00
wikidata: null,
wikipedia: null,
spareobj: {},
2018-12-01 03:04:08 +01:00
error: null,
isLoaded: false
};
this.getWikiBox = this.getWikiBox.bind(this);
this.raffina = this.raffina.bind(this);
}
2018-11-15 18:33:17 +01:00
2018-12-01 03:04:08 +01:00
getWikiBox(name) {
wikijs()
.page(name)
.then(page => page.fullInfo())
.then(
infobox => console.log('infobox', infobox)
//this.setState({ infobox })
);
//console.log('infobox', this.state.infobox)
}
2018-11-15 18:33:17 +01:00
2018-12-01 03:04:08 +01:00
raffina(results) {
console.log('raffina', results);
return results[0];
}
2018-11-25 19:45:16 +01:00
2018-12-01 03:04:08 +01:00
// componentWillMount() {
2018-11-15 18:33:17 +01:00
2018-12-01 03:04:08 +01:00
// }
2018-11-15 18:33:17 +01:00
2018-12-01 03:04:08 +01:00
componentWillMount() {
2018-12-11 03:56:13 +01:00
// 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
// });
// }
// );
axios
.get(wdk.getReverseClaims('P1651', this.props.videoId)) // P1651 is youtube_video_id property
.then(wikidataSearchRes => {
if (wikidataSearchRes.data.results.bindings.length) {
axios.get(wdk.getEntities(wdk.simplify.sparqlResults(wikidataSearchRes.data), 'en'))
.then(wikidataPage => {
this.setState({
isLoaded: true,
wikidata: wikidataPage.data.entities[Object.keys(wikidataPage.data.entities)[0]]
});
console.info('wikidata baby',this.state.wikidata);
});
} else {
console.log('oof');
2018-12-01 03:04:08 +01:00
}
2018-12-11 03:56:13 +01:00
});
2018-12-01 03:04:08 +01:00
}
2018-11-15 18:33:17 +01:00
2018-12-01 03:04:08 +01:00
// componentWillReceiveProps(nextProps) {
2018-11-15 18:33:17 +01:00
2018-12-01 03:04:08 +01:00
// }
2018-11-15 18:33:17 +01:00
2018-12-01 03:04:08 +01:00
// shouldComponentUpdate(nextProps, nextState) {
2018-11-15 18:33:17 +01:00
2018-12-01 03:04:08 +01:00
// }
2018-11-15 18:33:17 +01:00
2018-12-01 03:04:08 +01:00
// componentWillUpdate(nextProps, nextState) {
2018-11-15 18:33:17 +01:00
2018-12-01 03:04:08 +01:00
// }
2018-11-15 18:33:17 +01:00
2018-12-01 03:04:08 +01:00
// componentDidUpdate(prevProps, prevState) {
2018-11-15 18:33:17 +01:00
2018-12-01 03:04:08 +01:00
// }
2018-11-15 18:33:17 +01:00
2018-12-01 03:04:08 +01:00
// componentWillUnmount() {
2018-11-15 18:33:17 +01:00
2018-12-01 03:04:08 +01:00
// }
2018-11-15 18:33:17 +01:00
2018-12-01 03:04:08 +01:00
render() {
2018-12-11 03:56:13 +01:00
const { wikidata, error, isLoaded } = this.state;
2018-12-01 03:04:08 +01:00
if (error) {
return <React.Fragment>Error: {error.message}</React.Fragment>;
} else if (!isLoaded) {
return <React.Fragment>Loading...</React.Fragment>;
} else {
return (
<div>
2018-12-11 03:56:13 +01:00
<p>risultato ricerca wikipedia:</p>
<pre>{ }</pre>
2018-12-01 03:04:08 +01:00
</div>
);
}
}
2018-11-15 18:33:17 +01:00
}
2018-12-01 03:04:08 +01:00
export default Wikipedia;