Move fetchChallenges up a level

This commit is contained in:
Berkeley Martinez
2016-05-06 16:04:23 -07:00
parent 861f89683b
commit 59dcabb588
10 changed files with 46 additions and 44 deletions

View File

@ -45,3 +45,12 @@ export const createErrorObserable = error => Observable.just({
type: types.handleError,
error
});
// challenges
// these need to be used by more than one route so we put them here
export const fetchChallenges = createAction(types.fetchChallenges);
export const fetchChallengesCompleted = createAction(
types.fetchChallengesCompleted,
(_, superBlocks) => superBlocks,
entities => ({ entities })
);

View File

@ -1,8 +1,5 @@
import { Observable } from 'rx';
import { fetchChallenges } from './types';
import { fetchChallengesCompleted } from './actions';
import { handleError } from '../../../redux/types';
import { createErrorObserable, fetchChallengesCompleted } from './actions';
export default function fetchChallengesSaga(action$, getState, { services }) {
return action$
@ -12,6 +9,6 @@ export default function fetchChallengesSaga(action$, getState, { services }) {
.map(({ entities, result } = {}) => {
return fetchChallengesCompleted(entities, result);
})
.catch(error => Observable.just({ type: handleError, error }));
.catch(createErrorObserable);
});
}

View File

@ -3,4 +3,5 @@ export { default as actions } from './actions';
export { default as types } from './types';
import fetchUserSaga from './fetch-user-saga';
export const sagas = [ fetchUserSaga ];
import fetchChallengesSaga from './fetch-challenges-saga';
export const sagas = [ fetchUserSaga, fetchChallengesSaga ];

View File

@ -30,6 +30,12 @@ export default handleActions(
[types.updateNavHeight]: (state, { payload: navHeight }) => ({
...state,
navHeight
}),
// challenges
[types.fetchChallengesCompleted]: (state, { payload = [] }) => ({
...state,
superBlocks: payload
})
},
{
@ -40,6 +46,7 @@ export default handleActions(
isSignedIn: false,
csrfToken: '',
windowHeight: 0,
navHeight: 0
navHeight: 0,
superBlocks: []
}
);

View File

@ -18,5 +18,10 @@ export default createTypes([
// data handling
'updateChallengesData',
'updateJobsData',
'updateHikesData'
'updateHikesData',
// challenges
'fetchChallenges',
'fetchChallengesCompleted'
], 'app');

View File

@ -8,9 +8,9 @@ import { createSelector } from 'reselect';
import Map from './Map.jsx';
import {
clearFilter,
fetchChallenges,
updateFilter
} from '../redux/actions';
import { fetchChallenges } from '../../../redux/actions';
const bindableActions = {
clearFilter,
@ -18,7 +18,7 @@ const bindableActions = {
updateFilter
};
const superBlocksSelector = createSelector(
state => state.map.superBlocks,
state => state.app.superBlocks,
state => state.entities.superBlock,
state => state.entities.block,
state => state.entities.challenge,
@ -28,25 +28,27 @@ const superBlocksSelector = createSelector(
superBlocks: []
};
}
return superBlocks
.map(superBlockName => superBlockMap[superBlockName])
.map(superBlock => ({
...superBlock,
blocks: superBlock.blocks
.map(blockName => blockMap[blockName])
.map(block => ({
...block,
challenges: block.challenges
.map(dashedName => challengeMap[dashedName])
}))
}));
return {
superBlocks: superBlocks
.map(superBlockName => superBlockMap[superBlockName])
.map(superBlock => ({
...superBlock,
blocks: superBlock.blocks
.map(blockName => blockMap[blockName])
.map(block => ({
...block,
challenges: block.challenges
.map(dashedName => challengeMap[dashedName])
}))
}))
};
}
);
const mapStateToProps = createSelector(
superBlocksSelector,
state => state.map.filter,
(superBlocks, filter) => {
({ superBlocks }, filter) => {
return {
superBlocks,
filter

View File

@ -1,14 +1,6 @@
import { createAction } from 'redux-actions';
import types from './types';
export const fetchChallenges = createAction(types.fetchChallenges);
export const fetchChallengesCompleted = createAction(
types.fetchChallengesCompleted,
(_, superBlocks) => superBlocks,
entities => ({ entities })
);
export const updateFilter = createAction(
types.updateFilter,
e => e.target.value

View File

@ -2,5 +2,4 @@ export actions from './actions';
export reducer from './reducer';
export types from './types';
import fetchChallengesSaga from './fetch-challenges-saga';
export const sagas = [ fetchChallengesSaga ];
export const sagas = [];

View File

@ -2,17 +2,9 @@ import { handleActions } from 'redux-actions';
import types from './types';
const initialState = {
superBlocks: [],
filter: ''
};
const initialState = { filter: '' };
export default handleActions(
{
[types.fetchChallengesCompleted]: (state, { payload = [] }) => ({
...state,
superBlocks: payload
}),
[types.updateFilter]: (state, { payload = ''}) => ({
...state,
filter: payload

View File

@ -1,8 +1,6 @@
import createTypes from '../../../utils/create-types';
export default createTypes([
'fetchChallenges',
'fetchChallengesCompleted',
'updateFilter',
'clearFilter'
], 'map');