« get me outta code hell

sort: sortContributionsChronologically - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
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
commit54c4ee38441766f29b93d78ad6d5b24b9f8f2d2f (patch)
treed5afa16592934951b772b96e557a068240a6f247
parentd64a0503bfdd577fb161fc917ac7302e94710e53 (diff)
sort: sortContributionsChronologically
-rw-r--r--src/util/sort.js27
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;
+}