1
0
mirror of https://github.com/fspc/workstand.git synced 2025-02-23 09:13:23 -05:00

Tidy up reducer.

This commit is contained in:
Drew Larson 2017-03-04 22:06:12 -06:00
parent 8f9d1c3663
commit f702233063
4 changed files with 8 additions and 19 deletions

View File

@ -4,4 +4,3 @@ export const fetchBikes = createAction('fetch bikes');
export const setBikes = createAction('set bikes');
export const setBikesIsFetching = createAction('set bikes.isFetching');
export const setBikesFetched = createAction('set bikes.fetched');
export const setBike = createAction('set bike');

View File

@ -68,7 +68,7 @@ class BikeTableComponent extends React.Component {
render() {
if (this.props.bikes.fetched) {
const bikeRows = renderBikes(Object.values(this.props.bikes.entities['bikes'] || []));
const bikeRows = renderBikes(Object.values(this.props.bikes.entities));
return (
<div className="mdl-grid">
<div className="mdl-cell mdl-cell--12-col">
@ -107,7 +107,7 @@ class BikeTableComponent extends React.Component {
}
const mapStateToProps = state => ({
bikes: state.bikes.bikes,
bikes: state.bikes,
});
const mapDispatchToProps = dispatch => ({

View File

@ -1,27 +1,17 @@
import { setBike, setBikes, setBikesIsFetching, setBikesFetched } from './actions';
import { setBikes, setBikesFetched, setBikesIsFetching } from './actions';
import { handleActions } from 'redux-actions';
export default handleActions({
[setBikes]: (state, action) => ({
...state,
bikes: action.payload,
entities: action.payload.entities.bikes,
}),
[setBikesIsFetching]: (state, action) => ({
...state,
bikes: {
...state.bikes,
isFetching: action.payload,
},
isFetching: action.payload,
}),
[setBikesFetched]: (state, action) => ({
...state,
bikes: {
...state.bikes,
fetched: action.payload
}
fetched: action.payload,
}),
[setBike]: (state, action) => ({
...state,
...action.payload,
}),
}, { bikes: [], bike: undefined });
}, { entities: {}, isFetching: false, fetched: false });

View File

@ -11,7 +11,7 @@ function* fetchBikes(action) {
yield put({ type: setBikesIsFetching.toString(), payload: true });
const bikes = yield call(Api.fetchBikes);
yield put({ type: setBikes.toString(), payload: normalize(bikes, schema.bikes) });
yield put({ type: setBikesFetched, payload: true });
yield put({ type: setBikesFetched.toString(), payload: true });
} catch (e) {
yield put({ type: 'BIKES_FETCH_FAILED', message: e.message });
throw e;