From 4136d9d53191be9e5bba72f70364fe0155c7593d Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Mon, 13 Jun 2022 22:36:36 -0300 Subject: detect what's an album without constructor refs This is kind of a hack but it totally works and gets client-side code to run again. http-music and mtui are filled to the brim with this kind of check and it's one of many reasons they need some serious reworking before i make a threequel lol --- src/util/wiki-data.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/util/wiki-data.js b/src/util/wiki-data.js index aba508c5..5aef812d 100644 --- a/src/util/wiki-data.js +++ b/src/util/wiki-data.js @@ -1,7 +1,5 @@ // Utility functions for interacting with wiki data. -import { Album, Track } from '../data/things.js'; - // Generic value operations export function getKebabCase(name) { @@ -216,12 +214,13 @@ export function sortByPositionInAlbum(data) { }); } -// Note that this function only checks constructor equality, not inheritence! -// So it won't group subclasses together (as though they were the same type). -export function sortByThingType(data, thingConstructors) { +// Sorts data so that items are grouped together according to whichever of a +// set of arbitrary given conditions is true first. If no conditions are met +// for a given item, it's moved over to the end! +export function sortByConditions(data, conditions) { data.sort((a, b) => { - const ai = thingConstructors.indexOf(a.constructor); - const bi = thingConstructors.indexOf(b.constructor); + const ai = conditions.findIndex(f => f(a)); + const bi = conditions.findIndex(f => f(b)); if (ai >= 0 && bi >= 0) { return ai - bi; @@ -276,7 +275,7 @@ export function sortChronologically(data, {getDirectory, getName, getDate} = {}) // This function also works for data lists which contain only tracks. export function sortAlbumsTracksChronologically(data, {getDate} = {}) { // Sort albums before tracks... - sortByThingType(data, [Album, Track]); + sortByConditions(data, [t => t.album === undefined]); // Group tracks by album... sortByDirectory(data, { -- cgit 1.3.0-6-gf8a5