Skip to content

Commit

Permalink
[SDESK-3157] Autosave error during spike
Browse files Browse the repository at this point in the history
style fix

review changes
  • Loading branch information
nrvikas committed Aug 24, 2018
1 parent c5842b7 commit 70cc985
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
19 changes: 11 additions & 8 deletions client/actions/autosave.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,7 @@ const remove = (autosave) => (
return Promise.resolve(autosave);
}
// Delete the changes from the local redux
dispatch({
type: AUTOSAVE.ACTIONS.REMOVE,
payload: autosave,
});
dispatch(self.removeLocalAutosave(autosave));

// If the Autosave item does not have an etag
// then it has not been saved to the server yet.
Expand Down Expand Up @@ -216,16 +213,21 @@ const removeById = (itemType, itemId, tryServer = true) => (
}

// ensure that autosave is removed from redux
dispatch({
type: AUTOSAVE.ACTIONS.REMOVE,
payload: {_id: itemId, type: itemType},
});
dispatch(self.removeLocalAutosave({
_id: itemId,
type: itemType,
}));

return Promise.resolve();
})
)
);

const removeLocalAutosave = (item) => ({
type: AUTOSAVE.ACTIONS.REMOVE,
payload: item,
});

// eslint-disable-next-line consistent-this
const self = {
save,
Expand All @@ -237,6 +239,7 @@ const self = {
fetchPlanning,
fetchAll,
fetchById,
removeLocalAutosave,
};

export default self;
20 changes: 15 additions & 5 deletions client/actions/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
POST_STATE,
PLANNING,
EVENTS,
AUTOSAVE,
AGENDA,
QUEUE_ITEM_PREFIX,
} from '../constants';
Expand Down Expand Up @@ -601,6 +600,20 @@ const closePreviewAndEditorForItems = (items, actionMessage = '', field = '_id')
}
}


items.forEach((item) => {
const itemType = (get(item, field) in selectors.planning.storedPlannings(getState())) ?
ITEM_TYPE.PLANNING : ITEM_TYPE.EVENT;
const autoSaves = selectors.forms.autosaves(getState());

if (getAutosaveItem(autoSaves, itemType, item[field])) {
dispatch(autosave.removeLocalAutosave({
_id: item[field],
type: itemType,
}));
}
});

return Promise.resolve();
}
);
Expand Down Expand Up @@ -1223,10 +1236,7 @@ const onItemUnlocked = (data, item, itemType) => (

if (autoSaveInStore) {
// Delete the changes from the local redux
dispatch({
type: AUTOSAVE.ACTIONS.REMOVE,
payload: autoSaveInStore,
});
dispatch(autosave.removeLocalAutosave(autoSaveInStore));
}

if (modalType !== MODALS.ADD_TO_PLANNING) {
Expand Down

0 comments on commit 70cc985

Please sign in to comment.