petit refacto

This commit is contained in:
Paul Schneider 2026-06-28 01:43:39 +01:00
commit 2f7df74000
2 changed files with 26 additions and 22 deletions

View file

@ -1,5 +1,6 @@
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
using Avalonia.Styling;
@ -50,17 +51,20 @@ public partial class MainPageViewModel : ViewModelBase
/// <c>App.axaml.cs</c> so the same client (and its token store)
/// is shared with the login flow.
/// </summary>
public BlogApiClient BlogClient { get; }
public BlogApiClient? BlogClient { get; }
public override bool CanNavigateNext { get => throw new NotImplementedException(); protected set => throw new NotImplementedException(); }
public override bool CanNavigatePrevious { get => throw new NotImplementedException(); protected set => throw new NotImplementedException(); }
/// <summary>
/// Test-friendly constructor: caller supplies a pre-built
/// <see cref="BlogApiClient"/>. Production code uses the
/// (Settings, BlogApiClient) overload below.
/// </summary>
public MainPageViewModel(BlogApiClient blogClient, Settings? settings = null)
public MainPageViewModel()
{
Init(null);
SettingsModel = new SettingsPageViewModel();
BlogClient = null;
}
private void Init(Settings? settings)
{
SearchText = string.Empty;
Posts = new ObservableCollection<BlogPost>();
@ -71,10 +75,21 @@ public partial class MainPageViewModel : ViewModelBase
Settings = settings ?? new Settings();
Title = "PostIt";
CurrentViewModel = this;
SettingsModel = new SettingsPageViewModel();
BlogClient = blogClient ?? throw new ArgumentNullException(nameof(blogClient));
}
/// <summary>
/// Test-friendly constructor: caller supplies a pre-built
/// <see cref="BlogApiClient"/>. Production code uses the
/// (Settings, BlogApiClient) overload below.
/// </summary>
public MainPageViewModel(BlogApiClient blogClient, Settings? settings = null)
{
SettingsModel = new SettingsPageViewModel();
BlogClient = blogClient ?? throw new ArgumentNullException(nameof(blogClient));;
Init(settings);
}
partial void OnSearchTextChanged(string value) => ApplyFilter();
partial void OnSelectedPostChanged(BlogPost? value) => UpdateCommandStates();

View file

@ -5,10 +5,10 @@
x:DataType="vm:LoginPageViewModel"
Header="Login">
<Design.DataContext>
<vm:LoginPageViewModel />
<vm:MainPageViewModel />
</Design.DataContext>
<StackPanel HorizontalAlignment="Center"
<StackPanel HorizontalAlignment="Stretch"
VerticalAlignment="Center"
Spacing="20">
@ -27,18 +27,7 @@
FontSize="24"
HorizontalAlignment="Center"/>
<StackPanel Spacing="4">
<TextBlock Text="Email"/>
<TextBox Name="EmailBox"
PlaceholderText="Enter your email"/>
</StackPanel>
<StackPanel Spacing="4">
<TextBlock Text="Password"/>
<TextBox Name="PasswordBox"
PlaceholderText="Enter your password"
PasswordChar="•"/>
</StackPanel>
<Button Content="Login"
Command="{Binding LoginAsync}"/>