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

Lightweight fix for PR detail view not refreshing #1359

Merged
merged 3 commits into from
Dec 4, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions src/GitHub.App/ViewModels/PullRequestDetailViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ namespace GitHub.ViewModels
/// </summary>
[ExportViewModel(ViewType = UIViewType.PRDetail)]
[PartCreationPolicy(CreationPolicy.NonShared)]
public class PullRequestDetailViewModel : PanePageViewModelBase, IPullRequestDetailViewModel
public sealed class PullRequestDetailViewModel : PanePageViewModelBase, IPullRequestDetailViewModel, IDisposable
{
static readonly ILogger log = LogManager.ForContext<PullRequestDetailViewModel>();

readonly IModelService modelService;
readonly IPullRequestService pullRequestsService;
readonly IPullRequestSessionManager sessionManager;
readonly IUsageTracker usageTracker;
readonly IVSGitExt vsGitExt;
IPullRequestModel model;
string sourceBranchDisplayName;
string targetBranchDisplayName;
Expand Down Expand Up @@ -65,13 +66,22 @@ public class PullRequestDetailViewModel : PanePageViewModelBase, IPullRequestDet
ITeamExplorerServiceHolder teservice,
IPullRequestService pullRequestsService,
IPullRequestSessionManager sessionManager,
IUsageTracker usageTracker)
IUsageTracker usageTracker,
IVSGitExt vsGitExt)
: this(teservice.ActiveRepo,
modelServiceFactory.CreateBlocking(connection.Get()),
pullRequestsService,
sessionManager,
usageTracker)
{
this.vsGitExt = vsGitExt;

vsGitExt.ActiveRepositoriesChanged += Refresh;
}

public void Dispose()
{
vsGitExt.ActiveRepositoriesChanged -= Refresh;
}

/// <summary>
Expand Down Expand Up @@ -502,6 +512,18 @@ public string GetLocalFilePath(IPullRequestFileNode file)
return Path.Combine(LocalRepository.LocalPath, file.DirectoryPath, file.FileName);
}

async void Refresh()
{
try
{
await Load(RemoteRepositoryOwner, Model);
}
catch (Exception e)
{
log.Error(e, "Error refreshing model");
}
}

void SubscribeOperationError(ReactiveCommand<Unit> command)
{
command.ThrownExceptions.Subscribe(x => OperationError = x.Message);
Expand Down