reintroduce microsoft login. upgrade a bunch of stuff.

This commit is contained in:
2023-01-19 16:20:41 -06:00
parent 2a423bcb93
commit 1d0beaf69f
29 changed files with 601 additions and 483 deletions

View File

@@ -1,6 +1,7 @@
@using Shogi.Contracts.Types
@using System.ComponentModel.DataAnnotations
@using System.Net
@using Shogi.Contracts.Types;
@using System.ComponentModel.DataAnnotations;
@using System.Net;
@using System.Text.Json;
@inject IShogiApi ShogiApi;
@inject ShogiSocket ShogiSocket;
@inject AccountState Account;
@@ -17,12 +18,27 @@
<div class="tab-content">
<div class="tab-pane fade show active" id="search-pane">
<h3>Games you&apos;re seated at</h3>
<div class="list-group">
@if (!sessions.Any())
@if (!joinedSessions.Any())
{
<p>No games exist</p>
<p>You have not joined any games.</p>
}
@foreach (var session in sessions)
@foreach (var session in joinedSessions)
{
<button class="list-group-item list-group-item-action @ActiveCss(session)" @onclick="() => OnClickSession(session)">
<span>@session.Name</span>
<span>(@session.PlayerCount/2)</span>
</button>
}
</div>
<h3>Other games</h3>
<div class="list-group">
@if (!otherSessions.Any())
{
<p>You have not joined any games.</p>
}
@foreach (var session in otherSessions)
{
<button class="list-group-item list-group-item-action @ActiveCss(session)" @onclick="() => OnClickSession(session)">
<span>@session.Name</span>
@@ -69,16 +85,19 @@
@code {
[Parameter]
public Action<SessionMetadata>? ActiveSessionChanged { get; set; }
CreateForm createForm = new();
SessionMetadata[] sessions = Array.Empty<SessionMetadata>();
SessionMetadata? activeSession;
HttpStatusCode? createSessionStatusCode;
private CreateForm createForm = new();
private SessionMetadata[] joinedSessions = Array.Empty<SessionMetadata>();
private SessionMetadata[] otherSessions = Array.Empty<SessionMetadata>();
private SessionMetadata? activeSession;
private HttpStatusCode? createSessionStatusCode;
protected override async Task OnInitializedAsync()
{
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();
@@ -99,7 +118,8 @@
var sessions = await ShogiApi.GetSessionsPlayerCount();
if (sessions != null)
{
this.sessions = sessions.PlayerHasJoinedSessions.Concat(sessions.AllOtherSessions).ToArray();
this.joinedSessions = sessions.PlayerHasJoinedSessions.ToArray();
this.otherSessions = sessions.AllOtherSessions.ToArray();
StateHasChanged();
}
}