|
| 1 | +using System; |
| 2 | +using System.Reactive; |
| 3 | +using System.Threading.Tasks; |
| 4 | +using GitHub.Models; |
| 5 | +using GitHub.ViewModels; |
| 6 | +using GitHub.ViewModels.Documents; |
| 7 | +using ReactiveUI; |
| 8 | + |
| 9 | +namespace GitHub.SampleData.Documents |
| 10 | +{ |
| 11 | + public class PullRequestPageViewModelDesigner : ViewModelBase, IPullRequestPageViewModel |
| 12 | + { |
| 13 | + public PullRequestPageViewModelDesigner() |
| 14 | + { |
| 15 | + Body = @"Save drafts of inline comments, PR reviews and PRs. |
| 16 | +
|
| 17 | +> Note: This feature required a refactoring of the comment view models because they now need async initialization and to be available from GitHub.App. This part of the PR has been submitted separately as #1993 to ease review. The two PRs can alternatively be reviewed as one if that's more convenient. |
| 18 | +
|
| 19 | +As described in #1905, it is easy to lose a comment that you're working on if you close the diff view accidentally. This PR saves drafts of comments as they are being written to an SQLite database. |
| 20 | +
|
| 21 | +In addition to saving drafts of inline comments, it also saves comments to PR reviews and PRs themselves. |
| 22 | +
|
| 23 | +The comments are written to an SQLite database directly instead of going through Akavache because in the case of inline reviews, there can be many drafts in progress on a separate file. When a diff is opened we need to look for any comments present on that file and show the most recent. That use-case didn't fit well with Akavache (being a pure key/value store). |
| 24 | +
|
| 25 | +## Testing |
| 26 | +
|
| 27 | +### Inline Comments |
| 28 | +
|
| 29 | +- Open a PR |
| 30 | +- Open the diff of a file |
| 31 | +- Start adding a comment |
| 32 | +- Close the comment by closing the peek view, or the document tab |
| 33 | +- Reopen the diff |
| 34 | +- You should see the comment displayed in edit mode with the draft of the comment you were previously writing |
| 35 | +
|
| 36 | +### PR reviews |
| 37 | +
|
| 38 | +- Open a PR |
| 39 | +- Click ""Add your review"" |
| 40 | +- Start adding a review |
| 41 | +- Click the ""Back"" button and navigate to a different PR |
| 42 | +- Click the ""Back"" button and navigate to the original PR |
| 43 | +- Click ""Add your review"" |
| 44 | +- You should see the the draft of the review you were previously writing |
| 45 | +
|
| 46 | +### PRs |
| 47 | +
|
| 48 | +-Click ""Create new"" at the top of the PR list |
| 49 | +- Start adding a PR title/ description |
| 50 | +- Close VS |
| 51 | +- Restart VS and click ""Create new"" again |
| 52 | +- You should see the the draft of the PR you were previously writing |
| 53 | +
|
| 54 | +Depends on #1993 |
| 55 | +Fixes #1905"; |
| 56 | + } |
| 57 | + |
| 58 | + public PullRequestState State { get; set; } = PullRequestState.Open; |
| 59 | + public IIssueishCommentThreadViewModel Thread { get; set; } |
| 60 | + public string SourceBranchDisplayName { get; set; } = "feature/save-drafts"; |
| 61 | + public string TargetBranchDisplayName { get; set; } = "master"; |
| 62 | + public IActorViewModel Author { get; set; } = new ActorViewModelDesigner("grokys"); |
| 63 | + public string Body { get; set; } |
| 64 | + public int Number { get; set; } = 1994; |
| 65 | + public IRepositoryModel Repository { get; set; } |
| 66 | + public string Title { get; set; } = "Save drafts of comments"; |
| 67 | + public Uri WebUrl { get; set; } |
| 68 | + public ReactiveCommand<Unit, Unit> OpenOnGitHub { get; } |
| 69 | + |
| 70 | + public Task InitializeAsync(ActorModel currentUser, PullRequestDetailModel model) => Task.CompletedTask; |
| 71 | + } |
| 72 | +} |
0 commit comments