Archived
1
0

Comments editor

This commit is contained in:
Michael Gordeev
2018-07-05 23:23:58 +03:00
parent 11fcfb4b76
commit 839be10ed2
+30 -7
View File
@@ -27,6 +27,7 @@ namespace FoxTube.Controls
public sealed partial class CommentCard : UserControl public sealed partial class CommentCard : UserControl
{ {
Comment item; Comment item;
CommentThread thread;
CommentType type = CommentType.TopLevel; CommentType type = CommentType.TopLevel;
string NextPageToken; string NextPageToken;
@@ -39,6 +40,7 @@ namespace FoxTube.Controls
public async void Initialize(CommentThread comment) public async void Initialize(CommentThread comment)
{ {
item = comment.Snippet.TopLevelComment; item = comment.Snippet.TopLevelComment;
thread = comment;
replyBtn.Visibility = !comment.Snippet.CanReply.Value || !SecretsVault.IsAuthorized ? Visibility.Collapsed : Visibility.Visible; replyBtn.Visibility = !comment.Snippet.CanReply.Value || !SecretsVault.IsAuthorized ? Visibility.Collapsed : Visibility.Visible;
if (!comment.Snippet.TotalReplyCount.HasValue || comment.Snippet.TotalReplyCount.Value == 0) if (!comment.Snippet.TotalReplyCount.HasValue || comment.Snippet.TotalReplyCount.Value == 0)
@@ -200,16 +202,37 @@ namespace FoxTube.Controls
editor.Visibility = Visibility.Collapsed; 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) editorText.IsEnabled = false;
{ editorSend.IsEnabled = false;
editorClose.IsEnabled = false;
} editorSending.Visibility = Visibility.Visible;
else
{
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) private void editorText_TextChanged(object sender, TextChangedEventArgs e)