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

Commit 9162006

Browse files
committed
Moved Done and Cancel into view models.
Moved the `Done` and `Cancel` observables out of the views and into the view models. In doing so, moved `IDialogViewModel` into `GitHub.Exports.Reactive` and removed `IReactiveDialogViewModel`.
1 parent ec1952f commit 9162006

File tree

48 files changed

+258
-282
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+258
-282
lines changed

src/GitHub.App/Controllers/UIController.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -525,15 +525,15 @@ void RunView(UIViewType viewType, ViewWithData arg = null)
525525
if (!firstTime)
526526
return;
527527

528-
SetupView(viewType, view);
528+
SetupView(viewType, view.ViewModel);
529529
}
530530

531-
void SetupView(UIViewType viewType, IView view)
531+
void SetupView(UIViewType viewType, IViewModel viewModel)
532532
{
533533
var list = GetObjectsForFlow(activeFlow);
534534
var pair = list[viewType];
535-
var hasDone = view as IHasDone;
536-
var hasCancel = view as IHasCancel;
535+
var hasDone = viewModel as IHasDone;
536+
var hasCancel = viewModel as IHasCancel;
537537

538538
// 2FA is set up when login is set up, so nothing to do
539539
if (viewType == UIViewType.TwoFactor)
@@ -551,7 +551,7 @@ void SetupView(UIViewType viewType, IView view)
551551
.ObserveOn(RxApp.MainThreadScheduler)
552552
.Subscribe(_ => Fire(Trigger.Next)));
553553

554-
pair2fa.AddHandler(((IHasCancel)pair2fa.View).Cancel
554+
pair2fa.AddHandler(((IHasCancel)pair2fa.ViewModel).Cancel
555555
.ObserveOn(RxApp.MainThreadScheduler)
556556
.Subscribe(_ => Fire(uiStateMachine.CanFire(Trigger.Cancel) ? Trigger.Cancel : Trigger.Finish)));
557557

src/GitHub.App/SampleData/LoggedOutViewModelDesigner.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
using System;
22
using System.Diagnostics.CodeAnalysis;
3+
using System.Reactive;
34
using System.Reactive.Linq;
4-
using System.Windows.Input;
5-
using GitHub.Collections;
6-
using GitHub.Models;
75
using GitHub.ViewModels;
86

97
namespace GitHub.SampleData

src/GitHub.App/SampleData/PullRequestCreationViewModelDesigner.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
using GitHub.Models;
55
using GitHub.Validation;
66
using ReactiveUI;
7+
using System;
8+
using System.Reactive;
79

810
namespace GitHub.SampleData
911
{
@@ -46,5 +48,6 @@ public PullRequestCreationViewModelDesigner()
4648

4749
public ReactivePropertyValidator BranchValidator { get; }
4850

51+
public override IObservable<Unit> Done { get; }
4952
}
5053
}

src/GitHub.App/SampleData/SampleViewModels.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ public LicenseItem SelectedLicense
186186
get;
187187
set;
188188
}
189+
190+
public override IObservable<Unit> Done { get; }
189191
}
190192

191193
[ExcludeFromCodeCoverage]
@@ -230,12 +232,6 @@ public bool IsHostComboBoxVisible
230232
}
231233
}
232234

233-
public bool IsPublishing
234-
{
235-
get;
236-
private set;
237-
}
238-
239235
public IReactiveCommand<ProgressState> PublishRepository
240236
{
241237
get;
@@ -423,6 +419,8 @@ public ReactivePropertyValidator<string> BaseRepositoryPathValidator
423419
get;
424420
private set;
425421
}
422+
423+
public override IObservable<Unit> Done { get; }
426424
}
427425

428426
public class GitHubHomeSectionDesigner : IGitHubHomeSection

src/GitHub.App/SampleData/StartPageCloneViewModelDesigner.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ public class StartPageCloneViewModelDesigner : DialogViewModelBase, IBaseCloneVi
1515
public ICommand BrowseForDirectory { get; }
1616
public IReactiveCommand<object> CloneCommand { get; }
1717
public IRepositoryModel SelectedRepository { get; set; }
18+
public override IObservable<Unit> Done { get; }
1819
}
1920
}

src/GitHub.App/Services/DialogService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public Task<CloneDialogResult> ShowCloneDialog([AllowNull] IConnection connectio
3030
{
3131
var vm = x.View.ViewModel as IBaseCloneViewModel;
3232

33-
((IHasDone)x.View).Done.Subscribe(_ =>
33+
((IDialogViewModel)x.View.ViewModel).Done.Subscribe(_ =>
3434
{
3535
basePath = vm?.BaseRepositoryPath;
3636
repository = vm?.SelectedRepository;
@@ -58,7 +58,7 @@ public Task<string> ShowReCloneDialog(IRepositoryModel repository)
5858
vm.SelectedRepository = repository;
5959
}
6060

61-
((IHasDone)x.View).Done.Subscribe(_ =>
61+
((IDialogViewModel)x.View.ViewModel).Done.Subscribe(_ =>
6262
{
6363
basePath = vm?.BaseRepositoryPath;
6464
});

src/GitHub.App/ViewModels/DialogViewModelBase.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
using ReactiveUI;
33
using NullGuard;
44
using GitHub.UI;
5+
using System;
6+
using System.Reactive;
7+
using GitHub.Extensions.Reactive;
58

69
namespace GitHub.ViewModels
710
{
811
/// <summary>
912
/// Base class for view models that can be dismissed, such as dialogs.
1013
/// </summary>
11-
public class DialogViewModelBase : ReactiveObject, IReactiveDialogViewModel, IHasBusy
14+
public abstract class DialogViewModelBase : ReactiveObject, IDialogViewModel, IHasBusy
1215
{
1316
protected ObservableAsPropertyHelper<bool> isShowing;
1417
string title;
@@ -19,14 +22,14 @@ public class DialogViewModelBase : ReactiveObject, IReactiveDialogViewModel, IHa
1922
/// </summary>
2023
protected DialogViewModelBase()
2124
{
22-
CancelCommand = ReactiveCommand.Create();
25+
Cancel = ReactiveCommand.Create();
2326
}
2427

2528
/// <inheritdoc/>
26-
public IReactiveCommand<object> CancelCommand { get; protected set; }
29+
public abstract IObservable<Unit> Done { get; }
2730

2831
/// <inheritdoc/>
29-
public ICommand Cancel { get { return CancelCommand; } }
32+
public ReactiveCommand<object> Cancel { get; }
3033

3134
/// <inheritdoc/>
3235
public string Title
@@ -46,6 +49,9 @@ public bool IsBusy
4649
set { this.RaiseAndSetIfChanged(ref isBusy, value); }
4750
}
4851

52+
/// <inheritdoc/>
53+
IObservable<Unit> IHasCancel.Cancel => Cancel.SelectUnit();
54+
4955
/// <inheritdoc/>
5056
public virtual void Initialize([AllowNull] ViewWithData data)
5157
{

src/GitHub.App/ViewModels/GistCreationViewModel.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
using System;
22
using System.ComponentModel.Composition;
33
using System.Linq;
4+
using System.Reactive;
45
using System.Reactive.Linq;
56
using GitHub.Api;
67
using GitHub.App;
78
using GitHub.Exports;
89
using GitHub.Extensions;
10+
using GitHub.Extensions.Reactive;
911
using GitHub.Models;
1012
using GitHub.Services;
1113
using NLog;
@@ -132,5 +134,7 @@ public string FileName
132134
get { return fileName; }
133135
set { this.RaiseAndSetIfChanged(ref fileName, value); }
134136
}
137+
138+
public override IObservable<Unit> Done => CreateGist.Where(x => x != null).SelectUnit();
135139
}
136140
}

src/GitHub.App/ViewModels/LoginControlViewModel.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using System;
22
using System.ComponentModel.Composition;
3+
using System.Reactive;
34
using System.Reactive.Linq;
45
using GitHub.App;
56
using GitHub.Authentication;
67
using GitHub.Exports;
8+
using GitHub.Extensions.Reactive;
79
using GitHub.Models;
810
using ReactiveUI;
911

@@ -78,6 +80,11 @@ public IRepositoryHosts RepositoryHosts
7880
public bool IsLoginInProgress { get { return isLoginInProgress.Value; } }
7981

8082
public IObservable<AuthenticationResult> AuthenticationResults { get; private set; }
83+
84+
public override IObservable<Unit> Done
85+
{
86+
get { return AuthenticationResults.Where(x => x == AuthenticationResult.Success).SelectUnit(); }
87+
}
8188
}
8289

8390
public enum LoginTarget

src/GitHub.App/ViewModels/LogoutRequiredViewModel.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
using ReactiveUI;
1515
using System.Diagnostics;
1616
using System.Globalization;
17+
using System.Reactive;
18+
using GitHub.Extensions.Reactive;
1719

1820
namespace GitHub.ViewModels
1921
{
@@ -53,6 +55,11 @@ public override void Initialize([AllowNull] ViewWithData data)
5355

5456
public IReactiveCommand<ProgressState> Logout { get; }
5557

58+
public override IObservable<Unit> Done
59+
{
60+
get { return Logout.Where(x => x == ProgressState.Success).SelectUnit(); }
61+
}
62+
5663
IObservable<ProgressState> OnLogout(object unused)
5764
{
5865
return DoLogout().ToObservable()

0 commit comments

Comments
 (0)