This repository was archived by the owner on Jun 21, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 12 files changed +103
-9
lines changed
Expand file tree Collapse file tree 12 files changed +103
-9
lines changed Original file line number Diff line number Diff line change 196196 <Project >{6AFE2E2D-6DB0-4430-A2EA-F5F5388D2F78}</Project >
197197 <Name >GitHub.Extensions</Name >
198198 </ProjectReference >
199+ <ProjectReference Include =" ..\GitHub.UI.Reactive\GitHub.UI.Reactive.csproj" >
200+ <Project >{158b05e8-fdbc-4d71-b871-c96e28d5adf5}</Project >
201+ <Name >GitHub.UI.Reactive</Name >
202+ </ProjectReference >
199203 <ProjectReference Include =" ..\GitHub.UI\GitHub.UI.csproj" >
200204 <Project >{346384dd-2445-4a28-af22-b45f3957bd89}</Project >
201205 <Name >GitHub.UI</Name >
Original file line number Diff line number Diff line change @@ -16,5 +16,10 @@ class CommentThreadViewModelDesigner : ICommentThreadViewModel
1616 = new AccountDesigner { Login = "shana" , IsUser = true } ;
1717
1818 public ReactiveCommand < ICommentModel > PostComment { get ; }
19+
20+ public Uri GetCommentUrl ( int id )
21+ {
22+ throw new NotImplementedException ( ) ;
23+ }
1924 }
2025}
Original file line number Diff line number Diff line change 33using GitHub . InlineReviews . ViewModels ;
44using GitHub . Models ;
55using GitHub . SampleData ;
6+ using GitHub . UI ;
67using ReactiveUI ;
78
89namespace GitHub . InlineReviews . SampleData
910{
10- class CommentViewModelDesigner : ICommentViewModel
11+ class CommentViewModelDesigner : ReactiveObject , ICommentViewModel
1112 {
1213 public CommentViewModelDesigner ( )
1314 {
1415 User = new AccountDesigner { Login = "shana" , IsUser = true } ;
1516 }
1617
18+ public void Initialize ( ViewWithData data )
19+ {
20+ }
21+
1722 public int Id { get ; set ; }
1823 public string Body { get ; set ; }
1924 public string ErrorMessage { get ; set ; }
2025 public CommentEditState EditState { get ; set ; }
2126 public bool IsReadOnly { get ; set ; }
27+ public ICommentThreadViewModel Thread { get ; }
2228 public DateTimeOffset UpdatedAt => DateTime . Now . Subtract ( TimeSpan . FromDays ( 3 ) ) ;
2329 public IAccount User { get ; set ; }
2430
2531 public ReactiveCommand < object > BeginEdit { get ; }
2632 public ReactiveCommand < object > CancelEdit { get ; }
2733 public ReactiveCommand < Unit > CommitEdit { get ; }
34+ public ReactiveCommand < object > OpenOnGitHub { get ; }
2835 }
2936}
Original file line number Diff line number Diff line change @@ -54,6 +54,9 @@ public void Dispose()
5454 GC . SuppressFinalize ( this ) ;
5555 }
5656
57+ /// <inheritdoc/>
58+ public abstract Uri GetCommentUrl ( int id ) ;
59+
5760 protected virtual void Dispose ( bool disposing )
5861 {
5962 if ( disposing )
Original file line number Diff line number Diff line change 55using System . Threading . Tasks ;
66using GitHub . Extensions ;
77using GitHub . Models ;
8+ using GitHub . UI ;
89using ReactiveUI ;
910
1011namespace GitHub . InlineReviews . ViewModels
@@ -73,6 +74,8 @@ public CommentViewModel(
7374 CancelEdit = ReactiveCommand . Create ( CommitEdit . IsExecuting . Select ( x => ! x ) ) ;
7475 CancelEdit . Subscribe ( DoCancelEdit ) ;
7576 AddErrorHandler ( CancelEdit ) ;
77+
78+ OpenOnGitHub = ReactiveCommand . Create ( this . WhenAnyValue ( x => x . Id , x => x != 0 ) ) ;
7679 }
7780
7881 /// <summary>
@@ -89,6 +92,11 @@ public CommentViewModel(
8992 {
9093 }
9194
95+ public void Initialize ( ViewWithData data )
96+ {
97+ // Nothing to do here: initialized in constructor.
98+ }
99+
92100 /// <summary>
93101 /// Creates a placeholder comment which can be used to add a new comment to a thread.
94102 /// </summary>
@@ -208,5 +216,8 @@ public DateTimeOffset UpdatedAt
208216
209217 /// <inheritdoc/>
210218 public ReactiveCommand < Unit > CommitEdit { get ; }
219+
220+ /// <inheritdoc/>
221+ public ReactiveCommand < object > OpenOnGitHub { get ; }
211222 }
212223}
Original file line number Diff line number Diff line change @@ -10,6 +10,13 @@ namespace GitHub.InlineReviews.ViewModels
1010 /// </summary>
1111 public interface ICommentThreadViewModel
1212 {
13+ /// <summary>
14+ /// Gets the browser URI for a comment in the thread.
15+ /// </summary>
16+ /// <param name="id">The ID of the comment.</param>
17+ /// <returns>The URI.</returns>
18+ Uri GetCommentUrl ( int id ) ;
19+
1320 /// <summary>
1421 /// Gets the comments in the thread.
1522 /// </summary>
Original file line number Diff line number Diff line change 11using System ;
22using System . Reactive ;
33using GitHub . Models ;
4+ using GitHub . ViewModels ;
45using ReactiveUI ;
56
67namespace GitHub . InlineReviews . ViewModels
@@ -12,7 +13,7 @@ public enum CommentEditState
1213 Placeholder ,
1314 }
1415
15- public interface ICommentViewModel
16+ public interface ICommentViewModel : IViewModel
1617 {
1718 /// <summary>
1819 /// Gets the ID of the comment.
@@ -49,6 +50,11 @@ public interface ICommentViewModel
4950 /// </summary>
5051 IAccount User { get ; }
5152
53+ /// <summary>
54+ /// Gets the thread that the comment is a part of.
55+ /// </summary>
56+ ICommentThreadViewModel Thread { get ; }
57+
5258 /// <summary>
5359 /// Gets a command which will begin editing of the comment.
5460 /// </summary>
@@ -63,5 +69,10 @@ public interface ICommentViewModel
6369 /// Gets a command which will commit edits to the comment.
6470 /// </summary>
6571 ReactiveCommand < Unit > CommitEdit { get ; }
72+
73+ /// <summary>
74+ /// Gets a command to open the comment in a browser.
75+ /// </summary>
76+ ReactiveCommand < object > OpenOnGitHub { get ; }
6677 }
6778}
Original file line number Diff line number Diff line change 11using System ;
22using System . Collections . Generic ;
3+ using System . Globalization ;
34using System . Reactive . Linq ;
45using System . Threading . Tasks ;
56using GitHub . Api ;
@@ -34,6 +35,7 @@ public InlineCommentThreadViewModel(
3435
3536 this . apiClient = apiClient ;
3637 Session = session ;
38+
3739 PostComment = ReactiveCommand . CreateAsyncTask (
3840 Observable . Return ( true ) ,
3941 DoPostComment ) ;
@@ -51,6 +53,17 @@ public InlineCommentThreadViewModel(
5153 /// </summary>
5254 public IPullRequestSession Session { get ; }
5355
56+ /// <inheritdoc/>
57+ public override Uri GetCommentUrl ( int id )
58+ {
59+ return new Uri ( string . Format (
60+ CultureInfo . InvariantCulture ,
61+ "{0}/pull/{1}#discussion_r{2}" ,
62+ Session . Repository . CloneUrl . ToRepositoryUrl ( ) ,
63+ Session . PullRequest . Number ,
64+ id ) ) ;
65+ }
66+
5467 async Task < ICommentModel > DoPostComment ( object parameter )
5568 {
5669 Guard . ArgumentNotNull ( parameter , nameof ( parameter ) ) ;
Original file line number Diff line number Diff line change @@ -17,6 +17,12 @@ public IssueCommentThreadViewModel(
1717 Number = number ;
1818 }
1919
20+ /// <inheritdoc/>
21+ public override Uri GetCommentUrl ( int id )
22+ {
23+ throw new NotImplementedException ( ) ;
24+ }
25+
2026 public IRepositoryModel Repository { get ; }
2127 public int Number { get ; }
2228 }
Original file line number Diff line number Diff line change @@ -97,6 +97,12 @@ public bool NeedsPush
9797 private set { this . RaiseAndSetIfChanged ( ref needsPush , value ) ; }
9898 }
9999
100+ /// <inheritdoc/>
101+ public override Uri GetCommentUrl ( int id )
102+ {
103+ throw new NotSupportedException ( "Cannot navigate to a non-posted comment." ) ;
104+ }
105+
100106 async Task < ICommentModel > DoPostComment ( object parameter )
101107 {
102108 Guard . ArgumentNotNull ( parameter , nameof ( parameter ) ) ;
You can’t perform that action at this time.
0 commit comments