diff --git a/frontend/js/reducers/movies.js b/frontend/js/reducers/movies.js index 395e4ad..8c48427 100644 --- a/frontend/js/reducers/movies.js +++ b/frontend/js/reducers/movies.js @@ -13,10 +13,14 @@ const handlers = { "MOVIE_LIST_FETCH_PENDING": state => state.set("loading", true), "MOVIE_LIST_FETCH_ERROR": state => state.set("loading", false), "MOVIE_LIST_FETCH_FULFILLED": (state, action) => { - let movies = Map(); + let allMoviesInPolochon = true + let movies = Map() action.payload.response.data.map(function (movie) { movie.fetchingDetails = false; movie.fetchingSubtitles = false; + if (movie.polochon_url === "") { + allMoviesInPolochon = false + } movies = movies.set(movie.imdb_id, fromJS(movie)); }) @@ -24,7 +28,16 @@ const handlers = { let selectedImdbId = ""; if (movies.size > 0) { // Sort by year - movies = movies.sort((a,b) => b.get("year") - a.get("year")); + movies = movies.sort((a,b) => { + if (!allMoviesInPolochon) { + return b.get("year") - a.get("year") + } + + const dateA = new Date(a.get("date_added")) + const dateB = new Date(b.get("date_added")) + return dateA > dateB ? -1 : dateA < dateB ? 1 : 0; + }); + selectedImdbId = movies.first().get("imdb_id"); }