Navigate to Main Page
This commit is contained in:
parent
786016344b
commit
286c29f4e3
6 changed files with 24 additions and 16 deletions
|
|
@ -25,7 +25,7 @@ public partial class App : Application
|
||||||
/// <c>DataValidationErrors.SetErrors</c>.
|
/// <c>DataValidationErrors.SetErrors</c>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IServiceProvider? Services { get; private set; }
|
public IServiceProvider? Services { get; private set; }
|
||||||
|
private MainWindow window;
|
||||||
public App()
|
public App()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
@ -137,7 +137,7 @@ public partial class App : Application
|
||||||
var homePage = provider.GetRequiredService<HomePage>();
|
var homePage = provider.GetRequiredService<HomePage>();
|
||||||
homePage.DataContext = provider.GetRequiredService<HomePageViewModel>();
|
homePage.DataContext = provider.GetRequiredService<HomePageViewModel>();
|
||||||
|
|
||||||
var window = new MainWindow();
|
window = new MainWindow();
|
||||||
window.SessionBanner.DataContext = sessionStatus;
|
window.SessionBanner.DataContext = sessionStatus;
|
||||||
|
|
||||||
// Build the navigation stack from scratch: HomePage is the
|
// Build the navigation stack from scratch: HomePage is the
|
||||||
|
|
@ -165,7 +165,7 @@ public partial class App : Application
|
||||||
sessionStatus.LoginSucceeded += () =>
|
sessionStatus.LoginSucceeded += () =>
|
||||||
{
|
{
|
||||||
var w = (MainWindow)((IClassicDesktopStyleApplicationLifetime)ApplicationLifetime!).MainWindow!;
|
var w = (MainWindow)((IClassicDesktopStyleApplicationLifetime)ApplicationLifetime!).MainWindow!;
|
||||||
_ = PushMainPageAsync(provider, w);
|
_ = PushMainPageAsync();
|
||||||
};
|
};
|
||||||
|
|
||||||
// When the user clicks the "Paramètres" button on the
|
// When the user clicks the "Paramètres" button on the
|
||||||
|
|
@ -196,7 +196,7 @@ public partial class App : Application
|
||||||
_ = w.NavRoot.PushAsync(settingsPage);
|
_ = 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)
|
else if (ApplicationLifetime is ISingleViewApplicationLifetime singleView)
|
||||||
{
|
{
|
||||||
|
|
@ -223,15 +223,14 @@ public partial class App : Application
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static async Task BootAsync(
|
private static async Task BootAsync(
|
||||||
IServiceProvider provider,
|
IServiceProvider provider,
|
||||||
YavscApiClient api,
|
YavscApiClient api)
|
||||||
MainWindow window)
|
|
||||||
{
|
{
|
||||||
var refreshed = await api.TrySilentLoginAsync().ConfigureAwait(true);
|
var refreshed = await api.TrySilentLoginAsync().ConfigureAwait(true);
|
||||||
var sessionStatus = provider.GetRequiredService<SessionStatusViewModel>();
|
var sessionStatus = provider.GetRequiredService<SessionStatusViewModel>();
|
||||||
sessionStatus.Refresh();
|
sessionStatus.Refresh();
|
||||||
if (!refreshed) return;
|
if (!refreshed) return;
|
||||||
|
|
||||||
await PushMainPageAsync(provider, window).ConfigureAwait(true);
|
await PushMainPageAsync().ConfigureAwait(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -241,12 +240,13 @@ public partial class App : Application
|
||||||
/// (interactive login from the banner). Pulled out as a helper so
|
/// (interactive login from the banner). Pulled out as a helper so
|
||||||
/// the two callers can't drift apart.
|
/// the two callers can't drift apart.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static async Task PushMainPageAsync(IServiceProvider provider, MainWindow window)
|
public static async Task PushMainPageAsync()
|
||||||
{
|
{
|
||||||
var mainVm = provider.GetRequiredService<MainPageViewModel>();
|
var app = (App)Current;
|
||||||
var mainPage = provider.GetRequiredService<MainPage>();
|
var mainVm = app.Services.GetRequiredService<MainPageViewModel>();
|
||||||
|
var mainPage = app.Services.GetRequiredService<MainPage>();
|
||||||
mainPage.DataContext = mainVm;
|
mainPage.DataContext = mainVm;
|
||||||
await window.NavRoot.PushAsync(mainPage).ConfigureAwait(true);
|
await app.window.FindControl<NavigationPage>("NavRoot").PushAsync(mainPage).ConfigureAwait(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool TryHandOffCustomSchemeUrl()
|
private bool TryHandOffCustomSchemeUrl()
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
|
using CommunityToolkit.Mvvm.Input;
|
||||||
using PostIt;
|
using PostIt;
|
||||||
using PostIt.Services;
|
using PostIt.Services;
|
||||||
using PostIt.ViewModels;
|
namespace PostIt.ViewModels;
|
||||||
|
|
||||||
public class HomePageViewModel : ViewModelBase
|
public class HomePageViewModel : ViewModelBase
|
||||||
{
|
{
|
||||||
|
|
@ -22,7 +23,7 @@ public class HomePageViewModel : ViewModelBase
|
||||||
Api = api;
|
Api = api;
|
||||||
Settings = settings;
|
Settings = settings;
|
||||||
}
|
}
|
||||||
|
public RelayCommand OpenBlogs { get; set; } = new RelayCommand(() => App.PushMainPageAsync());
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Avalonia designer constructor. Builds a self-contained VM
|
/// Avalonia designer constructor. Builds a self-contained VM
|
||||||
/// with a freshly-constructed Settings so the XAML preview can
|
/// with a freshly-constructed Settings so the XAML preview can
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,12 @@
|
||||||
<ContentPage xmlns="https://github.com/avaloniaui"
|
<ContentPage xmlns="https://github.com/avaloniaui"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:vm="using:PostIt.ViewModels"
|
||||||
x:Class="PostIt.Views.HomePage"
|
x:Class="PostIt.Views.HomePage"
|
||||||
|
x:DataType="vm:HomePageViewModel"
|
||||||
Header="Home">
|
Header="Home">
|
||||||
|
<Design.DataContext>
|
||||||
|
<vm:HomePageViewModel />
|
||||||
|
</Design.DataContext>
|
||||||
<StackPanel HorizontalAlignment="Center"
|
<StackPanel HorizontalAlignment="Center"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
Spacing="12">
|
Spacing="12">
|
||||||
|
|
@ -9,5 +14,8 @@
|
||||||
FontSize="22"
|
FontSize="22"
|
||||||
FontWeight="SemiBold"
|
FontWeight="SemiBold"
|
||||||
HorizontalAlignment="Center"/>
|
HorizontalAlignment="Center"/>
|
||||||
|
<Button Content="Open Blog Interface"
|
||||||
|
Command="{Binding OpenBlogs}"
|
||||||
|
HorizontalAlignment="Center"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</ContentPage>
|
</ContentPage>
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,6 @@
|
||||||
<StackPanel Grid.Row="0" Spacing="12"
|
<StackPanel Grid.Row="0" Spacing="12"
|
||||||
HorizontalAlignment="Stretch"
|
HorizontalAlignment="Stretch"
|
||||||
VerticalAlignment="Top">
|
VerticalAlignment="Top">
|
||||||
<TextBlock Text="PostIt Blog API Interface" FontSize="20" FontWeight="Bold" />
|
|
||||||
|
|
||||||
<StackPanel Orientation="Horizontal" Spacing="8">
|
<StackPanel Orientation="Horizontal" Spacing="8">
|
||||||
<Button Command="{Binding LoadPosts}" Content="Load posts" />
|
<Button Command="{Binding LoadPosts}" Content="Load posts" />
|
||||||
|
|
@ -93,4 +92,4 @@
|
||||||
</Grid>
|
</Grid>
|
||||||
</Border>
|
</Border>
|
||||||
</Grid>
|
</Grid>
|
||||||
</ContentPage>
|
</ContentPage>
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
-->
|
-->
|
||||||
<DockPanel LastChildFill="True">
|
<DockPanel LastChildFill="True">
|
||||||
<views:SessionStatusBanner x:Name="SessionBanner"
|
<views:SessionStatusBanner x:Name="SessionBanner"
|
||||||
DockPanel.Dock="Top"/>
|
DockPanel.Dock="Bottom"/>
|
||||||
<NavigationPage x:Name="NavRoot"/>
|
<NavigationPage x:Name="NavRoot"/>
|
||||||
</DockPanel>
|
</DockPanel>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue