Update the shows reducer from switch to map
This commit is contained in:
parent
255aa83453
commit
d144d0a982
@ -1,4 +1,4 @@
|
||||
import { OrderedMap, Map, fromJS } from 'immutable'
|
||||
import { OrderedMap, Map, fromJS } from "immutable"
|
||||
|
||||
const defaultState = Map({
|
||||
loading: false,
|
||||
@ -9,41 +9,39 @@ const defaultState = Map({
|
||||
exploreOptions: Map(),
|
||||
});
|
||||
|
||||
export default function showsStore(state = defaultState, action) {
|
||||
switch (action.type) {
|
||||
case 'SHOW_LIST_FETCH_PENDING':
|
||||
return state.set('loading', true);
|
||||
case 'SHOW_LIST_FETCH_FULFILLED':
|
||||
const handlers = {
|
||||
"SHOW_LIST_FETCH_PENDING": state => state.set("loading", true),
|
||||
"SHOW_LIST_FETCH_FULFILLED": (state, action) => {
|
||||
let shows = Map();
|
||||
action.payload.response.data.map(function (show) {
|
||||
show.fetchingDetails = false;
|
||||
show.fetchingSubtitles = false;
|
||||
shows = shows.set(show.imdb_id, fromJS(show));
|
||||
})
|
||||
});
|
||||
|
||||
let selectedImdbId = "";
|
||||
if (shows.size > 0) {
|
||||
// Sort by year
|
||||
shows = shows.sort((a,b) => b.get('year') - a.get('year'));
|
||||
selectedImdbId = shows.first().get('imdb_id');
|
||||
shows = shows.sort((a,b) => b.get("year") - a.get("year"));
|
||||
selectedImdbId = shows.first().get("imdb_id");
|
||||
}
|
||||
|
||||
return state.delete('shows').merge(Map({
|
||||
return state.delete("shows").merge(Map({
|
||||
shows: shows,
|
||||
filter: "",
|
||||
loading: false,
|
||||
selectedImdbId: selectedImdbId,
|
||||
}))
|
||||
case 'SHOW_GET_DETAILS_PENDING':
|
||||
return state.setIn(['shows', action.payload.main.imdbId, 'fetchingDetails'], true);
|
||||
case 'SHOW_GET_DETAILS_FULFILLED':
|
||||
}));
|
||||
},
|
||||
"SHOW_GET_DETAILS_PENDING": (state, action) => state.setIn(["shows", action.payload.main.imdbId, "fetchingDetails"], true),
|
||||
"SHOW_GET_DETAILS_FULFILLED": (state, action) => {
|
||||
let show = action.payload.response.data;
|
||||
show.fetchingDetails = false;
|
||||
show.fetchingSubtitles = false;
|
||||
return state.setIn(['shows', show.imdb_id], fromJS(show));
|
||||
case 'SHOW_GET_EXPLORE_OPTIONS_FULFILLED':
|
||||
return state.set('exploreOptions', fromJS(action.payload.response.data));
|
||||
case 'SHOW_UPDATE_STORE_WISHLIST':
|
||||
return state.setIn(["shows", show.imdb_id], fromJS(show));
|
||||
},
|
||||
"SHOW_GET_EXPLORE_OPTIONS_FULFILLED": (state, action) => state.set("exploreOptions", fromJS(action.payload.response.data)),
|
||||
"SHOW_UPDATE_STORE_WISHLIST": (state, action) => {
|
||||
let season = action.payload.season;
|
||||
let episode = action.payload.episode;
|
||||
if (action.payload.wishlisted) {
|
||||
@ -55,17 +53,15 @@ export default function showsStore(state = defaultState, action) {
|
||||
}
|
||||
}
|
||||
|
||||
return state.mergeIn(['shows', action.payload.imdbId], Map({
|
||||
tracked_season: season,
|
||||
tracked_episode: episode,
|
||||
return state.mergeIn(["shows", action.payload.imdbId], Map({
|
||||
"tracked_season": season,
|
||||
"tracked_episode": episode,
|
||||
}));
|
||||
case 'UPDATE_LAST_SHOWS_FETCH_URL':
|
||||
return state.set('lastFetchUrl', action.payload.url);
|
||||
case 'SELECT_SHOW':
|
||||
return state.set('selectedImdbId', action.payload.imdbId);
|
||||
case 'SHOWS_UPDATE_FILTER':
|
||||
return state.set('filter', action.payload.filter);
|
||||
default:
|
||||
return state
|
||||
}
|
||||
},
|
||||
"UPDATE_LAST_SHOWS_FETCH_URL": (state, action) => state.set("lastFetchUrl", action.payload.url),
|
||||
"SELECT_SHOW": (state, action) => state.set("selectedImdbId", action.payload.imdbId),
|
||||
"SHOWS_UPDATE_FILTER": (state, action) => state.set("filter", action.payload.filter),
|
||||
}
|
||||
|
||||
export default (state = defaultState, action) =>
|
||||
handlers[action.type] ? handlers[action.type](state, action) : state;
|
||||
|
Loading…
x
Reference in New Issue
Block a user