mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 08:23:00 +08:00
Remove ReplyCommentEditor
into its own class
This commit is contained in:
parent
7f4d8bdcaa
commit
07af18b8a7
@ -606,52 +606,5 @@ namespace osu.Game.Overlays.Comments
|
||||
return parentComment.HasMessage ? parentComment.Message : parentComment.IsDeleted ? CommentsStrings.Deleted : string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
private partial class ReplyCommentEditor : CancellableCommentEditor
|
||||
{
|
||||
[Resolved]
|
||||
private CommentsContainer commentsContainer { get; set; } = null!;
|
||||
|
||||
[Resolved]
|
||||
private IAPIProvider api { get; set; } = null!;
|
||||
|
||||
private readonly Comment parentComment;
|
||||
|
||||
public Action<DrawableComment[]>? OnPost;
|
||||
|
||||
protected override LocalisableString FooterText => default;
|
||||
protected override LocalisableString CommitButtonText => CommonStrings.ButtonsReply;
|
||||
protected override LocalisableString TextBoxPlaceholder => CommentsStrings.PlaceholderReply;
|
||||
|
||||
public ReplyCommentEditor(Comment parent)
|
||||
{
|
||||
parentComment = parent;
|
||||
OnCancel = () => this.FadeOut(200).Expire();
|
||||
}
|
||||
|
||||
protected override void OnCommit(string text)
|
||||
{
|
||||
ShowLoadingSpinner = true;
|
||||
CommentPostRequest req = new CommentPostRequest(commentsContainer.Type.Value, commentsContainer.Id.Value, text, parentComment.Id);
|
||||
req.Failure += e => Schedule(() =>
|
||||
{
|
||||
ShowLoadingSpinner = false;
|
||||
Logger.Error(e, "Posting reply comment failed.");
|
||||
});
|
||||
req.Success += cb => Schedule(processPostedComments, cb);
|
||||
api.Queue(req);
|
||||
}
|
||||
|
||||
private void processPostedComments(CommentBundle cb)
|
||||
{
|
||||
foreach (var comment in cb.Comments)
|
||||
comment.ParentComment = parentComment;
|
||||
|
||||
var drawables = cb.Comments.Select(commentsContainer.GetDrawableComment).ToArray();
|
||||
OnPost?.Invoke(drawables);
|
||||
|
||||
OnCancel!.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
63
osu.Game/Overlays/Comments/ReplyCommentEditor.cs
Normal file
63
osu.Game/Overlays/Comments/ReplyCommentEditor.cs
Normal file
@ -0,0 +1,63 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Localisation;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.API.Requests;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Resources.Localisation.Web;
|
||||
|
||||
namespace osu.Game.Overlays.Comments
|
||||
{
|
||||
public partial class ReplyCommentEditor : CancellableCommentEditor
|
||||
{
|
||||
[Resolved]
|
||||
private CommentsContainer commentsContainer { get; set; } = null!;
|
||||
|
||||
[Resolved]
|
||||
private IAPIProvider api { get; set; } = null!;
|
||||
|
||||
private readonly Comment parentComment;
|
||||
|
||||
public Action<DrawableComment[]>? OnPost;
|
||||
|
||||
protected override LocalisableString FooterText => default;
|
||||
protected override LocalisableString CommitButtonText => CommonStrings.ButtonsReply;
|
||||
protected override LocalisableString TextBoxPlaceholder => CommentsStrings.PlaceholderReply;
|
||||
|
||||
public ReplyCommentEditor(Comment parent)
|
||||
{
|
||||
parentComment = parent;
|
||||
OnCancel = () => this.FadeOut(200).Expire();
|
||||
}
|
||||
|
||||
protected override void OnCommit(string text)
|
||||
{
|
||||
ShowLoadingSpinner = true;
|
||||
CommentPostRequest req = new CommentPostRequest(commentsContainer.Type.Value, commentsContainer.Id.Value, text, parentComment.Id);
|
||||
req.Failure += e => Schedule(() =>
|
||||
{
|
||||
ShowLoadingSpinner = false;
|
||||
Logger.Error(e, "Posting reply comment failed.");
|
||||
});
|
||||
req.Success += cb => Schedule(processPostedComments, cb);
|
||||
api.Queue(req);
|
||||
}
|
||||
|
||||
private void processPostedComments(CommentBundle cb)
|
||||
{
|
||||
foreach (var comment in cb.Comments)
|
||||
comment.ParentComment = parentComment;
|
||||
|
||||
var drawables = cb.Comments.Select(commentsContainer.GetDrawableComment).ToArray();
|
||||
OnPost?.Invoke(drawables);
|
||||
|
||||
OnCancel!.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user