Skip to content

Commit

Permalink
fix(feeds): handle missing project when fetching project's feed sources
Browse files Browse the repository at this point in the history
  • Loading branch information
landonreed committed Aug 21, 2018
1 parent aeb46f8 commit 68735d5
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions lib/manager/reducers/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,25 +153,27 @@ const projects = (state: ProjectsState = defaultState, action: any): ProjectsSta
})
}
case 'RECEIVE_FEEDSOURCES': {
const projectIndex = state.all.findIndex(p => p.id === action.payload.projectId)
const {feedSources, projectId} = action.payload
const projectIndex = state.all.findIndex(p => p.id === projectId)
if (projectIndex === -1) {
console.warn(`Project ID ${projectId} not found in state`)
return state
}
const currentFeedSources = state.all[projectIndex].feedSources
let sourceIndex, feeds
if (
state.all[projectIndex] &&
state.all[projectIndex].feedSources &&
state.all[projectIndex].feedSources.length === 1
) {
if (currentFeedSources && currentFeedSources.length === 1) {
// If lazy fetching the rest of the feed sources, don't overwrite current
// feed source.
sourceIndex = action.payload.feedSources
.findIndex(fs => fs.id === state.all[projectIndex].feedSources[0].id)
sourceIndex = feedSources
.findIndex(fs => fs.id === currentFeedSources[0].id)
if (sourceIndex === -1) {
// There is no feed source to overwrite (none is loaded or none exist).
feeds = action.payload.feedSources
feeds = feedSources
} else {
action.payload.feedSources.splice(sourceIndex, 1)
feedSources.splice(sourceIndex, 1)
feeds = [
...state.all[projectIndex].feedSources,
...action.payload.feedSources
...currentFeedSources,
...feedSources
]
}
} else {
Expand Down

0 comments on commit 68735d5

Please # to comment.