38 lines
1.0 KiB
C#
38 lines
1.0 KiB
C#
using CommunityToolkit.Mvvm.Messaging;
|
|
using MauiApp.Core.Business.Contracts;
|
|
using MauiApp.Core.System.Navigation;
|
|
using MauiApp.Views;
|
|
|
|
namespace MauiApp;
|
|
|
|
public partial class AppShell : Shell
|
|
{
|
|
private readonly IMessenger _messenger;
|
|
private readonly IAccountService _accountService;
|
|
|
|
public AppShell(IMessenger messenger, IAccountService accountService)
|
|
{
|
|
_messenger = messenger;
|
|
_accountService = accountService;
|
|
InitializeComponent();
|
|
|
|
_ = NavigationFlow();
|
|
}
|
|
|
|
|
|
private async Task NavigationFlow()
|
|
{
|
|
if (_accountService.IsLoggedIn)
|
|
await NavigateAsync<MainPage>(clearStack: true);
|
|
else
|
|
await NavigateAsync<LoginPage>(clearStack: true);
|
|
}
|
|
|
|
|
|
private async Task NavigateAsync<TPage>(INavigationParameters pageParams = null, bool clearStack = false) where TPage : Page
|
|
{
|
|
var pageName = typeof(TPage).Name;
|
|
pageParams ??= new NavigationParameters();
|
|
await GoToAsync((clearStack ? "//" : "") + pageName, true, pageParams);
|
|
}
|
|
} |