Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit c2d230a

Browse files
committed
Confirm that the user really wants to delete a comment
1 parent df92a61 commit c2d230a

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

src/GitHub.InlineReviews/ViewModels/CommentViewModel.cs

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Reactive;
44
using System.Reactive.Linq;
55
using System.Threading.Tasks;
6+
using System.Windows;
67
using GitHub.Extensions;
78
using GitHub.Logging;
89
using GitHub.Models;
@@ -130,22 +131,41 @@ protected void AddErrorHandler<T>(ReactiveCommand<T> command)
130131

131132
async Task DoDelete(object unused)
132133
{
133-
try
134-
{
135-
ErrorMessage = null;
136-
IsSubmitting = true;
134+
string deleteCommentMessageBoxText = "Are you sure you want to delete this comment?";
135+
string deleteCommentCaption = "Delete Comment";
136+
MessageBoxButton deleteCommentButton = MessageBoxButton.YesNo;
137+
MessageBoxImage deleteCommentImage = MessageBoxImage.Question;
137138

138-
await Thread.DeleteComment.ExecuteAsyncTask(new Tuple<int, int>(PullRequestId, DatabaseId));
139-
}
140-
catch (Exception e)
141-
{
142-
var message = e.Message;
143-
ErrorMessage = message;
144-
log.Error(e, "Error Deleting comment");
145-
}
146-
finally
139+
MessageBoxResult result = MessageBox.Show(deleteCommentMessageBoxText, deleteCommentCaption, deleteCommentButton, deleteCommentImage);
140+
141+
switch(result)
147142
{
148-
IsSubmitting = false;
143+
case (MessageBoxResult.Yes):
144+
{
145+
try
146+
{
147+
ErrorMessage = null;
148+
IsSubmitting = true;
149+
150+
await Thread.DeleteComment.ExecuteAsyncTask(new Tuple<int, int>(PullRequestId, DatabaseId));
151+
}
152+
catch (Exception e)
153+
{
154+
var message = e.Message;
155+
ErrorMessage = message;
156+
log.Error(e, "Error Deleting comment");
157+
}
158+
finally
159+
{
160+
IsSubmitting = false;
161+
}
162+
break;
163+
}
164+
165+
case (MessageBoxResult.No):
166+
{
167+
break;
168+
}
149169
}
150170
}
151171

0 commit comments

Comments
 (0)