Skip to content

Commit

Permalink
fix: handle spaces as an immutable set
Browse files Browse the repository at this point in the history
closes #54
  • Loading branch information
juancarlosfarah committed May 27, 2019
1 parent f4c8b7e commit 2d2b003
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 27 deletions.
27 changes: 16 additions & 11 deletions src/Home.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes';
import { withRouter } from 'react-router';
import classNames from 'classnames';
import { withStyles } from '@material-ui/core/styles';
Expand All @@ -24,6 +25,21 @@ class Home extends Component {
open: false,
};

static propTypes = {
classes: PropTypes.shape({ appBar: PropTypes.string.isRequired })
.isRequired,
theme: PropTypes.shape({ direction: PropTypes.string }).isRequired,
dispatchGetSpaces: PropTypes.func.isRequired,
spaces: ImmutablePropTypes.setOf(
PropTypes.shape({
id: PropTypes.string.isRequired,
})
).isRequired,
activity: PropTypes.bool.isRequired,
history: PropTypes.shape({ length: PropTypes.number.isRequired })
.isRequired,
};

componentDidMount() {
const { dispatchGetSpaces } = this.props;
dispatchGetSpaces();
Expand Down Expand Up @@ -116,17 +132,6 @@ const mapDispatchToProps = {
dispatchGetSpaces: getSpaces,
};

Home.propTypes = {
classes: PropTypes.shape({ appBar: PropTypes.string.isRequired }).isRequired,
theme: PropTypes.shape({ direction: PropTypes.string }).isRequired,
dispatchGetSpaces: PropTypes.func.isRequired,
spaces: PropTypes.arrayOf(
PropTypes.shape({ id: PropTypes.string.isRequired })
).isRequired,
activity: PropTypes.bool.isRequired,
history: PropTypes.shape({ length: PropTypes.number.isRequired }).isRequired,
};

export default withRouter(
withStyles(Styles, { withTheme: true })(
connect(
Expand Down
8 changes: 6 additions & 2 deletions src/components/space/SpaceGrid.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { Set } from 'immutable';
import ImmutablePropTypes from 'react-immutable-proptypes';
import RemoveRedEyeIcon from '@material-ui/icons/RemoveRedEye';
import Button from '@material-ui/core/Button/Button';
import { withStyles } from '@material-ui/core';
Expand All @@ -24,7 +24,11 @@ class SpaceGrid extends Component {
classes: PropTypes.shape({
leftIcon: PropTypes.string.isRequired,
}).isRequired,
spaces: PropTypes.instanceOf(Set).isRequired,
spaces: ImmutablePropTypes.setOf(
PropTypes.shape({
id: PropTypes.string.isRequired,
})
).isRequired,
history: PropTypes.shape({ length: PropTypes.number.isRequired })
.isRequired,
dispatchClearSpace: PropTypes.func.isRequired,
Expand Down
28 changes: 14 additions & 14 deletions src/reducers/SpaceReducer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Immutable from 'immutable';
import { Set, Map } from 'immutable';
import {
GET_SPACE,
TOGGLE_SPACE_MENU,
Expand All @@ -17,19 +17,19 @@ import {
GET_SPACES_NEARBY_SUCCEEDED,
} from '../types';

const INITIAL_STATE = Immutable.Map({
current: Immutable.Map({
content: Immutable.Map(),
const INITIAL_STATE = Map({
current: Map({
content: Map(),
activity: false,
error: null,
menu: Immutable.Map({
menu: Map({
open: false,
}),
deleted: false,
}),
saved: Immutable.Set(),
nearby: Immutable.Map({
content: Immutable.Set(),
saved: Set(),
nearby: Map({
content: Set(),
activity: false,
}),
});
Expand All @@ -39,7 +39,7 @@ export default (state = INITIAL_STATE, { type, payload }) => {
case CLEAR_SPACE:
// set content to empty map
return state
.setIn(['current', 'content'], Immutable.Map())
.setIn(['current', 'content'], Map())
.setIn(['current', 'deleted'], false);
case FLAG_SAVING_SPACE:
return state.setIn(['current', 'activity'], payload);
Expand All @@ -56,19 +56,19 @@ export default (state = INITIAL_STATE, { type, payload }) => {
case DELETE_SPACE_SUCCESS:
return state.setIn(['current', 'deleted'], payload);
case GET_SPACES:
return state.setIn(['saved'], payload);
return state.setIn(['saved'], Set(payload));
case GET_SPACE:
return state.setIn(['current', 'content'], Immutable.Map(payload));
return state.setIn(['current', 'content'], Map(payload));
case TOGGLE_SPACE_MENU:
return state.setIn(['current', 'menu', 'open'], payload);
case GET_SPACE_SUCCEEDED:
return state.setIn(['current', 'content'], Immutable.Map(payload));
return state.setIn(['current', 'content'], Map(payload));
case SAVE_SPACE_SUCCEEDED:
return state.setIn(['current', 'content'], Immutable.Map(payload));
return state.setIn(['current', 'content'], Map(payload));
case FLAG_GETTING_SPACES_NEARBY:
return state.setIn(['nearby', 'activity'], payload);
case GET_SPACES_NEARBY_SUCCEEDED:
return state.setIn(['nearby', 'content'], payload);
return state.setIn(['nearby', 'content'], Set(payload));
default:
return state;
}
Expand Down

0 comments on commit 2d2b003

Please sign in to comment.