1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 19:22:54 +08:00

Move metadata change logic to it's own method

This commit is contained in:
Andrei Zavatski 2021-05-11 15:39:50 +03:00
parent 9603712aa1
commit 0a9c3c9413
2 changed files with 27 additions and 18 deletions

View File

@ -32,7 +32,7 @@ namespace osu.Game.Tests.Visual.Online
}
[Test]
public void TestMetadata()
public void TestVisibility()
{
AddStep("Change metadata to null", () => metadataBindable.Value = null);
AddAssert("Panel is hidden", () => panel.IsPresent == false);

View File

@ -66,12 +66,21 @@ namespace osu.Game.Overlays.News.Sidebar
{
base.LoadComplete();
Metadata.BindValueChanged(metadata =>
Metadata.BindValueChanged(onMetadataChanged, true);
}
private void onMetadataChanged(ValueChangedEvent<APINewsSidebar> metadata)
{
monthsFlow.Clear();
if (metadata.NewValue != null)
{
if (metadata.NewValue == null)
return;
var allPosts = metadata.NewValue.NewsPosts;
if (!allPosts?.Any() ?? false)
return;
var lookup = metadata.NewValue.NewsPosts.ToLookup(post => post.PublishedAt.Month);
var keys = lookup.Select(kvp => kvp.Key);
@ -79,13 +88,13 @@ namespace osu.Game.Overlays.News.Sidebar
for (int i = 0; i < sortedKeys.Count; i++)
{
monthsFlow.Add(new MonthPanel(lookup[sortedKeys[i]])
var posts = lookup[sortedKeys[i]];
monthsFlow.Add(new MonthPanel(posts)
{
IsOpen = { Value = i == 0 }
});
}
}
}, true);
}
}
}