Fix news sidebar assuming returned posts are always from given year

This commit is contained in:
Bartłomiej Dach 2022-01-19 23:13:30 +01:00
parent 4cad5890c6
commit b8184a3005
No known key found for this signature in database
GPG Key ID: BCECCD4FA41F6497

View File

@ -56,19 +56,17 @@ namespace osu.Game.Overlays.News.Sidebar
if (allPosts?.Any() != true)
return;
var lookup = metadata.NewValue.NewsPosts.ToLookup(post => post.PublishedAt.Month);
var lookup = metadata.NewValue.NewsPosts.ToLookup(post => (post.PublishedAt.Month, post.PublishedAt.Year));
var keys = lookup.Select(kvp => kvp.Key);
var sortedKeys = keys.OrderByDescending(k => k).ToList();
int year = metadata.NewValue.CurrentYear;
var sortedKeys = keys.OrderByDescending(k => k.Year).ThenByDescending(k => k.Month).ToList();
for (int i = 0; i < sortedKeys.Count; i++)
{
int month = sortedKeys[i];
var posts = lookup[month];
var key = sortedKeys[i];
var posts = lookup[key];
monthsFlow.Add(new MonthSection(month, year, posts)
monthsFlow.Add(new MonthSection(key.Month, key.Year, posts)
{
Expanded = { Value = i == 0 }
});