mirror of https://github.com/ppy/osu
Allow CommentsContainer refetch comments using a method
This commit is contained in:
parent
a614e33405
commit
e0f66928e6
|
@ -30,29 +30,23 @@ public class TestSceneCommentsContainer : OsuTestScene
|
|||
|
||||
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());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 @@ public class CommentsContainer : CompositeDrawable
|
|||
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 @@ public CommentsContainer(CommentableType type, long id)
|
|||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Margin = new MarginPadding(5),
|
||||
Action = getComments
|
||||
Action = getComments,
|
||||
IsLoading = true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -121,12 +119,24 @@ private void load()
|
|||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
Sort.BindValueChanged(onSortChanged, true);
|
||||
Sort.BindValueChanged(_ => resetComments());
|
||||
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();
|
||||
getComments();
|
||||
}
|
||||
|
@ -152,7 +162,7 @@ private void onSuccess(CommentBundle response)
|
|||
{
|
||||
loadCancellation = new CancellationTokenSource();
|
||||
|
||||
FillFlowContainer page = new FillFlowContainer
|
||||
var page = new FillFlowContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
|
|
Loading…
Reference in New Issue