From 220eef035181e3d08b0fde4430b966b3f69c3cb7 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Mon, 10 May 2021 17:00:18 +0300 Subject: [PATCH] Remove overcomplicated date logic in MonthPanel --- .../Visual/Online/TestSceneNewsMonthPanel.cs | 10 ++++++---- osu.Game/Overlays/News/Sidebar/MonthPanel.cs | 6 +++--- osu.Game/Overlays/News/Sidebar/NewsSideBar.cs | 3 +-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneNewsMonthPanel.cs b/osu.Game.Tests/Visual/Online/TestSceneNewsMonthPanel.cs index 75e02b66e1..ee7fb8b407 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneNewsMonthPanel.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneNewsMonthPanel.cs @@ -2,6 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using System; +using System.Collections.Generic; using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Graphics; @@ -33,7 +34,7 @@ namespace osu.Game.Tests.Visual.Online RelativeSizeAxes = Axes.Both, Colour = colourProvider.Background2, }, - new MonthPanel(DateTime.Now, posts), + new MonthPanel(posts), } }); } @@ -53,7 +54,7 @@ namespace osu.Game.Tests.Visual.Online RelativeSizeAxes = Axes.Both, Colour = colourProvider.Background2, }, - new MonthPanel(DateTime.Now, posts) + new MonthPanel(posts) { IsOpen = { Value = true } }, @@ -61,11 +62,12 @@ namespace osu.Game.Tests.Visual.Online }); } - private static APINewsPost[] posts => new[] + private static List posts => new List { new APINewsPost { - Title = "Short title" + Title = "Short title", + PublishedAt = DateTimeOffset.Now }, new APINewsPost { diff --git a/osu.Game/Overlays/News/Sidebar/MonthPanel.cs b/osu.Game/Overlays/News/Sidebar/MonthPanel.cs index 8b405eae10..5f2acd63d1 100644 --- a/osu.Game/Overlays/News/Sidebar/MonthPanel.cs +++ b/osu.Game/Overlays/News/Sidebar/MonthPanel.cs @@ -23,7 +23,7 @@ namespace osu.Game.Overlays.News.Sidebar private readonly FillFlowContainer postsFlow; - public MonthPanel(DateTime date, APINewsPost[] posts) + public MonthPanel(List posts) { Width = 160; AutoSizeDuration = 250; @@ -36,7 +36,7 @@ namespace osu.Game.Overlays.News.Sidebar Spacing = new Vector2(0, 5), Children = new Drawable[] { - new DropdownButton(date) + new DropdownButton(posts[0].PublishedAt) { IsOpen = { BindTarget = IsOpen } }, @@ -87,7 +87,7 @@ namespace osu.Game.Overlays.News.Sidebar private readonly SpriteIcon icon; - public DropdownButton(DateTime date) + public DropdownButton(DateTimeOffset date) { Size = new Vector2(160, 15); Action = IsOpen.Toggle; diff --git a/osu.Game/Overlays/News/Sidebar/NewsSideBar.cs b/osu.Game/Overlays/News/Sidebar/NewsSideBar.cs index 34c995cab6..9a2fdf2d97 100644 --- a/osu.Game/Overlays/News/Sidebar/NewsSideBar.cs +++ b/osu.Game/Overlays/News/Sidebar/NewsSideBar.cs @@ -9,7 +9,6 @@ using osu.Game.Online.API.Requests.Responses; using osu.Framework.Graphics.Shapes; using osuTK; using System.Collections.Generic; -using System; namespace osu.Game.Overlays.News.Sidebar { @@ -100,7 +99,7 @@ namespace osu.Game.Overlays.News.Sidebar foreach (var keyValuePair in dict) { - monthsFlow.Add(new MonthPanel(new DateTime(metadata.NewValue.CurrentYear, keyValuePair.Key, 1), keyValuePair.Value.ToArray()) + monthsFlow.Add(new MonthPanel(keyValuePair.Value) { IsOpen = { Value = isFirst } });