From 0308f17db70e5a66e0e2e59b87a810c81f9a3546 Mon Sep 17 00:00:00 2001 From: erri120 Date: Wed, 20 Sep 2023 15:56:36 +0200 Subject: [PATCH 01/15] Update TopBar controls --- .../Controls/TopBar/TopBarDesignViewModel.cs | 25 +++++++---------- .../Controls/TopBar/TopBarView.axaml | 4 +-- .../Controls/TopBar/TopBarView.axaml.cs | 27 +++++++++---------- .../Controls/TopBar/TopBarViewModel.cs | 26 +++++++++++------- src/NexusMods.App.UI/NexusMods.App.UI.csproj | 6 +++++ 5 files changed, 46 insertions(+), 42 deletions(-) diff --git a/src/NexusMods.App.UI/Controls/TopBar/TopBarDesignViewModel.cs b/src/NexusMods.App.UI/Controls/TopBar/TopBarDesignViewModel.cs index efe98bdd90..5e531c72ff 100644 --- a/src/NexusMods.App.UI/Controls/TopBar/TopBarDesignViewModel.cs +++ b/src/NexusMods.App.UI/Controls/TopBar/TopBarDesignViewModel.cs @@ -1,4 +1,5 @@ using System.Reactive; +using System.Reactive.Disposables; using System.Reactive.Linq; using Avalonia.Media; using Avalonia.Media.Imaging; @@ -16,17 +17,13 @@ public class TopBarDesignViewModel : AViewModel, ITopBarViewMo [Reactive] public bool IsLoggedIn { get; set; } - [Reactive] - public bool IsPremium { get; set; } + [Reactive] public bool IsPremium { get; set; } = true; - [Reactive] - public IImage Avatar { get; set; } + [Reactive] public IImage Avatar { get; set; } = new Bitmap(AssetLoader.Open(new Uri("avares://NexusMods.App.UI/Assets/DesignTime/cyberpunk_game.png"))); - [Reactive] - public ReactiveCommand LoginCommand { get; set; } + [Reactive] public ReactiveCommand LoginCommand { get; set; } = Initializers.EnabledReactiveCommand; - [Reactive] - public ReactiveCommand LogoutCommand { get; set; } + [Reactive] public ReactiveCommand LogoutCommand { get; set; } = Initializers.EnabledReactiveCommand; [Reactive] public ReactiveCommand MinimizeCommand { get; set; } = ReactiveCommand.Create(() => { }); @@ -38,13 +35,11 @@ public class TopBarDesignViewModel : AViewModel, ITopBarViewMo public TopBarDesignViewModel() { - Avatar = new Bitmap(AssetLoader.Open(new Uri("avares://NexusMods.App.UI/Assets/DesignTime/cyberpunk_game.png"))); - IsLoggedIn = false; - IsPremium = true; - - LogoutCommand = ReactiveCommand.Create(ToggleLogin, this.WhenAnyValue(vm => vm.IsLoggedIn)); - LoginCommand = ReactiveCommand.Create(ToggleLogin, this.WhenAnyValue(vm => vm.IsLoggedIn) - .Select(x => !x)); + this.WhenActivated(disposables => + { + LogoutCommand = ReactiveCommand.Create(ToggleLogin, this.WhenAnyValue(vm => vm.IsLoggedIn)).DisposeWith(disposables); + LoginCommand = ReactiveCommand.Create(ToggleLogin, this.WhenAnyValue(vm => vm.IsLoggedIn).Select(x => !x)).DisposeWith(disposables); + }); } private void ToggleLogin() diff --git a/src/NexusMods.App.UI/Controls/TopBar/TopBarView.axaml b/src/NexusMods.App.UI/Controls/TopBar/TopBarView.axaml index 632af15331..c1a8efd19b 100644 --- a/src/NexusMods.App.UI/Controls/TopBar/TopBarView.axaml +++ b/src/NexusMods.App.UI/Controls/TopBar/TopBarView.axaml @@ -26,7 +26,7 @@ Path="avares://NexusMods.App.UI/Assets/nexus-logo-with-text.svg" VerticalAlignment="Center"/> -