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

Commit e448a9d

Browse files
committed
Move to home page when repo is published.
Fixes regression of #48
1 parent 11e9f8d commit e448a9d

File tree

8 files changed

+72
-45
lines changed

8 files changed

+72
-45
lines changed

src/GitHub.App/Controllers/UIController.cs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ enum Trigger { Cancel = 0, Auth = 1, Create = 2, Clone = 3, Publish = 4, Next, F
3636
readonly CompositeDisposable disposables = new CompositeDisposable();
3737
readonly StateMachine<UIViewType, Trigger> machine;
3838
Subject<UserControl> transition;
39+
Subject<bool> completion;
3940
UIControllerFlow currentFlow;
4041
NotifyCollectionChangedEventHandler connectionAdded;
4142

@@ -118,17 +119,10 @@ public UIController(IUIProvider uiProvider, IRepositoryHosts hosts, IExportFacto
118119
.Permit(Trigger.Next, UIViewType.End);
119120

120121
machine.Configure(UIViewType.End)
121-
.OnEntry(() =>
122-
{
123-
uiProvider.RemoveService(typeof(IConnection));
124-
transition.OnCompleted();
125-
})
122+
.OnEntryFrom(Trigger.Cancel, () => End(false))
123+
.OnEntryFrom(Trigger.Next, () => End(true))
126124
.Permit(Trigger.Next, UIViewType.Finished);
127125

128-
// it might be useful later to check which triggered
129-
// made us enter here (Cancel or Next) and set a final
130-
// result accordingly, which is why UIViewType.End only
131-
// allows a Next trigger
132126
machine.Configure(UIViewType.Finished);
133127
}
134128

@@ -142,6 +136,25 @@ public IObservable<UserControl> SelectFlow(UIControllerFlow choice)
142136
return transition;
143137
}
144138

139+
/// <summary>
140+
/// Allows listening to the completion state of the ui flow - whether
141+
/// it was completed because it was cancelled or whether it succeeded.
142+
/// </summary>
143+
/// <returns>true for success, false for cancel</returns>
144+
public IObservable<bool> ListenToCompletionState()
145+
{
146+
completion = new Subject<bool>();
147+
return completion;
148+
}
149+
150+
void End(bool success)
151+
{
152+
uiProvider.RemoveService(typeof(IConnection));
153+
completion.OnNext(success);
154+
completion.OnCompleted();
155+
transition.OnCompleted();
156+
}
157+
145158
void RunView(UIViewType viewType)
146159
{
147160
var view = CreateViewAndViewModel(viewType);

src/GitHub.App/SampleData/SampleViewModels.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ public bool IsPublishing
249249
private set;
250250
}
251251

252-
public IReactiveCommand<Unit> PublishRepository
252+
public IReactiveCommand<ProgressState> PublishRepository
253253
{
254254
get;
255255
private set;

src/GitHub.App/ViewModels/RepositoryPublishViewModel.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public RepositoryPublishViewModel(
117117
public bool CanKeepPrivate { get { return canKeepPrivate.Value; } }
118118
public bool IsPublishing { get { return isPublishing.Value; } }
119119

120-
public IReactiveCommand<Unit> PublishRepository { get; private set; }
120+
public IReactiveCommand<ProgressState> PublishRepository { get; private set; }
121121
public ReactiveList<IConnection> Connections { get; private set; }
122122

123123
IConnection selectedConnection;
@@ -145,29 +145,32 @@ public bool IsHostComboBoxVisible
145145
get { return isHostComboBoxVisible.Value; }
146146
}
147147

148-
ReactiveCommand<Unit> InitializePublishRepositoryCommand()
148+
ReactiveCommand<ProgressState> InitializePublishRepositoryCommand()
149149
{
150150
var canCreate = this.WhenAny(x => x.RepositoryNameValidator.ValidationResult.IsValid, x => x.Value);
151151
return ReactiveCommand.CreateAsyncObservable(canCreate, OnPublishRepository);
152152
}
153153

154-
private IObservable<Unit> OnPublishRepository(object arg)
154+
IObservable<ProgressState> OnPublishRepository(object arg)
155155
{
156156
var newRepository = GatherRepositoryInfo();
157157
var account = SelectedAccount;
158158

159159
return repositoryPublishService.PublishRepository(newRepository, account, SelectedHost.ApiClient)
160-
.SelectUnit()
161-
.Do(_ => vsServices.ShowMessage("Repository published successfully."))
162-
.Catch<Unit, Exception>(ex =>
160+
.Select(_ =>
161+
{
162+
vsServices.ShowMessage("Repository published successfully.");
163+
return ProgressState.Success;
164+
})
165+
.Catch<ProgressState, Exception>(ex =>
163166
{
164167
if (!ex.IsCriticalException())
165168
{
166169
log.Error(ex);
167170
var error = new PublishRepositoryUserError(ex.Message);
168171
vsServices.ShowError((error.ErrorMessage + Environment.NewLine + error.ErrorCauseOrResolution).TrimEnd());
169172
}
170-
return Observable.Return(Unit.Default);
173+
return Observable.Return(ProgressState.Fail);
171174
});
172175
}
173176

src/GitHub.Exports.Reactive/ViewModels/IRepositoryPublishViewModel.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public interface IRepositoryPublishViewModel : IRepositoryForm
1111
/// <summary>
1212
/// Command that creates the repository.
1313
/// </summary>
14-
IReactiveCommand<Unit> PublishRepository { get; }
14+
IReactiveCommand<ProgressState> PublishRepository { get; }
1515

1616
/// <summary>
1717
/// True when publishing is in progress.
@@ -33,4 +33,13 @@ public interface IRepositoryPublishViewModel : IRepositoryForm
3333
/// </summary>
3434
string DefaultRepositoryName { get; }
3535
}
36+
37+
public enum ProgressState
38+
{
39+
Idle,
40+
Running,
41+
Success,
42+
Fail
43+
}
44+
3645
}

src/GitHub.Exports/UI/IUIController.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@ namespace GitHub.UI
77
{
88
public interface IUIController
99
{
10-
//IObservable<object> Transition { get; }
1110
IObservable<UserControl> SelectFlow(UIControllerFlow choice);
11+
/// <summary>
12+
/// Allows listening to the completion state of the ui flow - whether
13+
/// it was completed because it was cancelled or whether it succeeded.
14+
/// </summary>
15+
/// <returns>true for success, false for cancel</returns>
16+
IObservable<bool> ListenToCompletionState();
1217
void Start(IConnection connection);
1318
void Stop();
1419
bool IsStopped { get; }

src/GitHub.VisualStudio/TeamExplorer/Sync/GitHubPublishSection.cs

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public GitHubPublishSection(ISimpleApiClientFactory apiFactory, ITeamExplorerSer
5050
view.DataContext = this;
5151
}
5252

53-
async void RTMSetup()
53+
async void Setup()
5454
{
5555
if (ActiveRepo != null && ActiveRepoUri == null)
5656
{
@@ -64,34 +64,16 @@ async void RTMSetup()
6464
IsVisible = false;
6565
}
6666

67-
async void PreRTMSetup()
68-
{
69-
if (ActiveRepo != null && ActiveRepoUri == null)
70-
{
71-
IsVisible = true;
72-
loggedIn = await connectionManager.IsLoggedIn(hosts);
73-
if (loggedIn)
74-
ShowPublish();
75-
else
76-
{
77-
ShowGetStarted = true;
78-
ShowSignup = true;
79-
}
80-
}
81-
else
82-
IsVisible = false;
83-
}
84-
8567
public override void Initialize(IServiceProvider serviceProvider)
8668
{
8769
base.Initialize(serviceProvider);
88-
RTMSetup();
70+
Setup();
8971
}
9072

9173
protected override void RepoChanged()
9274
{
9375
base.RepoChanged();
94-
RTMSetup();
76+
Setup();
9577
}
9678

9779
public async void Connect()
@@ -135,6 +117,15 @@ void ShowPublish()
135117
disposable = uiflow;
136118
var ui = uiflow.Value;
137119
var creation = ui.SelectFlow(UIControllerFlow.Publish);
120+
ui.ListenToCompletionState().Subscribe(done =>
121+
{
122+
if (done)
123+
{
124+
IsVisible = false;
125+
ServiceProvider.TryGetService<ITeamExplorer>()?.NavigateToPage(new Guid(TeamExplorerPageIds.Home), null);
126+
}
127+
});
128+
138129
creation.Subscribe(c =>
139130
{
140131
SectionContent = c;

src/GitHub.VisualStudio/UI/Views/Controls/RepositoryPublishControl.xaml.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ public RepositoryPublishControl()
4444
d(this.OneWayBind(ViewModel, vm => vm.IsPublishing, v => v.description.IsEnabled, x => x == false));
4545
d(this.OneWayBind(ViewModel, vm => vm.IsPublishing, v => v.accountsComboBox.IsEnabled, x => x == false));
4646

47-
ViewModel.PublishRepository.Subscribe(_ => NotifyDone());
47+
ViewModel.PublishRepository.Subscribe(state =>
48+
{
49+
if (state == ProgressState.Fail)
50+
NotifyCancel();
51+
else
52+
NotifyDone();
53+
});
4854

4955
d(this.WhenAny(x => x.ViewModel.IsPublishing, x => x.Value)
5056
.Subscribe(x => NotifyIsBusy(x)));

src/UnitTests/GitHub.App/ViewModels/RepositoryPublishViewModelTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ public async Task DisplaysSuccessMessageWhenCompletedWithoutError()
339339

340340
vm.RepositoryName = "repo-name";
341341

342-
await vm.PublishRepository.ExecuteAsync().Catch(Observable.Return(Unit.Default));
342+
await vm.PublishRepository.ExecuteAsync().Catch(Observable.Return(ProgressState.Success));
343343

344344
vsServices.Received().ShowMessage("Repository published successfully.");
345345
vsServices.DidNotReceive().ShowError(Args.String);
@@ -358,7 +358,7 @@ public async Task DisplaysRepositoryExistsErrorWithVisualStudioNotifications()
358358
var vm = Helpers.SetupConnectionsAndViewModel(hosts, repositoryPublishService, vsServices, cm);
359359
vm.RepositoryName = "repo-name";
360360

361-
await vm.PublishRepository.ExecuteAsync().Catch(Observable.Return(Unit.Default));
361+
await vm.PublishRepository.ExecuteAsync().Catch(Observable.Return(ProgressState.Fail));
362362

363363
vsServices.DidNotReceive().ShowMessage(Args.String);
364364
vsServices.Received().ShowError("There is already a repository named 'repo-name' for the current account.");
@@ -391,7 +391,7 @@ public async Task ClearsErrorsWhenSwitchingHosts()
391391

392392
vm.RepositoryName = "repo-name";
393393

394-
await vm.PublishRepository.ExecuteAsync().Catch(Observable.Return(Unit.Default));
394+
await vm.PublishRepository.ExecuteAsync().Catch(Observable.Return(ProgressState.Fail));
395395

396396
vm.SelectedConnection = conns.First(x => x != vm.SelectedConnection);
397397

@@ -422,7 +422,7 @@ public async Task ClearsErrorsWhenSwitchingAccounts()
422422

423423
vm.RepositoryName = "repo-name";
424424

425-
await vm.PublishRepository.ExecuteAsync().Catch(Observable.Return(Unit.Default));
425+
await vm.PublishRepository.ExecuteAsync().Catch(Observable.Return(ProgressState.Fail));
426426

427427
vm.SelectedAccount = accounts[1];
428428

0 commit comments

Comments
 (0)