Skip to content

Commit

Permalink
Remove optimistic-ui entry when persistence fails
Browse files Browse the repository at this point in the history
  • Loading branch information
vanderhoop committed Jun 7, 2022
1 parent 124dd34 commit 95b4e00
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test/redux/ideas_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,23 @@ describe("idea reducer", () => {

})

describe("when the action is IDEA_SUBMISSION_REJECTED", () => {
it("removes the idea with an id of Infinity from state", () => {
const initialState = [
{ id: Infinity, body: "body", category: "happy", user_id: 2 },
{ id: 5, body: "who", category: "happy", user_id: 3 },
]

deepFreeze(initialState)

const action = { type: "IDEA_SUBMISSION_REJECTED" }

expect(ideasReducer(initialState, action)).to.deep.equal([
{ id: 5, body: "who", category: "happy", user_id: 3 },
])
})
})

describe("when the action is SET_INITIAL_STATE", () => {
it("should replace the state with the ideas passed in the action's inialState object", () => {
const initialIdeas = [{ body: "i'm an old idea!", category: "happy", user_id: 2 }]
Expand Down
3 changes: 3 additions & 0 deletions web/static/js/redux/ideas.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ export const reducer = (state = [], action) => {
replaceOptimisticallyAddedIdea(state, ideaAttrs) :
[...state, action.idea]
}
case actionTypes.IDEA_SUBMISSION_REJECTED: {
return state.filter(idea => idea.id !== OPTIMISTIC_UI_IDEA_ID)
}
case actionTypes.IDEA_UPDATE_COMMITTED:
return state.map(idea => (
(idea.id === action.ideaId) ? { ...idea, ...action.newAttributes } : idea
Expand Down

0 comments on commit 95b4e00

Please sign in to comment.