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

Commit 0962668

Browse files
authored
Merge pull request #364 from github/fixes/354-github-pane-signin-register-2
Make "Sign in"/"Create an account" links in GitHub pane work.
2 parents f8dd285 + 004f5f5 commit 0962668

File tree

10 files changed

+103
-22
lines changed

10 files changed

+103
-22
lines changed

src/GitHub.App/GitHub.App.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@
198198
<Compile Include="ViewModels\BaseViewModel.cs" />
199199
<Compile Include="Models\ConnectionRepositoryHostMap.cs" />
200200
<Compile Include="ViewModels\GistCreationViewModel.cs" />
201+
<Compile Include="ViewModels\LoggedOutViewModel.cs" />
201202
<Compile Include="ViewModels\LogoutRequiredViewModel.cs" />
202203
<Compile Include="ViewModels\PullRequestCreationViewModel.cs" />
203204
<Compile Include="ViewModels\PullRequestDetailViewModel.cs" />

src/GitHub.App/Models/RepositoryHosts.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,20 @@ public IObservable<AuthenticationResult> LogIn(
157157
);
158158
if (successful)
159159
{
160+
// Make sure that GitHubHost/EnterpriseHost are set when the connections
161+
// changed event is raised and likewise that the connection is added when
162+
// the property changed notification is sent.
160163
if (isDotCom)
161-
GitHubHost = host;
164+
githubHost = host;
162165
else
163-
EnterpriseHost = host;
166+
enterpriseHost = host;
167+
164168
connectionManager.AddConnection(address, usernameOrEmail);
169+
170+
if (isDotCom)
171+
this.RaisePropertyChanged(nameof(GitHubHost));
172+
else
173+
this.RaisePropertyChanged(nameof(EnterpriseHost));
165174
}
166175
});
167176
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using System;
2+
using System.ComponentModel.Composition;
3+
using System.Reactive.Linq;
4+
using GitHub.Exports;
5+
using GitHub.Info;
6+
using GitHub.Services;
7+
using GitHub.UI;
8+
using ReactiveUI;
9+
10+
namespace GitHub.ViewModels
11+
{
12+
/// <summary>
13+
/// The view model for the "Sign in to GitHub" view in the GitHub pane.
14+
/// </summary>
15+
[ExportViewModel(ViewType = UIViewType.LoggedOut)]
16+
[PartCreationPolicy(CreationPolicy.NonShared)]
17+
public class LoggedOutViewModel : BaseViewModel, ILoggedOutViewModel
18+
{
19+
IUIProvider uiProvider;
20+
IVisualStudioBrowser browser;
21+
22+
/// <summary>
23+
/// Initializes a new instance of the <see cref="LoggedOutViewModel"/> class.
24+
/// </summary>
25+
[ImportingConstructor]
26+
public LoggedOutViewModel(IUIProvider uiProvider, IVisualStudioBrowser browser)
27+
{
28+
this.uiProvider = uiProvider;
29+
this.browser = browser;
30+
SignIn = ReactiveCommand.Create();
31+
SignIn.Subscribe(_ => OnSignIn());
32+
Register = ReactiveCommand.Create();
33+
Register.Subscribe(_ => OnRegister());
34+
}
35+
36+
/// <inheritdoc/>
37+
public IReactiveCommand<object> SignIn { get; }
38+
39+
/// <inheritdoc/>
40+
public IReactiveCommand<object> Register { get; }
41+
42+
/// <summary>
43+
/// Called when the <see cref="SignIn"/> command is executed.
44+
/// </summary>
45+
void OnSignIn()
46+
{
47+
// Show the Sign In dialog. We don't need to listen to the outcome of this: the parent
48+
// GitHubPaneViewModel will listen to RepositoryHosts.IsLoggedInToAnyHost and close
49+
// this view when the user logs in.
50+
uiProvider.SetupUI(UIControllerFlow.Authentication, null);
51+
uiProvider.RunUI();
52+
}
53+
54+
/// <summary>
55+
/// Called when the <see cref="Register"/> command is executed.
56+
/// </summary>
57+
void OnRegister()
58+
{
59+
browser.OpenUrl(GitHubUrls.Pricing);
60+
}
61+
}
62+
}

src/GitHub.Exports.Reactive/GitHub.Exports.Reactive.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
<Compile Include="Services\IGistPublishService.cs" />
9898
<Compile Include="ViewModels\IGistCreationViewModel.cs" />
9999
<Compile Include="Services\NotificationDispatcher.cs" />
100+
<Compile Include="ViewModels\ILoggedOutViewModel.cs" />
100101
<Compile Include="ViewModels\ILogoutRequiredViewModel.cs" />
101102
<Compile Include="ViewModels\ILoginControlViewModel.cs" />
102103
<Compile Include="ViewModels\ILoginToGitHubForEnterpriseViewModel.cs" />
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Reactive;
3+
using ReactiveUI;
4+
5+
namespace GitHub.ViewModels
6+
{
7+
/// <summary>
8+
/// Defines the view model for the "Sign in to GitHub" view in the GitHub pane.
9+
/// </summary>
10+
public interface ILoggedOutViewModel : IViewModel
11+
{
12+
/// <summary>
13+
/// Gets the command executed when the user clicks the "Sign in" link.
14+
/// </summary>
15+
IReactiveCommand<object> SignIn { get; }
16+
17+
/// <summary>
18+
/// Gets the command executed when the user clicks the "Create an Account" link.
19+
/// </summary>
20+
IReactiveCommand<object> Register { get; }
21+
}
22+
}

src/GitHub.VisualStudio/GitHub.VisualStudio.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,6 @@
273273
<Compile Include="UI\Views\GitHubPaneView.xaml.cs">
274274
<DependentUpon>GitHubPaneView.xaml</DependentUpon>
275275
</Compile>
276-
<Compile Include="UI\Views\LoggedOutViewModel.cs" />
277276
<Compile Include="UI\Views\GitHubPaneViewModel.cs" />
278277
<Compile Include="UI\Views\LoggedOutView.xaml.cs">
279278
<DependentUpon>LoggedOutView.xaml</DependentUpon>

src/GitHub.VisualStudio/UI/Views/GitHubPaneViewModel.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ public GitHubPaneViewModel(ISimpleApiClientFactory apiFactory, ITeamExplorerServ
5151
syncContext = SynchronizationContext.Current;
5252
CancelCommand = ReactiveCommand.Create();
5353
Title = "GitHub";
54+
55+
hosts.WhenAnyValue(x => x.IsLoggedInToAnyHost).Subscribe(_ => Reload().Forget());
5456
}
5557

5658
public override void Initialize(IServiceProvider serviceProvider)
@@ -140,6 +142,7 @@ async Task Reload([AllowNull] ViewWithData data = null, bool navigating = false)
140142
{
141143
var factory = ServiceProvider.GetExportedValue<IUIFactory>();
142144
var c = factory.CreateViewAndViewModel(UIViewType.LoggedOut);
145+
c.View.DataContext = c.ViewModel;
143146
Control = c.View;
144147
}
145148
return;

src/GitHub.VisualStudio/UI/Views/LoggedOutView.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@
5353
<TextBlock
5454
Margin="10,0"
5555
HorizontalAlignment="Center">
56-
<Hyperlink>Sign in</Hyperlink>
56+
<Hyperlink Command="{Binding SignIn}">Sign in</Hyperlink>
5757
</TextBlock>
5858

5959
<TextBlock
6060
Margin="10,0"
6161
HorizontalAlignment="Center">
62-
<Hyperlink>Create an account</Hyperlink>
62+
<Hyperlink Command="{Binding Register}">Create an account</Hyperlink>
6363
</TextBlock>
6464
</StackPanel>
6565
</StackPanel>

src/GitHub.VisualStudio/UI/Views/LoggedOutView.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace GitHub.VisualStudio.UI.Views
88
{
9-
public class GenericLoggedOutView : SimpleViewUserControl<IViewModel, GenericLoggedOutView>
9+
public class GenericLoggedOutView : SimpleViewUserControl<ILoggedOutViewModel, GenericLoggedOutView>
1010
{
1111
}
1212

src/GitHub.VisualStudio/UI/Views/LoggedOutViewModel.cs

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)