From 62722d45b0b7b9c358407481155da44ede0df6c1 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Fri, 13 Dec 2024 19:13:55 +0200 Subject: [PATCH] Fixed: Using all movie genres for collection filters --- .../src/Store/Actions/movieCollectionActions.js | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/frontend/src/Store/Actions/movieCollectionActions.js b/frontend/src/Store/Actions/movieCollectionActions.js index c335a936d..be9be6ad5 100644 --- a/frontend/src/Store/Actions/movieCollectionActions.js +++ b/frontend/src/Store/Actions/movieCollectionActions.js @@ -91,12 +91,8 @@ export const defaultState = { genres: function(item, filterValue, type) { const predicate = filterTypePredicates[type]; - let allGenres = []; - item.movies.forEach((movie) => { - allGenres = allGenres.concat(movie.genres); - }); - - const genres = Array.from(new Set(allGenres)).slice(0, 3); + const allGenres = item.movies.flatMap(({ genres }) => genres); + const genres = Array.from(new Set(allGenres)); return predicate(genres, filterValue); }, @@ -138,12 +134,8 @@ export const defaultState = { type: filterBuilderTypes.ARRAY, optionsSelector: function(items) { const genreList = items.reduce((acc, collection) => { - let collectionGenres = []; - collection.movies.forEach((movie) => { - collectionGenres = collectionGenres.concat(movie.genres); - }); - - const genres = Array.from(new Set(collectionGenres)).slice(0, 3); + const collectionGenres = collection.movies.flatMap(({ genres }) => genres); + const genres = Array.from(new Set(collectionGenres)); genres.forEach((genre) => { acc.push({