62 lines
1.4 KiB
Plaintext
62 lines
1.4 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 {
|
|
private bool welcomeModalIsVisible;
|
|
private string activeSessionName;
|
|
private ClientWebSocket socket;
|
|
|
|
public Home()
|
|
{
|
|
welcomeModalIsVisible = false;
|
|
activeSessionName = string.Empty;
|
|
socket = new ClientWebSocket();
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
Account.LoginChangedEvent += OnLoginChanged;
|
|
var success = await AccountManager.TryLoginSilentAsync();
|
|
if (!success)
|
|
{
|
|
welcomeModalIsVisible = true;
|
|
}
|
|
}
|
|
|
|
private Task OnLoginChanged(LoginEventArgs args)
|
|
{
|
|
welcomeModalIsVisible = args.User == null;
|
|
StateHasChanged();
|
|
return Task.CompletedTask;
|
|
}
|
|
private void OnChangeSession(SessionMetadata s)
|
|
{
|
|
activeSessionName = s.Name;
|
|
StateHasChanged();
|
|
}
|
|
}
|