diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2024-03-07 12:22:29 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2024-06-18 22:56:04 -0300 |
commit | 54c4ee38441766f29b93d78ad6d5b24b9f8f2d2f (patch) | |
tree | d5afa16592934951b772b96e557a068240a6f247 | |
parent | d64a0503bfdd577fb161fc917ac7302e94710e53 (diff) |
sort: sortContributionsChronologically
-rw-r--r-- | src/util/sort.js | 27 |
1 files changed, 27 insertions, 0 deletions
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; +} |