Skip to content

Commit

Permalink
fix: do not fetch from api if space is saved
Browse files Browse the repository at this point in the history
closes #95
  • Loading branch information
juancarlosfarah committed Jun 14, 2019
1 parent be10b87 commit 3778518
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class Home extends Component {
})}
>
<div className={classes.drawerHeader} />
<SpaceGrid spaces={spaces} />
<SpaceGrid spaces={spaces} saved />
</main>
</div>
);
Expand Down
5 changes: 3 additions & 2 deletions src/actions/space.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,9 @@ const loadSpace = ({ fileLocation }) => dispatch => {
});
};

const getSpace = ({ id }) => dispatch => {
if (window.navigator.onLine) {
const getSpace = ({ id, saved = false }) => dispatch => {
// only get the space from the api if not saved
if (!saved) {
dispatch(getRemoteSpace({ id }));
} else {
dispatch(getLocalSpace({ id }));
Expand Down
2 changes: 2 additions & 0 deletions src/components/phase/Phase.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Phase extends Component {
render() {
const { phase, space, dispatchSelectPhase, start } = this.props;
const phases = space.get('phases');
const saved = space.get('saved');
const lang = space.get('language');
const description = space.get('description');
if (!phase || phase.isEmpty()) {
Expand All @@ -47,6 +48,7 @@ class Phase extends Component {
selectPhase={dispatchSelectPhase}
start={start}
lang={lang}
saved={saved}
/>
);
}
Expand Down
8 changes: 5 additions & 3 deletions src/components/space/SpaceGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ class SpaceGrid extends Component {
history: PropTypes.shape({ length: PropTypes.number.isRequired })
.isRequired,
dispatchClearSpace: PropTypes.func.isRequired,
saved: PropTypes.bool,
};

static defaultProps = {
folder: null,
saved: false,
};

componentDidMount() {
Expand Down Expand Up @@ -78,7 +80,7 @@ class SpaceGrid extends Component {
};

render() {
const { spaces, classes, history } = this.props;
const { spaces, classes, history, saved } = this.props;

// spaces is a set to mapping through it will return a set
const MediaCards = spaces.map(space => {
Expand All @@ -90,7 +92,7 @@ class SpaceGrid extends Component {
size="large"
color="primary"
id={id}
onClick={() => replace(`/space/${id}`)}
onClick={() => replace(`/space/${id}?saved=${saved}`)}
fullWidth
>
<RemoveRedEyeIcon className={classes.leftIcon} />
Expand Down Expand Up @@ -118,7 +120,7 @@ class SpaceGrid extends Component {
);
}
return (
<Grid container spacing={16}>
<Grid container spacing={6}>
{MediaCards}
</Grid>
);
Expand Down
12 changes: 10 additions & 2 deletions src/components/space/SpaceScreen.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { Component } from 'react';
import Qs from 'qs';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes';
Expand Down Expand Up @@ -57,6 +58,9 @@ class SpaceScreen extends Component {
id: PropTypes.string.isRequired,
}),
}).isRequired,
location: PropTypes.shape({
search: PropTypes.string.isRequired,
}).isRequired,
history: PropTypes.shape({ length: PropTypes.number.isRequired })
.isRequired,
};
Expand All @@ -66,9 +70,13 @@ class SpaceScreen extends Component {
match: {
params: { id },
},
location: { search },
dispatchGetSpace,
} = this.props;
dispatchGetSpace({ id });

// tell action creator if this space has already been saved
const { saved } = Qs.parse(search, { ignoreQueryPrefix: true });
dispatchGetSpace({ id, saved: saved === 'true' });
}

componentDidUpdate() {
Expand Down Expand Up @@ -137,7 +145,7 @@ class SpaceScreen extends Component {
const phases = space.get('phases') || [];
// const description = space.get('description');
return (
<div className={classes.root} style={{ height: '100%' }}>
<div className={classes.root}>
<CssBaseline />
<SpaceHeader
handleDrawerOpen={this.handleDrawerOpen}
Expand Down

0 comments on commit 3778518

Please sign in to comment.