Skip to content

Commit

Permalink
fix: does not save action and resource when space is not saved
Browse files Browse the repository at this point in the history
closes #296
  • Loading branch information
pyphilia committed Aug 4, 2020
1 parent 92fa3d8 commit 0b5bb5d
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/components/phase/PhaseApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class PhaseApp extends Component {
}),
user: PropTypes.instanceOf(Map).isRequired,
actionsEnabled: PropTypes.bool.isRequired,
isSpaceSaved: PropTypes.bool,
};

static defaultProps = {
Expand All @@ -70,6 +71,7 @@ class PhaseApp extends Component {
name: 'Image',
lang: DEFAULT_LANGUAGE,
userId: null,
isSpaceSaved: false,
};

state = {
Expand Down Expand Up @@ -116,6 +118,7 @@ class PhaseApp extends Component {
appInstance,
dispatchPostAction,
user,
isSpaceSaved,
} = this.props;

// get app instance id in message
Expand All @@ -127,18 +130,28 @@ class PhaseApp extends Component {
}

// only receive message from intended app instance
// save data if space is saved
if (componentAppInstanceId === messageAppInstanceId) {
switch (type) {
case GET_APP_INSTANCE:
return dispatchGetAppInstance(payload, this.postMessage);
case GET_APP_INSTANCE_RESOURCES:
return getAppInstanceResources(payload, this.postMessage);
case POST_APP_INSTANCE_RESOURCE:
return postAppInstanceResource(payload, this.postMessage);
if (isSpaceSaved) {
return postAppInstanceResource(payload, this.postMessage);
}
break;
case PATCH_APP_INSTANCE_RESOURCE:
return patchAppInstanceResource(payload, this.postMessage);
case GET_APP_INSTANCE:
return dispatchGetAppInstance(payload, this.postMessage);
if (isSpaceSaved) {
return patchAppInstanceResource(payload, this.postMessage);
}
break;
case POST_ACTION: {
return dispatchPostAction(payload, user, this.postMessage);
if (isSpaceSaved) {
return dispatchPostAction(payload, user, this.postMessage);
}
break;
}
default:
return false;
Expand Down Expand Up @@ -305,6 +318,7 @@ const mapStateToProps = ({ authentication, Space }) => ({
userId: authentication.getIn(['user', 'id']),
user: authentication.getIn(['user']),
actionsEnabled: authentication.getIn(['user', 'settings', 'actionsEnabled']),
isSpaceSaved: Space.getIn(['current', 'content', 'saved']),
});

const mapDispatchToProps = {
Expand Down

0 comments on commit 0b5bb5d

Please sign in to comment.