petit refacto
This commit is contained in:
parent
fd6d6ab2d8
commit
2f7df74000
2 changed files with 26 additions and 22 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Avalonia.Styling;
|
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)
|
/// <c>App.axaml.cs</c> so the same client (and its token store)
|
||||||
/// is shared with the login flow.
|
/// is shared with the login flow.
|
||||||
/// </summary>
|
/// </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 CanNavigateNext { get => throw new NotImplementedException(); protected set => throw new NotImplementedException(); }
|
||||||
public override bool CanNavigatePrevious { 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
|
public MainPageViewModel()
|
||||||
/// <see cref="BlogApiClient"/>. Production code uses the
|
{
|
||||||
/// (Settings, BlogApiClient) overload below.
|
Init(null);
|
||||||
/// </summary>
|
SettingsModel = new SettingsPageViewModel();
|
||||||
public MainPageViewModel(BlogApiClient blogClient, Settings? settings = null)
|
BlogClient = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Init(Settings? settings)
|
||||||
{
|
{
|
||||||
SearchText = string.Empty;
|
SearchText = string.Empty;
|
||||||
Posts = new ObservableCollection<BlogPost>();
|
Posts = new ObservableCollection<BlogPost>();
|
||||||
|
|
@ -71,10 +75,21 @@ public partial class MainPageViewModel : ViewModelBase
|
||||||
Settings = settings ?? new Settings();
|
Settings = settings ?? new Settings();
|
||||||
Title = "PostIt";
|
Title = "PostIt";
|
||||||
CurrentViewModel = this;
|
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 OnSearchTextChanged(string value) => ApplyFilter();
|
||||||
|
|
||||||
partial void OnSelectedPostChanged(BlogPost? value) => UpdateCommandStates();
|
partial void OnSelectedPostChanged(BlogPost? value) => UpdateCommandStates();
|
||||||
|
|
@ -5,10 +5,10 @@
|
||||||
x:DataType="vm:LoginPageViewModel"
|
x:DataType="vm:LoginPageViewModel"
|
||||||
Header="Login">
|
Header="Login">
|
||||||
<Design.DataContext>
|
<Design.DataContext>
|
||||||
<vm:LoginPageViewModel />
|
<vm:MainPageViewModel />
|
||||||
</Design.DataContext>
|
</Design.DataContext>
|
||||||
|
|
||||||
<StackPanel HorizontalAlignment="Center"
|
<StackPanel HorizontalAlignment="Stretch"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
Spacing="20">
|
Spacing="20">
|
||||||
|
|
||||||
|
|
@ -27,18 +27,7 @@
|
||||||
FontSize="24"
|
FontSize="24"
|
||||||
HorizontalAlignment="Center"/>
|
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"
|
<Button Content="Login"
|
||||||
Command="{Binding LoginAsync}"/>
|
Command="{Binding LoginAsync}"/>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue