diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2023-01-04 20:58:46 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2023-01-04 20:58:46 -0400 |
commit | 0698f5ec7bff107b5fd3881fda45a023dc6e8737 (patch) | |
tree | 064449c06aa35dc7f9796675ec6d19e6d1c6c554 /src/data/things/album.js | |
parent | d4b5120dfd4af3bc1c6eb94f2b1859a189f7079c (diff) |
trackGroups -> trackSections
Diffstat (limited to 'src/data/things/album.js')
-rw-r--r-- | src/data/things/album.js | 113 |
1 files changed, 39 insertions, 74 deletions
diff --git a/src/data/things/album.js b/src/data/things/album.js index ade34e3d..0c0c7fb4 100644 --- a/src/data/things/album.js +++ b/src/data/things/album.js @@ -10,13 +10,11 @@ export class Album extends Thing { Artist, Group, Track, - TrackGroup, validators: { isDate, isDimensions, - validateArrayItems, - validateInstanceOf, + isTrackSectionList, }, }) => ({ // Update & expose @@ -56,11 +54,39 @@ export class Album extends Thing { groupsByRef: Thing.common.referenceList(Group), artTagsByRef: Thing.common.referenceList(ArtTag), - trackGroups: { + trackSections: { flags: {update: true, expose: true}, update: { - validate: validateArrayItems(validateInstanceOf(TrackGroup)), + validate: isTrackSectionList, + }, + + expose: { + dependencies: ['color', 'trackData'], + transform(trackSections, { + color: albumColor, + trackData, + }) { + let startIndex = 0; + return trackSections?.map(section => ({ + name: section.name ?? null, + color: section.color ?? albumColor ?? null, + dateOriginallyReleased: section.dateOriginallyReleased ?? null, + isDefaultTrackSection: section.isDefaultTrackSection ?? false, + + startIndex: ( + startIndex += section.tracksByRef.length, + startIndex - section.tracksByRef.length + ), + + tracksByRef: section.tracksByRef ?? [], + tracks: + (trackData && section.tracksByRef + ?.map(ref => find.track(ref, trackData, {mode: 'quiet'})) + .filter(Boolean)) ?? + [], + })); + }, }, }, @@ -114,11 +140,11 @@ export class Album extends Thing { flags: {expose: true}, expose: { - dependencies: ['trackGroups', 'trackData'], - compute: ({trackGroups, trackData}) => - trackGroups && trackData - ? trackGroups - .flatMap((group) => group.tracksByRef ?? []) + dependencies: ['trackSections', 'trackData'], + compute: ({trackSections, trackData}) => + trackSections && trackData + ? trackSections + .flatMap((section) => section.tracksByRef ?? []) .map((ref) => find.track(ref, trackData, {mode: 'quiet'})) .filter(Boolean) : [], @@ -179,72 +205,11 @@ export class Album extends Thing { }); } -export class TrackGroup extends Thing { - static [Thing.getPropertyDescriptors] = ({ - isColor, - Track, - - validators: { - validateInstanceOf, - }, - }) => ({ - // Update & expose - +export class TrackSectionHelper extends Thing { + static [Thing.getPropertyDescriptors] = () => ({ name: Thing.common.name('Unnamed Track Group'), - - color: { - flags: {update: true, expose: true}, - - update: {validate: isColor}, - - expose: { - dependencies: ['album'], - - transform(color, {album}) { - return color ?? album?.color ?? null; - }, - }, - }, - + color: Thing.common.color(), dateOriginallyReleased: Thing.common.simpleDate(), - - tracksByRef: Thing.common.referenceList(Track), - isDefaultTrackGroup: Thing.common.flag(false), - - // Update only - - album: { - flags: {update: true}, - update: {validate: validateInstanceOf(Album)}, - }, - - trackData: Thing.common.wikiData(Track), - - // Expose only - - tracks: { - flags: {expose: true}, - - expose: { - dependencies: ['tracksByRef', 'trackData'], - compute: ({tracksByRef, trackData}) => - tracksByRef && trackData - ? tracksByRef.map((ref) => find.track(ref, trackData)).filter(Boolean) - : [], - }, - }, - - startIndex: { - flags: {expose: true}, - - expose: { - dependencies: ['album'], - compute: ({album, [TrackGroup.instance]: trackGroup}) => - album.trackGroups - .slice(0, album.trackGroups.indexOf(trackGroup)) - .reduce((acc, tg) => acc + tg.tracks.length, 0), - }, - }, }) } |