This commit is contained in:
2023-01-28 13:21:47 -06:00
parent 11b387b928
commit 8a25c0ed35
26 changed files with 443 additions and 359 deletions

View File

@@ -1,7 +1,10 @@
@using Shogi.Contracts.Types;
@implements IDisposable;
@using Shogi.Contracts.Types;
@using System.ComponentModel.DataAnnotations;
@using System.Net;
@using System.Text.Json;
@inject IShogiApi ShogiApi;
@inject ShogiSocket ShogiSocket;
@inject AccountState Account;
@@ -76,7 +79,6 @@
The name you chose is taken; choose another.
</div>
}
</EditForm>
</div>
</div>
@@ -92,17 +94,12 @@
private SessionMetadata? activeSession;
private HttpStatusCode? createSessionStatusCode;
protected override async Task OnInitializedAsync()
protected override void OnInitialized()
{
ShogiSocket.OnCreateGameMessage += async (sender, message) => await FetchSessions();
Account.LoginChangedEvent += async (sender, message) =>
{
Console.WriteLine($"LoginEvent. Message={JsonSerializer.Serialize(message)}.");
if (message.User != null)
{
await FetchSessions();
}
};
base.OnInitialized();
ShogiSocket.OnSessionCreated += FetchSessions;
ShogiSocket.OnSessionJoined += FetchSessions;
Account.LoginChangedEvent += LoginChangedEvent_FetchSessions;
}
string ActiveCss(SessionMetadata s) => s == activeSession ? "active" : string.Empty;
@@ -112,6 +109,14 @@
activeSession = s;
ActiveSessionChanged?.Invoke(s);
}
Task LoginChangedEvent_FetchSessions(LoginEventArgs args)
{
if (args.User != null)
{
return FetchSessions();
}
return Task.CompletedTask;
}
async Task FetchSessions()
{
@@ -129,6 +134,13 @@
createSessionStatusCode = await ShogiApi.PostSession(createForm.Name, createForm.IsPrivate);
}
public void Dispose()
{
ShogiSocket.OnSessionCreated -= FetchSessions;
ShogiSocket.OnSessionJoined -= FetchSessions;
Account.LoginChangedEvent -= LoginChangedEvent_FetchSessions;
}
private class CreateForm
{
[Required]