From f4801c08ff9693c8e97a5252b96a38fe6f288760 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 11 May 2021 22:34:01 +0300 Subject: [PATCH] Refactor MonthDropdown to ensure all the posts are within a given month --- osu.Game/Overlays/News/Sidebar/MonthDropdown.cs | 11 ++++++++--- osu.Game/Overlays/News/Sidebar/NewsSideBar.cs | 7 +++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/osu.Game/Overlays/News/Sidebar/MonthDropdown.cs b/osu.Game/Overlays/News/Sidebar/MonthDropdown.cs index 11c0ce863f..91412d9527 100644 --- a/osu.Game/Overlays/News/Sidebar/MonthDropdown.cs +++ b/osu.Game/Overlays/News/Sidebar/MonthDropdown.cs @@ -14,6 +14,7 @@ using System.Linq; using System.Collections.Generic; using osu.Framework.Allocation; using osu.Framework.Graphics.Sprites; +using System.Diagnostics; namespace osu.Game.Overlays.News.Sidebar { @@ -26,8 +27,10 @@ namespace osu.Game.Overlays.News.Sidebar private readonly FillFlowContainer postsFlow; - public MonthDropdown(IEnumerable posts) + public MonthDropdown(int month, int year, IEnumerable posts) { + Debug.Assert(posts.All(p => p.PublishedAt.Month == month && p.PublishedAt.Year == year)); + RelativeSizeAxes = Axes.X; Masking = true; InternalChild = new FillFlowContainer @@ -38,7 +41,7 @@ namespace osu.Game.Overlays.News.Sidebar Spacing = new Vector2(0, 5), Children = new Drawable[] { - new DropdownHeader(posts.ElementAt(0).PublishedAt) + new DropdownHeader(month, year) { IsOpen = { BindTarget = IsOpen } }, @@ -102,8 +105,10 @@ namespace osu.Game.Overlays.News.Sidebar private readonly SpriteIcon icon; - public DropdownHeader(DateTimeOffset date) + public DropdownHeader(int month, int year) { + var date = new DateTime(year, month, 1); + RelativeSizeAxes = Axes.X; Height = header_height; Action = IsOpen.Toggle; diff --git a/osu.Game/Overlays/News/Sidebar/NewsSideBar.cs b/osu.Game/Overlays/News/Sidebar/NewsSideBar.cs index baa1826185..3851dea83a 100644 --- a/osu.Game/Overlays/News/Sidebar/NewsSideBar.cs +++ b/osu.Game/Overlays/News/Sidebar/NewsSideBar.cs @@ -86,11 +86,14 @@ namespace osu.Game.Overlays.News.Sidebar var keys = lookup.Select(kvp => kvp.Key); var sortedKeys = keys.OrderByDescending(k => k).ToList(); + var year = metadata.NewValue.CurrentYear; + for (int i = 0; i < sortedKeys.Count; i++) { - var posts = lookup[sortedKeys[i]]; + var month = sortedKeys[i]; + var posts = lookup[month]; - monthsFlow.Add(new MonthDropdown(posts) + monthsFlow.Add(new MonthDropdown(month, year, posts) { IsOpen = { Value = i == 0 } });