Skip to content

Commit

Permalink
Merge pull request #3032 from metabrainz/LB-1660
Browse files Browse the repository at this point in the history
LB-1660: Sort by listen count on artist pages doesn't properly sort
  • Loading branch information
anshg1214 authored Nov 13, 2024
2 parents 3f74261 + 5b778d1 commit bcad255
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions frontend/js/src/artist/ArtistPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,15 @@ function SortingButtons({
);
}

interface ReleaseGroupWithSecondaryTypes extends ReleaseGroup {
interface ReleaseGroupWithSecondaryTypesAndListenCount extends ReleaseGroup {
secondary_types: string[];
total_listen_count: number | null;
}

export type ArtistPageProps = {
popularRecordings: PopularRecording[];
artist: MusicBrainzArtist;
releaseGroups: ReleaseGroupWithSecondaryTypes[];
releaseGroups: ReleaseGroupWithSecondaryTypesAndListenCount[];
similarArtists: {
artists: SimilarArtist[];
topReleaseGroupColor: ReleaseColor | undefined;
Expand Down Expand Up @@ -139,13 +140,17 @@ export default function ArtistPage(): JSX.Element {
);

const sortReleaseGroups = (
releaseGroupsInput: ReleaseGroupWithSecondaryTypes[]
releaseGroupsInput: ReleaseGroupWithSecondaryTypesAndListenCount[]
) =>
orderBy(
releaseGroupsInput,
[
sort === "release_date" ? (rg) => rg.date || "" : "total_listen_count",
sort === "release_date" ? "total_listen_count" : (rg) => rg.date || "",
sort === "release_date"
? (rg) => rg.date || ""
: (rg) => rg.total_listen_count ?? 0,
sort === "release_date"
? (rg) => rg.total_listen_count ?? 0
: (rg) => rg.date || "",
"name",
],
["desc", "desc", "asc"]
Expand All @@ -167,7 +172,7 @@ export default function ArtistPage(): JSX.Element {

const groupedReleaseGroups: Record<
string,
ReleaseGroupWithSecondaryTypes[]
ReleaseGroupWithSecondaryTypesAndListenCount[]
> = {};
sortedRgGroupsKeys.forEach((type) => {
groupedReleaseGroups[type] = sortReleaseGroups(rgGroups[type]);
Expand Down

0 comments on commit bcad255

Please sign in to comment.