LANCommander/LANCommander.Launcher/UI/Components/AuthenticatedView.razor
2025-04-24 01:39:12 +02:00

43 lines
No EOL
1.2 KiB
Text

@using ConnectionState = LANCommander.Launcher.Models.ConnectionState
@inject AuthenticationService AuthenticationService
@inject NavigationManager NavigationManager
<CascadingValue Value="ConnectionState">
@if (ConnectionState.IsConnected || ConnectionState.OfflineModeEnabled)
{
@Authenticated
}
else
{
@NotAuthenticated
}
</CascadingValue>
@code {
[Parameter] public RenderFragment Authenticated { get; set; }
[Parameter] public RenderFragment NotAuthenticated { get; set; }
public ConnectionState ConnectionState = new();
protected override async Task OnInitializedAsync()
{
AuthenticationService.OnLogin += async (sender, args) =>
{
await Validate();
};
AuthenticationService.OnRegister += async (sender, args) =>
{
await Validate();
};
await Validate();
}
public async Task Validate()
{
ConnectionState.IsConnected = await AuthenticationService.ValidateConnectionAsync();
ConnectionState.OfflineModeEnabled = AuthenticationService.OfflineModeEnabled();
await InvokeAsync(StateHasChanged);
}
}