chore: moving window for recent movies
This commit is contained in:
parent
ef6987da19
commit
94528b129f
1 changed files with 2 additions and 1 deletions
|
@ -63,6 +63,7 @@ const fetchAllMovies = async () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function () {
|
export default async function () {
|
||||||
|
const year = DateTime.now().year
|
||||||
const movies = await fetchAllMovies()
|
const movies = await fetchAllMovies()
|
||||||
const formatMovieData = (movies, watched = true) => movies.map((item) => {
|
const formatMovieData = (movies, watched = true) => movies.map((item) => {
|
||||||
const movie = {
|
const movie = {
|
||||||
|
@ -89,7 +90,7 @@ export default async function () {
|
||||||
}).filter(movie => watched ? movie['lastWatched'] : !movie['lastWatched'])
|
}).filter(movie => watched ? movie['lastWatched'] : !movie['lastWatched'])
|
||||||
const favoriteMovies = movies.filter(movie => movie['favorite'])
|
const favoriteMovies = movies.filter(movie => movie['favorite'])
|
||||||
const collectedMovies = movies.filter(movie => movie['collected'])
|
const collectedMovies = movies.filter(movie => movie['collected'])
|
||||||
const recentlyWatchedMovies = movies.filter(movie => movie['last_watched']).sort((a, b) => new Date(b['last_watched']) - new Date(a['last_watched']))
|
const recentlyWatchedMovies = movies.filter(movie => movie['last_watched'] && year - DateTime.fromISO(movie['last_watched']).year <= 3).sort((a, b) => new Date(b['last_watched']) - new Date(a['last_watched']))
|
||||||
|
|
||||||
return {
|
return {
|
||||||
movies: [...formatMovieData(movies), ...formatMovieData(movies, false)],
|
movies: [...formatMovieData(movies), ...formatMovieData(movies, false)],
|
||||||
|
|
Reference in a new issue