From 340bb46c465f80f1b72504f495d17edcca74f3a9 Mon Sep 17 00:00:00 2001 From: Gregorio Date: Mon, 25 Feb 2019 18:45:48 +0100 Subject: [PATCH] Recenti messi in ordine di data (funzione su videoplayer) --- src/VideoPlayer.js | 3 +++ src/reccomenders/Recent.js | 11 ++++++++++- src/reccomenders/fvitali.js | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/VideoPlayer.js b/src/VideoPlayer.js index 9c2b65b..26f00a0 100644 --- a/src/VideoPlayer.js +++ b/src/VideoPlayer.js @@ -107,6 +107,9 @@ 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 331c5c8..065da5a 100644 --- a/src/reccomenders/Recent.js +++ b/src/reccomenders/Recent.js @@ -29,7 +29,17 @@ class Recent extends React.Component { // response => { // //this.shuffleArray(response.data); // console.info ('a',response.data); + // let lastWatchedList = JSON.parse(localStorage.getItem('lastWatched')).map(x =>x.lastWatched) + // lastWatchedList.sort((a,b)=> new Date(b.lastWatched).getTime() - new Date(a.lastWatched).getTime()); + this.getThumbnailsNames(JSON.parse(localStorage.getItem('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, @@ -95,7 +105,6 @@ class Recent extends React.Component { }*/ render() { - const recentVideoList = JSON.parse(localStorage.getItem('lastWatched')) const { error, isLoaded, items } = this.state; if (error) { return ( diff --git a/src/reccomenders/fvitali.js b/src/reccomenders/fvitali.js index 29d386f..eb8afb7 100644 --- a/src/reccomenders/fvitali.js +++ b/src/reccomenders/fvitali.js @@ -3,7 +3,7 @@ import { Col, Card } from 'react-bootstrap'; // eslint-disable-line no-unused-va 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 { state = {