1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 13:27:23 +08:00

Merge pull request #7460 from EVAST9919/view-comments-via-propery

Allow CommentsContainer refetch comments using a method
This commit is contained in:
Dean Herbert 2020-01-23 19:17:48 +09:00 committed by GitHub
commit f5b280971f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 28 deletions

View File

@ -30,29 +30,23 @@ namespace osu.Game.Tests.Visual.Online
public TestSceneCommentsContainer()
{
BasicScrollContainer scrollFlow;
BasicScrollContainer scroll;
CommentsContainer comments;
Add(scrollFlow = new BasicScrollContainer
Add(scroll = new BasicScrollContainer
{
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();
scrollFlow.Add(new CommentsContainer(CommentableType.Beatmapset, 41823));
});
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));
scroll.Clear();
scroll.Add(comments = new CommentsContainer());
});
}
}

View File

@ -18,8 +18,8 @@ namespace osu.Game.Overlays.Comments
{
public class CommentsContainer : CompositeDrawable
{
private readonly CommentableType type;
private readonly long id;
private CommentableType type;
private long? id;
public readonly Bindable<CommentsSortCriteria> Sort = new Bindable<CommentsSortCriteria>();
public readonly BindableBool ShowDeleted = new BindableBool();
@ -39,11 +39,8 @@ namespace osu.Game.Overlays.Comments
private readonly DeletedChildrenPlaceholder deletedChildrenPlaceholder;
private readonly CommentsShowMoreButton moreButton;
public CommentsContainer(CommentableType type, long id)
public CommentsContainer()
{
this.type = type;
this.id = id;
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
AddRangeInternal(new Drawable[]
@ -101,7 +98,8 @@ namespace osu.Game.Overlays.Comments
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Margin = new MarginPadding(5),
Action = getComments
Action = getComments,
IsLoading = true,
}
}
}
@ -121,11 +119,24 @@ namespace osu.Game.Overlays.Comments
protected override void LoadComplete()
{
Sort.BindValueChanged(onSortChanged, true);
Sort.BindValueChanged(_ => refetchComments(), true);
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;
if (!IsLoaded)
return;
refetchComments();
}
private void refetchComments()
{
clearComments();
getComments();
@ -133,9 +144,12 @@ namespace osu.Game.Overlays.Comments
private void getComments()
{
if (!id.HasValue)
return;
request?.Cancel();
loadCancellation?.Cancel();
request = new GetCommentsRequest(type, id, Sort.Value, currentPage++);
request = new GetCommentsRequest(type, id.Value, Sort.Value, currentPage++);
request.Success += onSuccess;
api.Queue(request);
}
@ -152,7 +166,7 @@ namespace osu.Game.Overlays.Comments
{
loadCancellation = new CancellationTokenSource();
FillFlowContainer page = new FillFlowContainer
var page = new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,