Skip to content

Commit

Permalink
Sort by disasterDare, then submissionTime
Browse files Browse the repository at this point in the history
  • Loading branch information
ericboucher committed Oct 23, 2024
1 parent 451c8f5 commit eca9fb2
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions apps/frontend/utils/formatRawToForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,18 @@ export const filterFloodReports = (
return reports[0];
}

// Sort by submission time and return the latest report
return reports.sort(
(a, b) =>
dayjs(b.disasterDate).valueOf() - dayjs(a.disasterDate).valueOf(),
)[0];
// Sort by disasterDate first, then by submissionTime, and return the first report
return reports.sort((a, b) => {
const disasterDateDiff =
dayjs(b.disasterDate).valueOf() - dayjs(a.disasterDate).valueOf();
if (disasterDateDiff !== 0) {
return disasterDateDiff;
}

// If disasterDate is the same, sort by submissionTime
return (
dayjs(b.submissionTime).valueOf() - dayjs(a.submissionTime).valueOf()
);
})[0];
});
};

0 comments on commit eca9fb2

Please sign in to comment.