From 839be10ed26b617a66caadd775509530c48a8fba Mon Sep 17 00:00:00 2001 From: Michael Gordeev Date: Thu, 5 Jul 2018 23:23:58 +0300 Subject: [PATCH] Comments editor --- FoxTube/Controls/CommentCard.xaml.cs | 37 ++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/FoxTube/Controls/CommentCard.xaml.cs b/FoxTube/Controls/CommentCard.xaml.cs index b49a863..3412d27 100644 --- a/FoxTube/Controls/CommentCard.xaml.cs +++ b/FoxTube/Controls/CommentCard.xaml.cs @@ -27,6 +27,7 @@ namespace FoxTube.Controls public sealed partial class CommentCard : UserControl { Comment item; + CommentThread thread; CommentType type = CommentType.TopLevel; string NextPageToken; @@ -39,6 +40,7 @@ namespace FoxTube.Controls public async void Initialize(CommentThread comment) { item = comment.Snippet.TopLevelComment; + thread = comment; replyBtn.Visibility = !comment.Snippet.CanReply.Value || !SecretsVault.IsAuthorized ? Visibility.Collapsed : Visibility.Visible; if (!comment.Snippet.TotalReplyCount.HasValue || comment.Snippet.TotalReplyCount.Value == 0) @@ -200,16 +202,37 @@ namespace FoxTube.Controls editor.Visibility = Visibility.Collapsed; } - private void editorSend_Click(object sender, RoutedEventArgs e) + private async void editorSend_Click(object sender, RoutedEventArgs e) { - if(type == CommentType.Reply) - { - - } - else - { + editorText.IsEnabled = false; + editorSend.IsEnabled = false; + editorClose.IsEnabled = false; + editorSending.Visibility = Visibility.Visible; + try + { + item.Snippet.TextDisplay = editorText.Text; + item.Snippet.UpdatedAt = DateTime.Now; + + if (type == CommentType.Reply) + await SecretsVault.Service.Comments.Update(item, "snippet").ExecuteAsync(); + else + { + thread.Snippet.TopLevelComment = item; + await SecretsVault.Service.CommentThreads.Update(thread, "snippet").ExecuteAsync(); + } + + editorClose_Click(this, null); } + catch + { + await new MessageDialog("Failed to edit your commentary. Please, try again later.", "Failed to edit your commentary").ShowAsync(); + } + + editorText.IsEnabled = true; + editorSend.IsEnabled = true; + editorClose.IsEnabled = true; + editorSending.Visibility = Visibility.Collapsed; } private void editorText_TextChanged(object sender, TextChangedEventArgs e)