Skip to content

Commit b8bc335

Browse files
authored
Merge pull request #2857 from erri120/fix/2062
Reset login requests
2 parents 1b05bb1 + 48e9385 commit b8bc335

File tree

4 files changed

+40
-34
lines changed

4 files changed

+40
-34
lines changed

src/NexusMods.App.UI/Controls/TopBar/ITopBarViewModel.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public interface ITopBarViewModel : IViewModelInterface
2424
public ReactiveCommand<Unit, Unit> OpenGitHubCommand { get; }
2525
public ReactiveCommand<Unit, Unit> OpenStatusPageCommand { get; }
2626

27-
public ReactiveCommand<Unit, Unit> LoginCommand { get; }
27+
public R3.ReactiveCommand<R3.Unit, R3.Unit> LoginCommand { get; }
2828
public ReactiveCommand<Unit, Unit> LogoutCommand { get; }
2929
public ReactiveCommand<Unit, Unit> OpenNexusModsProfileCommand { get; }
3030
public ReactiveCommand<Unit, Unit> OpenNexusModsPremiumCommand { get; }

src/NexusMods.App.UI/Controls/TopBar/TopBarDesignViewModel.cs

+23-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Reactive;
21
using System.Reactive.Linq;
32
using Avalonia.Media;
43
using Avalonia.Media.Imaging;
@@ -7,8 +6,12 @@
76
using NexusMods.Abstractions.UI;
87
using NexusMods.App.UI.Controls.Navigation;
98
using NexusMods.App.UI.WorkspaceSystem;
9+
using R3;
1010
using ReactiveUI;
1111
using ReactiveUI.Fody.Helpers;
12+
using Observable = R3.Observable;
13+
using ReactiveCommand = ReactiveUI.ReactiveCommand;
14+
using Unit = System.Reactive.Unit;
1215

1316
namespace NexusMods.App.UI.Controls.TopBar;
1417

@@ -23,28 +26,33 @@ public class TopBarDesignViewModel : AViewModel<ITopBarViewModel>, ITopBarViewMo
2326

2427
[Reactive] public IAddPanelDropDownViewModel AddPanelDropDownViewModel { get; set; } = new AddPanelDropDownDesignViewModel();
2528

26-
public ReactiveCommand<NavigationInformation, Unit> OpenSettingsCommand => ReactiveCommand.Create<NavigationInformation, Unit>(_ => Unit.Default);
29+
public ReactiveUI.ReactiveCommand<NavigationInformation, Unit> OpenSettingsCommand => ReactiveCommand.Create<NavigationInformation, Unit>(_ => Unit.Default);
2730

28-
public ReactiveCommand<NavigationInformation, Unit> ViewChangelogCommand => ReactiveCommand.Create<NavigationInformation, Unit>(_ => Unit.Default);
29-
public ReactiveCommand<Unit, Unit> ViewAppLogsCommand => Initializers.DisabledReactiveCommand;
30-
public ReactiveCommand<Unit, Unit> ShowWelcomeMessageCommand => Initializers.EnabledReactiveCommand;
31-
public ReactiveCommand<Unit, Unit> OpenDiscordCommand => ReactiveCommand.Create(() => {});
32-
public ReactiveCommand<Unit, Unit> OpenForumsCommand => ReactiveCommand.Create(() => {});
33-
public ReactiveCommand<Unit, Unit> OpenGitHubCommand => ReactiveCommand.Create(() => {});
34-
public ReactiveCommand<Unit, Unit> OpenStatusPageCommand => ReactiveCommand.Create(() => {});
31+
public ReactiveUI.ReactiveCommand<NavigationInformation, Unit> ViewChangelogCommand => ReactiveCommand.Create<NavigationInformation, Unit>(_ => Unit.Default);
32+
public ReactiveUI.ReactiveCommand<Unit, Unit> ViewAppLogsCommand => Initializers.DisabledReactiveCommand;
33+
public ReactiveUI.ReactiveCommand<Unit, Unit> ShowWelcomeMessageCommand => Initializers.EnabledReactiveCommand;
34+
public ReactiveUI.ReactiveCommand<Unit, Unit> OpenDiscordCommand => ReactiveCommand.Create(() => {});
35+
public ReactiveUI.ReactiveCommand<Unit, Unit> OpenForumsCommand => ReactiveCommand.Create(() => {});
36+
public ReactiveUI.ReactiveCommand<Unit, Unit> OpenGitHubCommand => ReactiveCommand.Create(() => {});
37+
public ReactiveUI.ReactiveCommand<Unit, Unit> OpenStatusPageCommand => ReactiveCommand.Create(() => {});
3538

36-
public ReactiveCommand<Unit, Unit> LoginCommand { get; set; }
37-
public ReactiveCommand<Unit, Unit> LogoutCommand { get; set; }
38-
public ReactiveCommand<Unit, Unit> OpenNexusModsProfileCommand => Initializers.DisabledReactiveCommand;
39-
public ReactiveCommand<Unit, Unit> OpenNexusModsPremiumCommand => Initializers.EnabledReactiveCommand;
40-
public ReactiveCommand<Unit, Unit> OpenNexusModsAccountSettingsCommand => Initializers.DisabledReactiveCommand;
39+
public R3.ReactiveCommand<R3.Unit, R3.Unit> LoginCommand { get; set; }
40+
public ReactiveUI.ReactiveCommand<Unit, Unit> LogoutCommand { get; set; }
41+
public ReactiveUI.ReactiveCommand<Unit, Unit> OpenNexusModsProfileCommand => Initializers.DisabledReactiveCommand;
42+
public ReactiveUI.ReactiveCommand<Unit, Unit> OpenNexusModsPremiumCommand => Initializers.EnabledReactiveCommand;
43+
public ReactiveUI.ReactiveCommand<Unit, Unit> OpenNexusModsAccountSettingsCommand => Initializers.DisabledReactiveCommand;
4144

4245
public IPanelTabViewModel? SelectedTab { get; set; }
4346

4447
public TopBarDesignViewModel()
4548
{
4649
LogoutCommand = ReactiveCommand.Create(ToggleLogin, this.WhenAnyValue(vm => vm.IsLoggedIn));
47-
LoginCommand = ReactiveCommand.Create(ToggleLogin, this.WhenAnyValue(vm => vm.IsLoggedIn).Select(x => !x));
50+
LoginCommand = ReactiveCommandExtensions.ToReactiveCommand<R3.Unit, R3.Unit>(Observable.ToObservable(this.WhenAnyValue(vm => vm.IsLoggedIn).Select(x => !x)), convert:
51+
_ =>
52+
{
53+
ToggleLogin();
54+
return R3.Unit.Default;
55+
});
4856
}
4957

5058
private void ToggleLogin()

src/NexusMods.App.UI/Controls/TopBar/TopBarViewModel.cs

+8-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
using NexusMods.App.UI.WorkspaceSystem;
2121
using NexusMods.CrossPlatform;
2222
using NexusMods.CrossPlatform.Process;
23-
using NexusMods.DataModel.Extensions;
2423
using NexusMods.Paths;
2524
using NexusMods.Telemetry;
2625
using R3;
@@ -49,7 +48,7 @@ public class TopBarViewModel : AViewModel<ITopBarViewModel>, ITopBarViewModel
4948
public ReactiveUI.ReactiveCommand<Unit, Unit> OpenForumsCommand { get; }
5049
public ReactiveUI.ReactiveCommand<Unit, Unit> OpenGitHubCommand { get; }
5150
public ReactiveUI.ReactiveCommand<Unit, Unit> OpenStatusPageCommand { get; }
52-
public ReactiveUI.ReactiveCommand<Unit, Unit> LoginCommand { get; }
51+
public R3.ReactiveCommand<R3.Unit, R3.Unit> LoginCommand { get; }
5352
public ReactiveUI.ReactiveCommand<Unit, Unit> LogoutCommand { get; }
5453
public ReactiveUI.ReactiveCommand<Unit, Unit> OpenNexusModsProfileCommand { get; }
5554
public ReactiveUI.ReactiveCommand<Unit, Unit> OpenNexusModsPremiumCommand { get; }
@@ -129,9 +128,13 @@ public TopBarViewModel(
129128
overlayController.Enqueue(alphaWarningViewModel);
130129
Tracking.AddEvent(Events.Help.GiveFeedback, metadata: new EventMetadata(name: null));
131130
});
132-
133-
var canLogin = this.WhenAnyValue(x => x.IsLoggedIn).Select(isLoggedIn => !isLoggedIn);
134-
LoginCommand = ReactiveCommand.CreateFromTask(Login, canLogin);
131+
132+
var canLogin = this.WhenAnyValue(x => x.IsLoggedIn).Select(isLoggedIn => !isLoggedIn).ToObservable();
133+
LoginCommand = canLogin.ToReactiveCommand<R3.Unit, R3.Unit>(async (_, _) =>
134+
{
135+
await Login();
136+
return R3.Unit.Default;
137+
}, awaitOperation: AwaitOperation.Parallel, configureAwait: false);
135138

136139
var canLogout = this.WhenAnyValue(x => x.IsLoggedIn);
137140
LogoutCommand = ReactiveCommand.CreateFromTask(Logout, canLogout);

src/NexusMods.App.UI/Overlays/Login/NexusLoginOverlayService.cs

+8-13
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ public class NexusLoginOverlayService : IHostedService
1515
private readonly CompositeDisposable _compositeDisposable;
1616

1717
private NexusLoginOverlayViewModel? _overlayViewModel;
18-
private IJob? _currentJob;
1918

2019
public NexusLoginOverlayService(IOverlayController overlayController, IJobMonitor jobMonitor)
2120
{
@@ -31,21 +30,18 @@ public Task StartAsync(CancellationToken cancellationToken)
3130
.OnUI()
3231
.SubscribeWithErrorLogging(changeSet =>
3332
{
34-
if (changeSet.Removes > 0 && _currentJob is not null)
35-
{
36-
if (changeSet.Any(x => x.Reason == ChangeReason.Remove && x.Current == _currentJob))
37-
{
38-
_currentJob = null;
39-
_overlayViewModel?.Close();
40-
}
41-
}
33+
if (changeSet.Removes > 0) _overlayViewModel?.Close();
4234

4335
if (changeSet.Adds > 0)
4436
{
45-
if (_currentJob is not null) return;
37+
if (_overlayViewModel is not null)
38+
{
39+
_overlayViewModel.Close();
40+
_overlayViewModel = null;
41+
}
4642

47-
_currentJob = changeSet.First(x => x.Reason == ChangeReason.Add).Current;
48-
_overlayViewModel = new NexusLoginOverlayViewModel(_currentJob);
43+
var job = changeSet.First(x => x.Reason == ChangeReason.Add).Current;
44+
_overlayViewModel = new NexusLoginOverlayViewModel(job);
4945

5046
_overlayController.Enqueue(_overlayViewModel);
5147
}
@@ -57,7 +53,6 @@ public Task StartAsync(CancellationToken cancellationToken)
5753

5854
public Task StopAsync(CancellationToken cancellationToken)
5955
{
60-
_currentJob = null;
6156
_overlayViewModel?.Close();
6257

6358
_compositeDisposable.Dispose();

0 commit comments

Comments
 (0)