aggiunta funzione ordinamento di recent, ripulito recent

This commit is contained in:
Gregorio
2019-02-26 12:04:24 +01:00
parent 70be1d815c
commit 06800e51cd
2 changed files with 1 additions and 45 deletions
+1
View File
@@ -109,6 +109,7 @@ class VideoPlayer extends React.Component {
tmp[j].timesWatched++;
tmp[j].lastWatched= new Date();
}
tmp.sort((a, b) => new Date(b.lastWatched).getTime() - new Date(a.lastWatched).getTime());
localStorage.setItem('lastWatched', JSON.stringify(tmp));
-45
View File
@@ -1,6 +1,3 @@
//http://site1825.tw.cs.unibo.it/TW/globpop fvitali
//http://site1825.tw.cs.unibo.it/video.json originale videolist
import React from 'react';
import { Col, ListGroup, Card, CardDeck } from 'react-bootstrap'; // eslint-disable-line no-unused-vars
import axios from 'axios'; // eslint-disable-line no-unused-vars
@@ -21,39 +18,7 @@ class Recent extends React.Component {
}
componentDidMount() {
// axios.get('http://site1825.tw.cs.unibo.it/TW/globpop', {
// 'params':{
// 'id':this.props.id
// }
// }).then(
// response => {
// //this.shuffleArray(response.data);
// console.info ('a',response.data);
this.getThumbnailsNames(JSON.parse(localStorage.getItem('lastWatched')));
let lastWatchedList = JSON.parse(localStorage.getItem('lastWatched')).map(x =>x.lastWatched)
let now = moment(new Date()); // riferimento unico temporale
let timePast = lastWatchedList.map(item => now.diff(item)) // differenza in secondi tra adesso e lastWatched
console.info(lastWatchedList, timePast.sort((a, b) => a - b))
// 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
// // exceptions from actual bugs in components.
// error => {
// console.error(error);
// this.setState({
// isLoaded: true,
// error
// });
// }
// );
}
// METODI
@@ -90,16 +55,6 @@ class Recent extends React.Component {
}
/*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 recentVideoList = JSON.parse(localStorage.getItem('lastWatched'))
const { error, isLoaded, items } = this.state;