From 54c4ee38441766f29b93d78ad6d5b24b9f8f2d2f Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Thu, 7 Mar 2024 12:22:29 -0400 Subject: sort: sortContributionsChronologically --- src/util/sort.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/util') diff --git a/src/util/sort.js b/src/util/sort.js index 9e9de641..8a096dc1 100644 --- a/src/util/sort.js +++ b/src/util/sort.js @@ -404,3 +404,30 @@ export function sortFlashesChronologically(data, { return data; } + +export function sortContributionsChronologically(data, sortThings, { + latestFirst = false, +} = {}) { + // Contributions only have one date property (which is provided when + // the contribution is created). They're sorted by this most primarily, + // but otherwise use the same sort as is provided. + + const entries = + data.map(contrib => ({ + entry: contrib, + thing: contrib.thing, + })); + + sortEntryThingPairs( + entries, + things => + sortThings(things, {latestFirst})); + + const contribs = + entries + .map(({entry: contrib}) => contrib); + + sortByDate(contribs, {latestFirst}); + + return contribs; +} -- cgit 1.3.0-6-gf8a5