Sort the polochon movies by date_added by default
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing

This commit is contained in:
Grégoire Delattre 2020-01-04 19:45:48 +01:00
parent 9dc473e250
commit e8313c00b6

View File

@ -13,10 +13,14 @@ const handlers = {
"MOVIE_LIST_FETCH_PENDING": state => state.set("loading", true), "MOVIE_LIST_FETCH_PENDING": state => state.set("loading", true),
"MOVIE_LIST_FETCH_ERROR": state => state.set("loading", false), "MOVIE_LIST_FETCH_ERROR": state => state.set("loading", false),
"MOVIE_LIST_FETCH_FULFILLED": (state, action) => { "MOVIE_LIST_FETCH_FULFILLED": (state, action) => {
let movies = Map(); let allMoviesInPolochon = true
let movies = Map()
action.payload.response.data.map(function (movie) { action.payload.response.data.map(function (movie) {
movie.fetchingDetails = false; movie.fetchingDetails = false;
movie.fetchingSubtitles = false; movie.fetchingSubtitles = false;
if (movie.polochon_url === "") {
allMoviesInPolochon = false
}
movies = movies.set(movie.imdb_id, fromJS(movie)); movies = movies.set(movie.imdb_id, fromJS(movie));
}) })
@ -24,7 +28,16 @@ const handlers = {
let selectedImdbId = ""; let selectedImdbId = "";
if (movies.size > 0) { if (movies.size > 0) {
// Sort by year // 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"); selectedImdbId = movies.first().get("imdb_id");
} }