Navigate to Main Page
Some checks failed
Dotnet build and test / log-the-inputs (pull_request) Has been cancelled
Dotnet build and test / build (pull_request) Has been cancelled

This commit is contained in:
Paul Schneider 2026-08-02 21:08:25 +01:00
commit 286c29f4e3
6 changed files with 24 additions and 16 deletions

View file

@ -25,7 +25,7 @@ public partial class App : Application
/// <c>DataValidationErrors.SetErrors</c>.
/// </summary>
public IServiceProvider? Services { get; private set; }
private MainWindow window;
public App()
{
}
@ -137,7 +137,7 @@ public partial class App : Application
var homePage = provider.GetRequiredService<HomePage>();
homePage.DataContext = provider.GetRequiredService<HomePageViewModel>();
var window = new MainWindow();
window = new MainWindow();
window.SessionBanner.DataContext = sessionStatus;
// Build the navigation stack from scratch: HomePage is the
@ -165,7 +165,7 @@ public partial class App : Application
sessionStatus.LoginSucceeded += () =>
{
var w = (MainWindow)((IClassicDesktopStyleApplicationLifetime)ApplicationLifetime!).MainWindow!;
_ = PushMainPageAsync(provider, w);
_ = PushMainPageAsync();
};
// When the user clicks the "Paramètres" button on the
@ -196,7 +196,7 @@ public partial class App : Application
_ = w.NavRoot.PushAsync(settingsPage);
};
window.Opened += async (_, _) => await BootAsync(provider, api, window);
window.Opened += async (_, _) => await BootAsync(provider, api);
}
else if (ApplicationLifetime is ISingleViewApplicationLifetime singleView)
{
@ -223,15 +223,14 @@ public partial class App : Application
/// </summary>
private static async Task BootAsync(
IServiceProvider provider,
YavscApiClient api,
MainWindow window)
YavscApiClient api)
{
var refreshed = await api.TrySilentLoginAsync().ConfigureAwait(true);
var sessionStatus = provider.GetRequiredService<SessionStatusViewModel>();
sessionStatus.Refresh();
if (!refreshed) return;
await PushMainPageAsync(provider, window).ConfigureAwait(true);
await PushMainPageAsync().ConfigureAwait(true);
}
/// <summary>
@ -241,12 +240,13 @@ public partial class App : Application
/// (interactive login from the banner). Pulled out as a helper so
/// the two callers can't drift apart.
/// </summary>
private static async Task PushMainPageAsync(IServiceProvider provider, MainWindow window)
public static async Task PushMainPageAsync()
{
var mainVm = provider.GetRequiredService<MainPageViewModel>();
var mainPage = provider.GetRequiredService<MainPage>();
var app = (App)Current;
var mainVm = app.Services.GetRequiredService<MainPageViewModel>();
var mainPage = app.Services.GetRequiredService<MainPage>();
mainPage.DataContext = mainVm;
await window.NavRoot.PushAsync(mainPage).ConfigureAwait(true);
await app.window.FindControl<NavigationPage>("NavRoot").PushAsync(mainPage).ConfigureAwait(true);
}
private bool TryHandOffCustomSchemeUrl()

View file

@ -1,6 +1,7 @@
using CommunityToolkit.Mvvm.Input;
using PostIt;
using PostIt.Services;
using PostIt.ViewModels;
namespace PostIt.ViewModels;
public class HomePageViewModel : ViewModelBase
{
@ -22,7 +23,7 @@ public class HomePageViewModel : ViewModelBase
Api = api;
Settings = settings;
}
public RelayCommand OpenBlogs { get; set; } = new RelayCommand(() => App.PushMainPageAsync());
/// <summary>
/// Avalonia designer constructor. Builds a self-contained VM
/// with a freshly-constructed Settings so the XAML preview can

View file

@ -1,7 +1,12 @@
<ContentPage xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:PostIt.ViewModels"
x:Class="PostIt.Views.HomePage"
x:DataType="vm:HomePageViewModel"
Header="Home">
<Design.DataContext>
<vm:HomePageViewModel />
</Design.DataContext>
<StackPanel HorizontalAlignment="Center"
VerticalAlignment="Center"
Spacing="12">
@ -9,5 +14,8 @@
FontSize="22"
FontWeight="SemiBold"
HorizontalAlignment="Center"/>
<Button Content="Open Blog Interface"
Command="{Binding OpenBlogs}"
HorizontalAlignment="Center"/>
</StackPanel>
</ContentPage>

View file

@ -27,7 +27,6 @@
<StackPanel Grid.Row="0" Spacing="12"
HorizontalAlignment="Stretch"
VerticalAlignment="Top">
<TextBlock Text="PostIt Blog API Interface" FontSize="20" FontWeight="Bold" />
<StackPanel Orientation="Horizontal" Spacing="8">
<Button Command="{Binding LoadPosts}" Content="Load posts" />
@ -93,4 +92,4 @@
</Grid>
</Border>
</Grid>
</ContentPage>
</ContentPage>

View file

@ -20,7 +20,7 @@
-->
<DockPanel LastChildFill="True">
<views:SessionStatusBanner x:Name="SessionBanner"
DockPanel.Dock="Top"/>
DockPanel.Dock="Bottom"/>
<NavigationPage x:Name="NavRoot"/>
</DockPanel>