54 lines
1.2 KiB
Plaintext
54 lines
1.2 KiB
Plaintext
@page "/"
|
|
@using Shogi.Contracts.Types
|
|
@using System.Net.WebSockets
|
|
@using System.Text
|
|
@inject ModalService modalService
|
|
@inject AccountManager AccountManager
|
|
@inject AccountState Account
|
|
|
|
@*<Modals />*@
|
|
|
|
<main class="shogi">
|
|
@if (welcomeModalIsVisible)
|
|
{
|
|
<LoginModal />
|
|
}
|
|
<PageHeader />
|
|
<GameBrowser ActiveSessionChanged="OnChangeSession" />
|
|
@if (Account.User == null || activeSessionName == null)
|
|
{
|
|
<EmptyGameBoard />
|
|
}
|
|
else
|
|
{
|
|
<GameBoard SessionName="@activeSessionName" />
|
|
}
|
|
</main>
|
|
|
|
@code {
|
|
bool welcomeModalIsVisible = false;
|
|
string activeSessionName = string.Empty;
|
|
ClientWebSocket socket = new ClientWebSocket();
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
Account.LoginChangedEvent += OnLoginChanged;
|
|
var success = await AccountManager.TryLoginSilentAsync();
|
|
if (!success)
|
|
{
|
|
welcomeModalIsVisible = true;
|
|
}
|
|
}
|
|
|
|
private void OnLoginChanged(object? sender, LoginEventArgs args)
|
|
{
|
|
welcomeModalIsVisible = args.User == null;
|
|
StateHasChanged();
|
|
}
|
|
private void OnChangeSession(SessionMetadata s)
|
|
{
|
|
activeSessionName = s.Name;
|
|
StateHasChanged();
|
|
}
|
|
}
|