Move to localize non ui data
parent
c7af14bcf7
commit
f29545ef6c
|
@ -2,6 +2,7 @@ import { combineReducers } from 'redux';
|
|||
import { reducer as formReducer } from 'redux-form';
|
||||
|
||||
import { reducer as app } from './redux';
|
||||
import entitieReducer from './redux/entities-reducer';
|
||||
import { reducer as hikesApp } from './routes/Hikes/redux';
|
||||
import { reducer as challengesApp } from './routes/challenges/redux';
|
||||
import {
|
||||
|
@ -12,6 +13,7 @@ import {
|
|||
export default function createReducer(sideReducers = {}) {
|
||||
return combineReducers({
|
||||
...sideReducers,
|
||||
entities: entitieReducer,
|
||||
app,
|
||||
hikesApp,
|
||||
jobsApp,
|
||||
|
|
|
@ -33,3 +33,9 @@ export const hardGoTo = createAction(types.hardGoTo);
|
|||
|
||||
export const updateWindowHeight = createAction(types.updateWindowHeight);
|
||||
export const updateNavHeight = createAction(types.updateNavHeight);
|
||||
|
||||
|
||||
// data
|
||||
export const updateChallengesData = createAction(types.updateChallengesData);
|
||||
export const updateJobsData = createAction(types.updateJobsData);
|
||||
export const updateHikesData = createAction(types.updateHikesData);
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
const initialState = {
|
||||
hike: {},
|
||||
challenge: {},
|
||||
job: {}
|
||||
};
|
||||
|
||||
export default function dataReducer(state = initialState, action) {
|
||||
if (action.meta && action.meta.entities) {
|
||||
return {
|
||||
...state,
|
||||
...action.meta.entities
|
||||
};
|
||||
}
|
||||
return state;
|
||||
}
|
|
@ -13,5 +13,10 @@ export default createTypes([
|
|||
'hardGoTo',
|
||||
|
||||
'updateWindowHeight',
|
||||
'updateNavHeight'
|
||||
'updateNavHeight',
|
||||
|
||||
// data handling
|
||||
'updateChallengesData',
|
||||
'updateJobsData',
|
||||
'updateHikesData'
|
||||
], 'app');
|
||||
|
|
|
@ -13,9 +13,9 @@ import contain from '../../../utils/professor-x';
|
|||
// const log = debug('fcc:hikes');
|
||||
|
||||
const mapStateToProps = createSelector(
|
||||
state => state.hikesApp.hikes.entities,
|
||||
state => state.hikesApp.hikes.results,
|
||||
(hikesMap, hikesByDashedName)=> {
|
||||
state => state.entities.hike,
|
||||
state => state.hikesApp.hikes,
|
||||
(hikesMap, hikesByDashedName) => {
|
||||
if (!hikesMap || !hikesByDashedName) {
|
||||
return { hikes: [] };
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ export class Lecture extends React.Component {
|
|||
|
||||
componentWillMount() {
|
||||
if (!this.props.id) {
|
||||
this.props.hardGoTo('/map');
|
||||
// this.props.hardGoTo('/map');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,8 @@ export const fetchHikes = createAction(types.fetchHikes);
|
|||
// called within fetchHikesSaga
|
||||
export const fetchHikesCompleted = createAction(
|
||||
types.fetchHikesCompleted,
|
||||
(hikes, currentHike) => ({ hikes, currentHike })
|
||||
(entities, hikes, currentHike) => ({ hikes, currentHike }),
|
||||
entities => ({ entities })
|
||||
);
|
||||
|
||||
export const resetHike = createAction(types.resetHike);
|
||||
|
|
|
@ -25,14 +25,9 @@ export default ({ services }) => ({ dispatch }) => next => {
|
|||
{ hikes: arrayOf(hike) }
|
||||
);
|
||||
|
||||
hikes = {
|
||||
entities: entities.hike,
|
||||
results: result.hikes
|
||||
};
|
||||
const currentHike = findCurrentHike(result.hikes, dashedName);
|
||||
|
||||
const currentHike = findCurrentHike(hikes, dashedName);
|
||||
|
||||
return fetchHikesCompleted(hikes, currentHike);
|
||||
return fetchHikesCompleted(entities, result.hikes, currentHike);
|
||||
})
|
||||
.catch(error => {
|
||||
return Observable.just({
|
||||
|
|
|
@ -3,10 +3,7 @@ import types from './types';
|
|||
import { findNextHikeName } from './utils';
|
||||
|
||||
const initialState = {
|
||||
hikes: {
|
||||
results: [],
|
||||
entities: {}
|
||||
},
|
||||
hikes: [],
|
||||
// ui
|
||||
// hike dashedName
|
||||
currentHike: '',
|
||||
|
@ -91,7 +88,6 @@ export default handleActions(
|
|||
|
||||
[types.fetchHikesCompleted]: (state, { payload }) => {
|
||||
const { hikes, currentHike } = payload;
|
||||
|
||||
return {
|
||||
...state,
|
||||
hikes,
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
import { createSelector } from 'reselect';
|
||||
|
||||
export const getCurrentHike = createSelector(
|
||||
state => state.hikesApp.hikes.entities,
|
||||
state => state.entities.hike,
|
||||
state => state.hikesApp.currentHike,
|
||||
(hikesMap, currentHikeDashedName) => (hikesMap[currentHikeDashedName] || {})
|
||||
);
|
||||
|
|
|
@ -4,7 +4,7 @@ import _ from 'lodash';
|
|||
const log = debug('fcc:hikes:utils');
|
||||
|
||||
function getFirstHike(hikes) {
|
||||
return hikes.results[0];
|
||||
return hikes[0];
|
||||
}
|
||||
|
||||
// interface Hikes {
|
||||
|
@ -26,7 +26,6 @@ export function findCurrentHike(hikes, dashedName) {
|
|||
const filterRegex = new RegExp(dashedName, 'i');
|
||||
|
||||
return hikes
|
||||
.results
|
||||
.filter(dashedName => {
|
||||
return filterRegex.test(dashedName);
|
||||
})
|
||||
|
@ -43,23 +42,23 @@ export function getCurrentHike(hikes = {}, dashedName) {
|
|||
}
|
||||
|
||||
// findNextHikeName(
|
||||
// hikes: { results: String[] },
|
||||
// hikes: String[],
|
||||
// dashedName: String
|
||||
// ) => String
|
||||
export function findNextHikeName({ results }, dashedName) {
|
||||
export function findNextHikeName(hikes, dashedName) {
|
||||
if (!dashedName) {
|
||||
log('find next hike no id provided');
|
||||
return results[0];
|
||||
log('find next hike no dashedName provided');
|
||||
return hikes[0];
|
||||
}
|
||||
const currentIndex = _.findIndex(
|
||||
results,
|
||||
hikes,
|
||||
_dashedName => _dashedName === dashedName
|
||||
);
|
||||
|
||||
if (currentIndex >= results.length) {
|
||||
if (currentIndex >= hikes.length) {
|
||||
return '';
|
||||
}
|
||||
return results[currentIndex + 1];
|
||||
return hikes[currentIndex + 1];
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -16,12 +16,11 @@ import {
|
|||
} from '../redux/actions';
|
||||
|
||||
const mapStateToProps = createSelector(
|
||||
state => state.jobsApp.jobs.entities,
|
||||
state => state.jobsApp.jobs.results,
|
||||
state => state.jobsApp,
|
||||
(jobsMap, jobsById) => {
|
||||
return { jobs: jobsById.map(id => jobsMap[id]) };
|
||||
}
|
||||
state => state.entities.job,
|
||||
state => state.jobsApp.jobs,
|
||||
(jobsMap, jobsById) => ({
|
||||
jobs: jobsById.map(id => jobsMap[id])
|
||||
})
|
||||
);
|
||||
|
||||
const bindableActions = {
|
||||
|
|
|
@ -60,12 +60,12 @@ function generateMessage(
|
|||
const mapStateToProps = createSelector(
|
||||
state => state.app,
|
||||
state => state.jobsApp.currentJob,
|
||||
state => state.jobsApp.jobs.entities,
|
||||
({ username, isFrontEndCert, isBackEndCert }, currentJob, jobs) => ({
|
||||
state => state.entities.job,
|
||||
({ username, isFrontEndCert, isBackEndCert }, currentJob, jobMap) => ({
|
||||
username,
|
||||
isFrontEndCert,
|
||||
isBackEndCert,
|
||||
job: jobs[currentJob] || {}
|
||||
job: jobMap[currentJob] || {}
|
||||
})
|
||||
);
|
||||
|
||||
|
|
|
@ -5,7 +5,8 @@ import types from './types';
|
|||
export const fetchJobs = createAction(types.fetchJobs);
|
||||
export const fetchJobsCompleted = createAction(
|
||||
types.fetchJobsCompleted,
|
||||
(currentJob, jobs) => ({ currentJob, jobs })
|
||||
(_, currentJob, jobs) => ({ currentJob, jobs }),
|
||||
entities => ({ entities })
|
||||
);
|
||||
|
||||
export const findJob = createAction(types.findJob);
|
||||
|
|
|
@ -32,11 +32,9 @@ export default ({ services }) => ({ dispatch }) => next => {
|
|||
|
||||
|
||||
return fetchJobsCompleted(
|
||||
entities,
|
||||
result.jobs[0],
|
||||
{
|
||||
entities: entities.job,
|
||||
results: result.jobs
|
||||
}
|
||||
result.jobs
|
||||
);
|
||||
})
|
||||
.catch(error => {
|
||||
|
|
|
@ -13,21 +13,15 @@ const initialState = {
|
|||
initialValues: {},
|
||||
currentJob: '',
|
||||
newJob: {},
|
||||
jobs: {
|
||||
entities: {},
|
||||
results: []
|
||||
}
|
||||
jobs: []
|
||||
};
|
||||
|
||||
export default handleActions(
|
||||
{
|
||||
[types.findJob]: (state, { payload: id }) => {
|
||||
const currentJob = state.jobs.entities[id];
|
||||
return {
|
||||
...state,
|
||||
currentJob: currentJob && currentJob.id ?
|
||||
currentJob.id :
|
||||
state.currentJob
|
||||
currentJob: id
|
||||
};
|
||||
},
|
||||
[types.fetchJobsCompleted]: (state, { payload: { jobs, currentJob } }) => ({
|
||||
|
|
Loading…
Reference in New Issue