Files
Shogi/Shogi.UI/Pages/Play/GameBrowser.razor
2024-10-31 19:14:54 -05:00

50 lines
979 B
Plaintext

@using Shogi.Contracts.Types;
@using System.ComponentModel.DataAnnotations;
@using System.Net;
@using System.Text.Json;
@inject ShogiApi ShogiApi
<section class="GameBrowser PrimaryTheme ThemeVariant--Contrast">
<div class="table">
<row class="header">
<span>Creator</span>
<span>Seats</span>
<span></span>
</row>
<hr />
<AuthorizeView>
@foreach (var session in allSessions)
{
<row>
<GameBrowserEntry Session="session" OnSessionDeleted="FetchSessions" />
</row>
}
</AuthorizeView>
</div>
@if (allSessions.Length == 0)
{
<p>There are no games being played.</p>
}
</section>
@code {
private SessionMetadata[] allSessions = Array.Empty<SessionMetadata>();
protected override Task OnInitializedAsync()
{
return FetchSessions();
}
async Task FetchSessions()
{
var sessions = await ShogiApi.GetAllSessionsMetadata();
if (sessions != null)
{
this.allSessions = sessions.ToArray();
StateHasChanged();
}
}
}