Archived
finito fvitali
This commit is contained in:
1 parent
ca17c2d73b
commit
d0ce052bc4
7 files changed
+79
-75
No files matched your search
+57
-57
@@ -6,19 +6,20 @@ import { Col, ListGroup, Card, CardDeck } from 'react-bootstrap'; // eslint-disa
|
||||
import axios from 'axios'; // eslint-disable-line no-unused-vars
|
||||
import { Link } from 'react-router-dom'; // eslint-disable-line no-unused-vars
|
||||
/*eslint no-console: ["error", { allow: ["warn", "error", "info"] }] */
|
||||
import moment from "moment";
|
||||
|
||||
class fvitali extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
state = {
|
||||
error: null,
|
||||
isLoaded: false,
|
||||
items: [],
|
||||
headers: null
|
||||
};
|
||||
this.getThumbnails = this.getThumbnails.bind(this);
|
||||
}
|
||||
|
||||
ISO_8601parse(a) {
|
||||
return moment(a, moment.ISO_8601).format('ddd, DD/MM/YYYY hh:mm:ss');
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
axios.get('http://site1825.tw.cs.unibo.it/TW/globpop', {
|
||||
'params':{
|
||||
@@ -26,13 +27,15 @@ class fvitali extends React.Component {
|
||||
}
|
||||
}).then(
|
||||
response => {
|
||||
//this.shuffleArray(response.data);
|
||||
//this.getThumbnails(response.data);
|
||||
//this.shuffleArray(response.data);
|
||||
console.info ('a',response.data);
|
||||
this.setState({
|
||||
isLoaded: true,
|
||||
items:response.data,
|
||||
});
|
||||
this.getThumbnailsNames(response.data.recommended);
|
||||
console.info(response.data.recommended);
|
||||
// this.setState({
|
||||
// isLoaded: true,
|
||||
// items:response.data.recommended,
|
||||
// });
|
||||
|
||||
},
|
||||
// Note: it's important to handle errors here
|
||||
// instead of a catch() block so that we don't swallow
|
||||
@@ -48,73 +51,51 @@ class fvitali extends React.Component {
|
||||
}
|
||||
|
||||
// METODI
|
||||
getThumbnails(videoItems) {
|
||||
let idToLookFor = videoItems.map(item => item.videoID);
|
||||
let finalChunk = (videoItems.length % 50) + 100;
|
||||
axios
|
||||
.all([
|
||||
// chain 3 parallel get
|
||||
getThumbnailsNames(reccomended) {
|
||||
let idToLookFor = reccomended.map(item => item.videoID);
|
||||
axios.get('https://www.googleapis.com/youtube/v3/videos', {
|
||||
params: {
|
||||
part: 'snippet',
|
||||
id: idToLookFor.slice(0, 50).toString(),
|
||||
id: idToLookFor.toString(),
|
||||
key: 'AIzaSyA21Odw9UdfiOJnxvA_eDfOW0OxuUfHKig',
|
||||
fields: 'items(id,snippet/thumbnails/medium)'
|
||||
}
|
||||
}),
|
||||
axios.get('https://www.googleapis.com/youtube/v3/videos', {
|
||||
//chain multiple get into promises
|
||||
params: {
|
||||
part: 'snippet',
|
||||
id: idToLookFor.slice(50, 100).toString(),
|
||||
key: 'AIzaSyA21Odw9UdfiOJnxvA_eDfOW0OxuUfHKig',
|
||||
fields: 'items(id,snippet/thumbnails/medium)'
|
||||
}
|
||||
}),
|
||||
axios.get('https://www.googleapis.com/youtube/v3/videos', {
|
||||
//chain multiple get into promises
|
||||
params: {
|
||||
part: 'snippet',
|
||||
id: idToLookFor.slice(100, finalChunk).toString(),
|
||||
key: 'AIzaSyA21Odw9UdfiOJnxvA_eDfOW0OxuUfHKig',
|
||||
fields: 'items(id,snippet/thumbnails/medium)'
|
||||
fields: 'items(id,snippet/thumbnails/medium,snippet/title)'
|
||||
}
|
||||
})
|
||||
])
|
||||
|
||||
.then(
|
||||
axios.spread((res1, res2, res3) => {
|
||||
let allres = [].concat(
|
||||
res1.data.items,
|
||||
res2.data.items,
|
||||
res3.data.items
|
||||
);
|
||||
allres.map(resCurrentValue => {
|
||||
Object.defineProperty(
|
||||
videoItems.find(videoItem => {
|
||||
res1 => {
|
||||
res1.data.items.map(resCurrentValue => {
|
||||
Object.defineProperties(
|
||||
reccomended.find(videoItem => {
|
||||
return videoItem.videoID === resCurrentValue.id;
|
||||
}),
|
||||
'thumbnail',
|
||||
{ value: resCurrentValue.snippet.thumbnails.medium.url }
|
||||
);
|
||||
{
|
||||
'thumbnail':
|
||||
{ value: resCurrentValue.snippet.thumbnails.medium.url },
|
||||
'name':
|
||||
{value: resCurrentValue.snippet.title}
|
||||
});
|
||||
});
|
||||
this.setState({
|
||||
isLoaded: true,
|
||||
items: videoItems
|
||||
items: reccomended
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
shuffleArray(videoarray) {
|
||||
|
||||
|
||||
/*shuffleArray(videoarray) {
|
||||
for (let i = videoarray.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
[videoarray[i], videoarray[j]] = [videoarray[j], videoarray[i]]; // eslint-disable-line no-param-reassign
|
||||
}
|
||||
// Durstenfeld shuffle.
|
||||
// https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#The_modern_algorithm
|
||||
}
|
||||
}*/
|
||||
|
||||
render() {
|
||||
const ISO_8601parse = this.ISO_8601parse;
|
||||
const { error, isLoaded, items, headers } = this.state;
|
||||
if (error) {
|
||||
return (
|
||||
@@ -133,8 +114,26 @@ class fvitali extends React.Component {
|
||||
} else {
|
||||
return (
|
||||
<React.Fragment>
|
||||
{items.reccomender}{items.site}{items.lastWatched}
|
||||
{items.recommended.map(raccomandato=>(<li>{raccomandato.videoID.toString()}</li>))}
|
||||
{items.map(item=>( <Col md="4">
|
||||
<Card>
|
||||
<Link
|
||||
to={{
|
||||
pathname: '/video/' + item.videoID,
|
||||
}}
|
||||
>
|
||||
<Card.Img
|
||||
src={item.thumbnail}
|
||||
alt={'Thumbnail of ' + item.name}
|
||||
/>
|
||||
<Card.ImgOverlay>
|
||||
<Card.Title className="bg-dark d-inline text-white">
|
||||
{item.name}<br/>
|
||||
{item.lastSelected}
|
||||
</Card.Title>
|
||||
</Card.ImgOverlay>
|
||||
</Link>
|
||||
</Card>
|
||||
</Col>))}
|
||||
|
||||
</React.Fragment>
|
||||
);
|
||||
@@ -142,5 +141,6 @@ class fvitali extends React.Component {
|
||||
}
|
||||
}
|
||||
|
||||
export default fvitali;
|
||||
|
||||
|
||||
export default fvitali;
|
||||
Reference in new issue
Block a user