|
1 | | -using System; |
2 | | -using System.Collections.ObjectModel; |
3 | | -using System.Reactive; |
| 1 | +using System.ComponentModel.Composition; |
| 2 | +using System.Threading.Tasks; |
4 | 3 | using GitHub.Extensions; |
5 | 4 | using GitHub.Models; |
6 | | -using GitHub.ViewModels; |
7 | 5 | using ReactiveUI; |
8 | 6 |
|
9 | | -namespace GitHub.InlineReviews.ViewModels |
| 7 | +namespace GitHub.ViewModels |
10 | 8 | { |
11 | 9 | /// <summary> |
12 | 10 | /// Base view model for a thread of comments. |
13 | 11 | /// </summary> |
14 | 12 | public abstract class CommentThreadViewModel : ReactiveObject, ICommentThreadViewModel |
15 | 13 | { |
16 | | - ReactiveCommand<string, Unit> postComment; |
17 | | - ReactiveCommand<Tuple<string, string>, Unit> editComment; |
18 | | - ReactiveCommand<Tuple<int, int>, Unit> deleteComment; |
| 14 | + readonly ReactiveList<ICommentViewModel> comments = new ReactiveList<ICommentViewModel>(); |
| 15 | + |
| 16 | + /// <summary> |
| 17 | + /// Initializes a new instance of the <see cref="CommentThreadViewModel"/> class. |
| 18 | + /// </summary> |
| 19 | + [ImportingConstructor] |
| 20 | + public CommentThreadViewModel() |
| 21 | + { |
| 22 | + } |
19 | 23 |
|
20 | 24 | /// <summary> |
21 | 25 | /// Intializes a new instance of the <see cref="CommentThreadViewModel"/> class. |
22 | 26 | /// </summary> |
23 | 27 | /// <param name="currentUser">The current user.</param> |
24 | | - protected CommentThreadViewModel(ActorModel currentUser) |
| 28 | + protected Task InitializeAsync(ActorModel currentUser) |
25 | 29 | { |
26 | 30 | Guard.ArgumentNotNull(currentUser, nameof(currentUser)); |
27 | | - |
28 | | - Comments = new ObservableCollection<ICommentViewModel>(); |
29 | 31 | CurrentUser = new ActorViewModel(currentUser); |
| 32 | + return Task.CompletedTask; |
30 | 33 | } |
31 | 34 |
|
32 | 35 | /// <inheritdoc/> |
33 | | - public ObservableCollection<ICommentViewModel> Comments { get; } |
| 36 | + public IReactiveList<ICommentViewModel> Comments => comments; |
34 | 37 |
|
35 | 38 | /// <inheritdoc/> |
36 | | - public ReactiveCommand<string, Unit> PostComment |
37 | | - { |
38 | | - get { return postComment; } |
39 | | - protected set |
40 | | - { |
41 | | - Guard.ArgumentNotNull(value, nameof(value)); |
42 | | - postComment = value; |
43 | | - |
44 | | - // We want to ignore thrown exceptions from PostComment - the error should be handled |
45 | | - // by the CommentViewModel that trigged PostComment.Execute(); |
46 | | - value.ThrownExceptions.Subscribe(_ => { }); |
47 | | - } |
48 | | - } |
| 39 | + public IActorViewModel CurrentUser { get; private set; } |
49 | 40 |
|
50 | | - public ReactiveCommand<Tuple<string, string>, Unit> EditComment |
51 | | - { |
52 | | - get { return editComment; } |
53 | | - protected set |
54 | | - { |
55 | | - Guard.ArgumentNotNull(value, nameof(value)); |
56 | | - editComment = value; |
57 | | - |
58 | | - value.ThrownExceptions.Subscribe(_ => { }); |
59 | | - } |
60 | | - } |
| 41 | + /// <inheritdoc/> |
| 42 | + IReadOnlyReactiveList<ICommentViewModel> ICommentThreadViewModel.Comments => comments; |
61 | 43 |
|
62 | | - public ReactiveCommand<Tuple<int, int>, Unit> DeleteComment |
63 | | - { |
64 | | - get { return deleteComment; } |
65 | | - protected set |
66 | | - { |
67 | | - Guard.ArgumentNotNull(value, nameof(value)); |
68 | | - deleteComment = value; |
| 44 | + /// <inheritdoc/> |
| 45 | + public abstract Task PostComment(string body); |
69 | 46 |
|
70 | | - value.ThrownExceptions.Subscribe(_ => { }); |
71 | | - } |
72 | | - } |
| 47 | + /// <inheritdoc/> |
| 48 | + public abstract Task EditComment(string id, string body); |
73 | 49 |
|
74 | 50 | /// <inheritdoc/> |
75 | | - public IActorViewModel CurrentUser { get; } |
| 51 | + public abstract Task DeleteComment(int pullRequestId, int commentId); |
76 | 52 | } |
77 | 53 | } |
0 commit comments