adding past hub and page skeleton to MAUI

This commit is contained in:
Andy Pack 2023-01-28 13:34:10 +00:00
parent 5c44c951d5
commit 95e1c66adf
Signed by: sarsoo
GPG Key ID: A55BA3536A5E0ED7
7 changed files with 116 additions and 7 deletions

View File

@ -28,15 +28,17 @@ public static class MauiProgram
builder.Services.AddBlazorWebViewDeveloperTools();
builder.Logging.AddDebug();
#endif
builder.Services.AddHttpClient();
builder.Services.AddHttpClient()
.AddTransient<ISelectorNetClient, SelectorNetClient>();
builder.Services.AddTransient<ISelectorNetClient, SelectorNetClient>();
builder.Services.AddSingleton<SessionManager>();
builder.Services.AddSingleton<NowHubClient>();
builder.Services.AddSingleton<NowHubCache>();
builder.Services.AddSingleton<NowHubClient>()
.AddSingleton<NowHubCache>();
return builder.Build();
builder.Services.AddSingleton<PastHubClient>();
return builder.Build();
}
}

View File

@ -2,6 +2,7 @@
@using Selector.SignalR
@inject NowHubClient nowClient
@inject NowHubCache nowCache
@inject PastHubClient pastClient
@inject ILogger<Index> logger
<h1>run that</h1>
@ -16,6 +17,7 @@
logger.LogInformation("Starting now hub connection");
await nowClient.StartAsync();
await pastClient.StartAsync();
nowCache.BindClient();
await nowClient.OnConnected();
}

View File

@ -0,0 +1,23 @@
@page "/past"
@using Selector.SignalR;
@using System.Linq;
@implements IDisposable
<h1>Past</h1>
<div class="app">
</div>
<div class="v-space"></div>
@code {
protected async override Task OnInitializedAsync()
{
}
}

View File

@ -0,0 +1,20 @@
body {
}
.app {
display: block;
}
h1 {
padding-bottom: 20px;
}
@media (min-width: 641px) {
.app {
display: flex;
align-items: flex-start;
flex-wrap: wrap;
width: 100%
}
}

View File

@ -17,11 +17,13 @@ public class SelectorNetClient : ISelectorNetClient
private readonly HttpClient _client;
private readonly string _baseUrl;
private readonly NowHubClient _nowClient;
private readonly PastHubClient _pastClient;
public SelectorNetClient(HttpClient client, NowHubClient nowClient)
public SelectorNetClient(HttpClient client, NowHubClient nowClient, PastHubClient pastClient)
{
_client = client;
_nowClient = nowClient;
_pastClient = pastClient;
//var baseOverride = Environment.GetEnvironmentVariable("SELECTOR_BASE_URL");
@ -83,6 +85,7 @@ public class SelectorNetClient : ISelectorNetClient
ret.Status = TokenResponseStatus.OK;
ret.Token = result.Content.ReadFromJsonAsync<TokenNetworkResponse>().Result.Token;
_nowClient.Token = ret.Token;
_pastClient.Token = ret.Token;
break;
default:
break;

View File

@ -9,7 +9,12 @@
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="now">
<span class="oi oi-dashboard" aria-hidden="true"></span> Now
<span class="oi oi-media-play" aria-hidden="true"></span> Now
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="past">
<span class="oi oi-magnifying-glass" aria-hidden="true"></span> Past
</NavLink>
</div>
<div class="nav-item px-3">

View File

@ -0,0 +1,54 @@
using Microsoft.AspNetCore.SignalR.Client;
namespace Selector.SignalR;
public class PastHubClient: BaseSignalRClient, IPastHub, IDisposable
{
private List<IDisposable> SearchResultCallbacks = new();
private bool disposedValue;
public PastHubClient(string token = null): base("nowhub", token)
{
}
public void OnRankResult(Action<IRankResult> action)
{
SearchResultCallbacks.Add(hubConnection.On(nameof(OnRankResult), action));
}
public Task OnConnected()
{
return hubConnection.InvokeAsync(nameof(OnConnected));
}
public Task OnSubmitted(IPastParams param)
{
return hubConnection.InvokeAsync(nameof(OnSubmitted), param);
}
protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
if (disposing)
{
foreach(var callback in SearchResultCallbacks)
{
callback.Dispose();
}
base.DisposeAsync();
}
disposedValue = true;
}
}
public void Dispose()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}