Skip to content

Commit 8b0f290

Browse files
author
vikasrohit
authored
Merge pull request #790 from maxceem/issue-774
#774 - fix: update challenge in the list after editing
2 parents f333c00 + 117e86a commit 8b0f290

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/reducers/challenges.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,20 @@ export default function (state = initialState, action) {
8585
return { ...state, isLoading: false, attachments: [], challenge: null, failedToLoad: true }
8686
case LOAD_CHALLENGE_DETAILS_SUCCESS:
8787
case UPDATE_CHALLENGE_DETAILS_SUCCESS:
88+
let updatedChallenges = state.challenges
89+
// when updating challenge details, make the same update in the challenge list
90+
if (action.type === UPDATE_CHALLENGE_DETAILS_SUCCESS) {
91+
const updatedChallengeIndex = _.findIndex(state.challenges, { id: action.challengeDetails.id })
92+
updatedChallenges = [
93+
...state.challenges.slice(0, updatedChallengeIndex),
94+
action.challengeDetails,
95+
...state.challenges.slice(updatedChallengeIndex + 1)
96+
]
97+
}
98+
8899
return {
89100
...state,
101+
challenges: updatedChallenges,
90102
challengeDetails: action.challengeDetails,
91103
isLoading: false,
92104
attachments: _.has(action.challengeDetails, 'attachments') ? action.challengeDetails.attachments : [],

src/services/challenges.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,11 @@ export function fetchChallenges (filters, params) {
138138
...filters,
139139
...params
140140
}
141-
return axiosInstance.get(`${CHALLENGE_API_URL}?${qs.stringify(query, { encode: false })}`)
141+
return axiosInstance.get(`${CHALLENGE_API_URL}?${qs.stringify(query, { encode: false })}`).then(response => {
142+
// normalize challenge data in the list of challenges for consistency with data of a single challenge details page
143+
response.data = response.data.map(normalizeChallengeDataFromAPI)
144+
return response
145+
})
142146
}
143147

144148
/**

0 commit comments

Comments
 (0)