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

Commit 8fb93d6

Browse files
Adding a CanEditOrDelete property
1 parent 0d9c2de commit 8fb93d6

File tree

4 files changed

+41
-31
lines changed

4 files changed

+41
-31
lines changed

src/GitHub.InlineReviews/SampleData/CommentViewModelDesigner.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public CommentViewModelDesigner()
2424
public CommentEditState EditState { get; set; }
2525
public bool IsReadOnly { get; set; }
2626
public bool IsSubmitting { get; set; }
27+
public bool CanEditOrDelete { get; } = true;
2728
public ICommentThreadViewModel Thread { get; }
2829
public DateTimeOffset UpdatedAt => DateTime.Now.Subtract(TimeSpan.FromDays(3));
2930
public IAccount User { get; set; }

src/GitHub.InlineReviews/ViewModels/CommentViewModel.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public class CommentViewModel : ReactiveObject, ICommentViewModel
2424
CommentEditState state;
2525
DateTimeOffset updatedAt;
2626
string undoBody;
27+
private bool canEditOrDelete;
2728

2829
/// <summary>
2930
/// Initializes a new instance of the <see cref="CommentViewModel"/> class.
@@ -60,17 +61,15 @@ protected CommentViewModel(
6061
User = user;
6162
UpdatedAt = updatedAt;
6263

63-
var canDelete = this.WhenAnyValue(
64+
var canEditOrDeleteObservable = this.WhenAnyValue(
6465
x => x.EditState,
6566
x => x == CommentEditState.None && user.Login.Equals(currentUser.Login));
6667

67-
Delete = ReactiveCommand.CreateAsyncTask(canDelete, DoDelete);
68+
canEditOrDeleteObservable.Subscribe(b => CanEditOrDelete = b);
6869

69-
var canEdit = this.WhenAnyValue(
70-
x => x.EditState,
71-
x => x == CommentEditState.None && user.Login.Equals(currentUser.Login));
70+
Delete = ReactiveCommand.CreateAsyncTask(canEditOrDeleteObservable, DoDelete);
7271

73-
BeginEdit = ReactiveCommand.Create(canEdit);
72+
BeginEdit = ReactiveCommand.Create(canEditOrDeleteObservable);
7473
BeginEdit.Subscribe(DoBeginEdit);
7574
AddErrorHandler(BeginEdit);
7675

@@ -283,6 +282,12 @@ public bool IsSubmitting
283282
protected set { this.RaiseAndSetIfChanged(ref isSubmitting, value); }
284283
}
285284

285+
public bool CanEditOrDelete
286+
{
287+
get { return canEditOrDelete; }
288+
private set { this.RaiseAndSetIfChanged(ref canEditOrDelete, value); }
289+
}
290+
286291
/// <inheritdoc/>
287292
public DateTimeOffset UpdatedAt
288293
{

src/GitHub.InlineReviews/ViewModels/ICommentViewModel.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ public interface ICommentViewModel : IViewModel
5555
/// </summary>
5656
bool IsSubmitting { get; }
5757

58+
/// <summary>
59+
/// Gets a value indicating whether the comment can be edited or deleted by the current user
60+
/// </summary>
61+
bool CanEditOrDelete { get; }
62+
5863
/// <summary>
5964
/// Gets the modified date of the comment.
6065
/// </summary>

src/GitHub.InlineReviews/Views/CommentView.xaml

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
xmlns:views="clr-namespace:GitHub.InlineReviews.Views"
1313
mc:Ignorable="d" d:DesignWidth="300">
1414
<d:DesignProperties.DataContext>
15-
<sample:CommentViewModelDesigner EditState="Editing">
15+
<sample:CommentViewModelDesigner EditState="None">
1616
<sample:CommentViewModelDesigner.Body>
1717
You can use a `CompositeDisposable` type here, it's designed to handle disposables in an optimal way (you can just call `Dispose()` on it and it will handle disposing everything it holds).
1818
</sample:CommentViewModelDesigner.Body>
@@ -51,46 +51,45 @@
5151
</StackPanel.Style>
5252

5353
<DockPanel>
54+
55+
<StackPanel Orientation="Horizontal" DockPanel.Dock="Left" >
5456
<controls:AccountAvatar Width="16"
55-
Height="16"
56-
Account="{Binding User}"
57-
DockPanel.Dock="Left" />
57+
Height="16"
58+
Account="{Binding User}"/>
5859

59-
<TextBlock Foreground="{DynamicResource GitHubVsToolWindowText}" FontWeight="Bold" Text="{Binding User.Login}" Margin="4 0"
60-
DockPanel.Dock="Left" />
60+
<TextBlock Foreground="{DynamicResource GitHubVsToolWindowText}" FontWeight="Bold" Text="{Binding User.Login}" Margin="4 0"/>
6161
<ui:GitHubActionLink Content="{Binding UpdatedAt, Converter={ui:DurationToStringConverter}}"
62-
Command="{Binding OpenOnGitHub}"
63-
Foreground="{DynamicResource GitHubVsToolWindowText}"
64-
Opacity="0.75"
65-
DockPanel.Dock="Left" />
62+
Command="{Binding OpenOnGitHub}"
63+
Foreground="{DynamicResource GitHubVsToolWindowText}"
64+
Opacity="0.75" />
6665
<Border Background="{DynamicResource VsBrush.InfoBackground}"
6766
BorderBrush="{DynamicResource VsBrush.AccentPale}"
6867
BorderThickness="1"
6968
CornerRadius="3"
7069
Padding="2 1"
71-
DockPanel.Dock="Left"
7270
Visibility="{Binding IsPending, Converter={ui:BooleanToVisibilityConverter}, FallbackValue=Collapsed}">
73-
<TextBlock FontSize="10">Pending</TextBlock>
71+
<TextBlock FontSize="10">Pending</TextBlock>
7472
</Border>
75-
<ui:GitHubActionLink Content="Delete"
76-
Command="{Binding Delete}"
77-
Foreground="{DynamicResource GitHubVsToolWindowText}"
78-
Opacity="0.75"
79-
HorizontalAlignment="Right"
80-
DockPanel.Dock="Right"/>
73+
</StackPanel>
74+
75+
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" DockPanel.Dock="Right"
76+
Visibility="{Binding CanEditOrDelete, Converter={ui:BooleanToVisibilityConverter}}">
8177
<ui:GitHubActionLink Content="Edit"
8278
Command="{Binding BeginEdit}"
8379
Foreground="{DynamicResource GitHubVsToolWindowText}"
84-
Opacity="0.75"
85-
HorizontalAlignment="Right"
86-
DockPanel.Dock="Right" />
87-
</DockPanel>
80+
Opacity="0.75" />
81+
<ui:GitHubActionLink Content="Delete"
82+
Command="{Binding Delete}"
83+
Foreground="{DynamicResource GitHubVsToolWindowText}"
84+
Opacity="0.75"/>
85+
</StackPanel>
8886

87+
</DockPanel>
8988

9089
<markdig:MarkdownViewer Grid.Column="1" Grid.Row="1"
91-
Margin="0 2 0 0"
92-
Foreground="{DynamicResource VsBrush.WindowText}"
93-
Markdown="{Binding Body}"/>
90+
Margin="0 2 0 0"
91+
Foreground="{DynamicResource VsBrush.WindowText}"
92+
Markdown="{Binding Body}"/>
9493
</StackPanel>
9594

9695
<!-- Displays edit view or a reply placeholder-->

0 commit comments

Comments
 (0)