Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/lib/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ function fetchChatReportsByIDs(chatList) {
// Merge the data into Ion
Ion.merge(`${IONKEYS.COLLECTION.REPORT}${report.reportID}`, newReport);
});
return {reports: _.indexBy(fetchedReports, 'reportID')};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think maybe fetchedReports is already an object indexed by reportID.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, maybe

});
}

Expand Down Expand Up @@ -290,14 +291,19 @@ function fetchAll(shouldRedirectToFirstReport = true, shouldFetchActions = false

promiseAllSettled(reportFetchPromises)
.then((data) => {
fetchedReports = _.compact(_.map(data, (promiseResult) => {
fetchedReports = _.compact(_.reduce(data, (finalArray, promiseResult) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably don't need compact if we're changing this to reduce

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point

// Grab the report from the promise result which stores it in the `value` key
const report = lodashGet(promiseResult, 'value.reports', {});
const reports = lodashGet(promiseResult, 'value.reports', {});

// If there is no report found from the promise, return null
// Otherwise, grab the actual report object from the first index in the values array
return _.isEmpty(report) ? null : _.values(report)[0];
}));
// If there are no reports found from the promise, stop early
if (_.isEmpty(reports)) {
return finalArray;
}

_.each(_.values(reports), report => finalArray.push(report));

return finalArray;
}, []));

// Set the first report ID so that the logged in person can be redirected there
// if they are on the home page
Expand Down