From 06800e51cdbd606ea60d426de5f9ee6c30314c09 Mon Sep 17 00:00:00 2001 From: Gregorio Date: Tue, 26 Feb 2019 12:04:24 +0100 Subject: [PATCH] aggiunta funzione ordinamento di recent, ripulito recent --- src/VideoPlayer.js | 1 + src/reccomenders/Recent.js | 45 -------------------------------------- 2 files changed, 1 insertion(+), 45 deletions(-) diff --git a/src/VideoPlayer.js b/src/VideoPlayer.js index f398eca..51a8d00 100644 --- a/src/VideoPlayer.js +++ b/src/VideoPlayer.js @@ -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)); diff --git a/src/reccomenders/Recent.js b/src/reccomenders/Recent.js index d4e9aa0..9181433 100644 --- a/src/reccomenders/Recent.js +++ b/src/reccomenders/Recent.js @@ -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;