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