From b8f83ae399daa72293170f2ea12bf8bdcdf8fbe1 Mon Sep 17 00:00:00 2001 From: Drew Weymouth Date: Tue, 24 Jun 2025 08:33:40 -0700 Subject: [PATCH] Fix #646: Sort artist discography by full date --- backend/mediaprovider/model.go | 20 ++++++++++++++++++++ ui/browsing/artistpage.go | 4 ++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/backend/mediaprovider/model.go b/backend/mediaprovider/model.go index e10f257..8a4e659 100644 --- a/backend/mediaprovider/model.go +++ b/backend/mediaprovider/model.go @@ -38,6 +38,26 @@ type ItemDate struct { Day *int } +func (i ItemDate) After(other ItemDate) bool { + a := []*int{i.Year, i.Month, i.Day} + b := []*int{other.Year, other.Month, other.Day} + for i := range a { + if a[i] == nil { + return false + } + if b[i] == nil { + return true + } + if *a[i] < *b[i] { + return false + } + if *a[i] > *b[i] { + return true + } + } + return false +} + type Album struct { ID string CoverArtID string diff --git a/ui/browsing/artistpage.go b/ui/browsing/artistpage.go index 5c827c6..b5b95c1 100644 --- a/ui/browsing/artistpage.go +++ b/ui/browsing/artistpage.go @@ -195,12 +195,12 @@ func (a *ArtistPage) getGridViewAlbumsModel() []widgets.GridViewItemModel { return nil } sortFunc := func(x, y int) bool { - return a.artistInfo.Albums[x].YearOrZero() < a.artistInfo.Albums[y].YearOrZero() + return a.artistInfo.Albums[y].Date.After(a.artistInfo.Albums[x].Date) } switch a.cfg.DiscographySort { case discographySorts[1]: /*year descending*/ sortFunc = func(x, y int) bool { - return a.artistInfo.Albums[x].YearOrZero() > a.artistInfo.Albums[y].YearOrZero() + return a.artistInfo.Albums[x].Date.After(a.artistInfo.Albums[y].Date) } case discographySorts[2]: /*name*/ sortFunc = func(x, y int) bool {