Skip to content

Commit bf102c4

Browse files
committed
content: listArtistsByGroup: count contributions in each group
Also disable the fallback behavior when divideTrackListsByGroups is empty, because what's the use of this listing at all, at that point...?
1 parent f151e42 commit bf102c4

File tree

2 files changed

+77
-77
lines changed

2 files changed

+77
-77
lines changed
+76-76
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import {sortAlphabetically} from '#sort';
2-
import {empty, filterMultipleArrays, stitchArrays, unique} from '#sugar';
3-
import {getArtistNumContributions} from '#wiki-data';
2+
import {
3+
empty,
4+
filterByCount,
5+
filterMultipleArrays,
6+
stitchArrays,
7+
transposeArrays,
8+
} from '#sugar';
49

510
export default {
611
contentDependencies: ['generateListingPage', 'linkArtist', 'linkGroup'],
@@ -15,29 +20,52 @@ export default {
1520
sortAlphabetically(
1621
sprawl.artistData.filter(artist => !artist.isAlias));
1722

18-
const groups =
23+
const interestingGroups =
1924
sprawl.wikiInfo.divideTrackListsByGroups;
2025

21-
if (empty(groups)) {
22-
return {spec, artists};
26+
if (empty(interestingGroups)) {
27+
return {spec};
2328
}
2429

25-
const artistGroups =
30+
// We don't actually care about *which* things belong to each group, only
31+
// how many belong to each group. So we'll just compute a list of all the
32+
// (interesting) groups that each of each artists' things belongs to.
33+
const artistThingGroups =
2634
artists.map(artist =>
27-
unique(
28-
unique([
29-
...artist.albumsAsAny,
30-
...artist.tracksAsAny.map(track => track.album),
31-
]).flatMap(album => album.groups)))
32-
33-
const artistsByGroup =
34-
groups.map(group =>
35-
artists.filter((artist, index) => artistGroups[index].includes(group)));
36-
37-
filterMultipleArrays(groups, artistsByGroup,
38-
(group, artists) => !empty(artists));
39-
40-
return {spec, groups, artistsByGroup};
35+
([...artist.albumsAsAny.map(album => album.groups),
36+
...artist.tracksAsAny.map(track => track.album.groups)])
37+
.map(groups => groups
38+
.filter(group => interestingGroups.includes(group))));
39+
40+
const [artistsByGroup, countsByGroup] =
41+
transposeArrays(interestingGroups.map(group => {
42+
const counts =
43+
artistThingGroups
44+
.map(thingGroups => thingGroups
45+
.filter(thingGroups => thingGroups.includes(group))
46+
.length);
47+
48+
const filteredArtists = artists.slice();
49+
50+
filterByCount(filteredArtists, counts);
51+
52+
return [filteredArtists, counts];
53+
}));
54+
55+
const groups = interestingGroups;
56+
57+
filterMultipleArrays(
58+
groups,
59+
artistsByGroup,
60+
countsByGroup,
61+
(_group, artists, _counts) => !empty(artists));
62+
63+
return {
64+
spec,
65+
groups,
66+
artistsByGroup,
67+
countsByGroup,
68+
};
4169
},
4270

4371
relations(relation, query) {
@@ -46,12 +74,6 @@ export default {
4674
relations.page =
4775
relation('generateListingPage', query.spec);
4876

49-
if (query.artists) {
50-
relations.artistLinks =
51-
query.artists
52-
.map(artist => relation('linkArtist', artist));
53-
}
54-
5577
if (query.artistsByGroup) {
5678
relations.groupLinks =
5779
query.groups
@@ -69,65 +91,43 @@ export default {
6991
data(query) {
7092
const data = {};
7193

72-
if (query.artists) {
73-
data.counts =
74-
query.artists
75-
.map(artist => getArtistNumContributions(artist));
76-
}
77-
7894
if (query.artistsByGroup) {
7995
data.groupDirectories =
8096
query.groups
8197
.map(group => group.directory);
8298

8399
data.countsByGroup =
84-
query.artistsByGroup
85-
.map(artists => artists
86-
.map(artist => getArtistNumContributions(artist)));
100+
query.countsByGroup;
87101
}
88102

89103
return data;
90104
},
91105

92-
generate(data, relations, {language}) {
93-
return (
94-
(relations.artistLinksByGroup
95-
? relations.page.slots({
96-
type: 'chunks',
97-
98-
showSkipToSection: true,
99-
chunkIDs:
100-
data.groupDirectories
101-
.map(directory => `contributed-to-${directory}`),
102-
103-
chunkTitles:
104-
relations.groupLinks.map(groupLink => ({
105-
group: groupLink,
106-
})),
107-
108-
chunkRows:
109-
stitchArrays({
110-
artistLinks: relations.artistLinksByGroup,
111-
counts: data.countsByGroup,
112-
}).map(({artistLinks, counts}) =>
113-
stitchArrays({
114-
link: artistLinks,
115-
count: counts,
116-
}).map(({link, count}) => ({
117-
artist: link,
118-
contributions: language.countContributions(count, {unit: true}),
119-
}))),
120-
})
121-
: relations.page.slots({
122-
type: 'rows',
123-
rows:
124-
stitchArrays({
125-
link: relations.artistLinks,
126-
count: data.counts,
127-
}).map(({link, count}) => ({
128-
artist: link,
129-
contributions: language.countContributions(count, {unit: true}),
130-
})),
131-
})));
132-
},
106+
generate: (data, relations, {language}) =>
107+
relations.page.slots({
108+
type: 'chunks',
109+
110+
showSkipToSection: true,
111+
chunkIDs:
112+
data.groupDirectories
113+
.map(directory => `contributed-to-${directory}`),
114+
115+
chunkTitles:
116+
relations.groupLinks.map(groupLink => ({
117+
group: groupLink,
118+
})),
119+
120+
chunkRows:
121+
stitchArrays({
122+
artistLinks: relations.artistLinksByGroup,
123+
counts: data.countsByGroup,
124+
}).map(({artistLinks, counts}) =>
125+
stitchArrays({
126+
link: artistLinks,
127+
count: counts,
128+
}).map(({link, count}) => ({
129+
artist: link,
130+
contributions: language.countContributions(count, {unit: true}),
131+
}))),
132+
}),
133133
};

src/listing-spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ listingSpec.push({
6767
contentFunction: 'listArtistsByDuration',
6868
});
6969

70-
// TODO: hide if no groups...
70+
// TODO: hide if divideTrackListsByGroups empty...
7171
listingSpec.push({
7272
directory: 'artists/by-group',
7373
stringsKey: 'listArtists.byGroup',

0 commit comments

Comments
 (0)