1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-13 15:03:13 +08:00

Allow CommentsContainer refetch comments using a method

This commit is contained in:
Andrei Zavatski 2020-01-07 01:07:50 +03:00
parent a614e33405
commit e0f66928e6
2 changed files with 31 additions and 27 deletions

View File

@ -30,29 +30,23 @@ namespace osu.Game.Tests.Visual.Online
public TestSceneCommentsContainer() public TestSceneCommentsContainer()
{ {
BasicScrollContainer scrollFlow; BasicScrollContainer scroll;
CommentsContainer comments;
Add(scrollFlow = new BasicScrollContainer Add(scroll = new BasicScrollContainer
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Child = comments = new CommentsContainer()
}); });
AddStep("Big Black comments", () => AddStep("Big Black comments", () => comments.ShowComments(CommentableType.Beatmapset, 41823));
AddStep("Airman comments", () => comments.ShowComments(CommentableType.Beatmapset, 24313));
AddStep("Lazer build comments", () => comments.ShowComments(CommentableType.Build, 4772));
AddStep("News comments", () => comments.ShowComments(CommentableType.NewsPost, 715));
AddStep("Idle state", () =>
{ {
scrollFlow.Clear(); scroll.Clear();
scrollFlow.Add(new CommentsContainer(CommentableType.Beatmapset, 41823)); scroll.Add(comments = new CommentsContainer());
});
AddStep("Airman comments", () =>
{
scrollFlow.Clear();
scrollFlow.Add(new CommentsContainer(CommentableType.Beatmapset, 24313));
});
AddStep("lazer build comments", () =>
{
scrollFlow.Clear();
scrollFlow.Add(new CommentsContainer(CommentableType.Build, 4772));
}); });
} }
} }

View File

@ -18,8 +18,8 @@ namespace osu.Game.Overlays.Comments
{ {
public class CommentsContainer : CompositeDrawable public class CommentsContainer : CompositeDrawable
{ {
private readonly CommentableType type; private CommentableType type;
private readonly long id; private long id;
public readonly Bindable<CommentsSortCriteria> Sort = new Bindable<CommentsSortCriteria>(); public readonly Bindable<CommentsSortCriteria> Sort = new Bindable<CommentsSortCriteria>();
public readonly BindableBool ShowDeleted = new BindableBool(); public readonly BindableBool ShowDeleted = new BindableBool();
@ -39,11 +39,8 @@ namespace osu.Game.Overlays.Comments
private readonly DeletedChildrenPlaceholder deletedChildrenPlaceholder; private readonly DeletedChildrenPlaceholder deletedChildrenPlaceholder;
private readonly CommentsShowMoreButton moreButton; private readonly CommentsShowMoreButton moreButton;
public CommentsContainer(CommentableType type, long id) public CommentsContainer()
{ {
this.type = type;
this.id = id;
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y; AutoSizeAxes = Axes.Y;
AddRangeInternal(new Drawable[] AddRangeInternal(new Drawable[]
@ -101,7 +98,8 @@ namespace osu.Game.Overlays.Comments
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
Margin = new MarginPadding(5), Margin = new MarginPadding(5),
Action = getComments Action = getComments,
IsLoading = true,
} }
} }
} }
@ -121,12 +119,24 @@ namespace osu.Game.Overlays.Comments
protected override void LoadComplete() protected override void LoadComplete()
{ {
Sort.BindValueChanged(onSortChanged, true); Sort.BindValueChanged(_ => resetComments());
base.LoadComplete(); base.LoadComplete();
} }
private void onSortChanged(ValueChangedEvent<CommentsSortCriteria> sort) /// <param name="type">The type of resource to get comments for.</param>
/// <param name="id">The id of the resource to get comments for.</param>
public void ShowComments(CommentableType type, long id)
{ {
this.type = type;
this.id = id;
Sort.TriggerChange();
}
private void resetComments()
{
if (id == default)
return;
clearComments(); clearComments();
getComments(); getComments();
} }
@ -152,7 +162,7 @@ namespace osu.Game.Overlays.Comments
{ {
loadCancellation = new CancellationTokenSource(); loadCancellation = new CancellationTokenSource();
FillFlowContainer page = new FillFlowContainer var page = new FillFlowContainer
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,