« get me outta code hell

content: listArtistsBy{CommentaryEntries,Name} + syntax changes - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies/listAlbumsByTracks.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-07-03 23:12:03 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-07-03 23:12:03 -0300
commit5408d6660b22b9ddee8c4a297c89fca92ae2d505 (patch)
treefe0bbb257fb1e478806a500d5ef8166085f8bbf7 /src/content/dependencies/listAlbumsByTracks.js
parent4e3cb1d34c8bd68032b736ee3f6cfe0aeb495ee4 (diff)
content: listArtistsBy{CommentaryEntries,Name} + syntax changes
Diffstat (limited to 'src/content/dependencies/listAlbumsByTracks.js')
-rw-r--r--src/content/dependencies/listAlbumsByTracks.js20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/content/dependencies/listAlbumsByTracks.js b/src/content/dependencies/listAlbumsByTracks.js
index acec5da..c31609b 100644
--- a/src/content/dependencies/listAlbumsByTracks.js
+++ b/src/content/dependencies/listAlbumsByTracks.js
@@ -1,4 +1,5 @@
-import {empty, stitchArrays} from '../../util/sugar.js';
+import {stitchArrays} from '../../util/sugar.js';
+import {filterByCount, sortByCount} from '../../util/wiki-data.js';
 
 export default {
   contentDependencies: ['generateListingPage', 'linkAlbum'],
@@ -9,14 +10,13 @@ export default {
   },
 
   query({albumData}, spec) {
-    return {
-      spec,
+    const albums = albumData.slice();
+    const counts = albums.map(album => album.tracks.length);
 
-      albums:
-        albumData
-          .filter(album => !empty(album.tracks))
-          .sort((a, b) => b.tracks.length - a.tracks.length),
-    };
+    filterByCount(albums, counts);
+    sortByCount(albums, counts, {greatestFirst: true});
+
+    return {spec, albums, counts};
   },
 
   relations(relation, query) {
@@ -31,9 +31,7 @@ export default {
 
   data(query) {
     return {
-      counts:
-        query.albums
-          .map(album => album.tracks.length),
+      counts: query.counts,
     };
   },