Remove unused modals service and display.
This commit is contained in:
@@ -75,9 +75,9 @@ public class AccountManager
|
||||
public async Task<bool> TryLoginSilentAsync()
|
||||
{
|
||||
var platform = await localStorage.GetAccountPlatform();
|
||||
Console.WriteLine($"Try Login Silent - {platform}");
|
||||
if (platform == WhichAccountPlatform.Guest)
|
||||
{
|
||||
Console.WriteLine($"Try Login Silent - {platform}");
|
||||
var response = await shogiApi.GetToken(WhichAccountPlatform.Guest);
|
||||
if (response != null)
|
||||
{
|
||||
@@ -91,6 +91,7 @@ public class AccountManager
|
||||
}
|
||||
else if (platform == WhichAccountPlatform.Microsoft)
|
||||
{
|
||||
Console.WriteLine($"Try Login Silent - {platform}");
|
||||
var state = await authState.GetAuthenticationStateAsync();
|
||||
if (state.User?.Identity?.Name != null)
|
||||
{
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace Shogi.UI.Pages.Home.Api
|
||||
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
||||
{
|
||||
request.SetBrowserRequestCredentials(BrowserRequestCredentials.Include);
|
||||
Console.WriteLine("cookie handler: {0}", request.RequestUri);
|
||||
return base.SendAsync(request, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,15 +13,14 @@ namespace Shogi.UI.Pages.Home.Api
|
||||
public const string MsalClientName = "Msal";
|
||||
|
||||
private readonly JsonSerializerOptions serializerOptions;
|
||||
private readonly IHttpClientFactory clientFactory;
|
||||
private readonly AccountState accountState;
|
||||
private readonly HttpClient guestHttpClient;
|
||||
private readonly HttpClient msalHttpClient;
|
||||
|
||||
public ShogiApi(IHttpClientFactory clientFactory, AccountState accountState)
|
||||
{
|
||||
serializerOptions = new JsonSerializerOptions(JsonSerializerDefaults.Web);
|
||||
this.clientFactory = clientFactory;
|
||||
Console.WriteLine("ShogiApi constructor");
|
||||
this.serializerOptions = new JsonSerializerOptions(JsonSerializerDefaults.Web);
|
||||
this.accountState = accountState;
|
||||
this.guestHttpClient = clientFactory.CreateClient(GuestClientName);
|
||||
this.msalHttpClient = clientFactory.CreateClient(MsalClientName);
|
||||
@@ -68,6 +67,7 @@ namespace Shogi.UI.Pages.Home.Api
|
||||
var httpClient = whichAccountPlatform == WhichAccountPlatform.Microsoft
|
||||
? this.msalHttpClient
|
||||
: this.guestHttpClient;
|
||||
|
||||
var response = await httpClient.GetAsync(RelativeUri("User/Token"));
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
@@ -82,7 +82,7 @@ namespace Shogi.UI.Pages.Home.Api
|
||||
|
||||
public async Task Move(string sessionName, MovePieceCommand command)
|
||||
{
|
||||
await this.HttpClient.PatchAsync($"Sessions/{sessionName}/Move", JsonContent.Create(command));
|
||||
await this.HttpClient.PatchAsync(RelativeUri($"Sessions/{sessionName}/Move"), JsonContent.Create(command));
|
||||
}
|
||||
|
||||
public async Task<HttpStatusCode> PostSession(string name, bool isPrivate)
|
||||
|
||||
@@ -2,11 +2,9 @@
|
||||
@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)
|
||||
|
||||
@@ -5,8 +5,6 @@ using Shogi.UI.Pages.Home;
|
||||
using Shogi.UI.Pages.Home.Account;
|
||||
using Shogi.UI.Pages.Home.Api;
|
||||
using Shogi.UI.Shared;
|
||||
using Shogi.UI.Shared.Modal;
|
||||
using System.Net.WebSockets;
|
||||
using System.Text.Json;
|
||||
|
||||
var builder = WebAssemblyHostBuilder.CreateDefault(args);
|
||||
@@ -54,7 +52,6 @@ static void ConfigureDependencies(IServiceCollection services, IConfiguration co
|
||||
services.AddScoped<AccountManager>();
|
||||
services.AddScoped<AccountState>();
|
||||
services.AddScoped<ShogiSocket>();
|
||||
services.AddScoped<ModalService>();
|
||||
services.AddScoped<ILocalStorage, LocalStorage>();
|
||||
services.AddScoped<MsalMessageHandler>();
|
||||
services.AddScoped<CookieCredentialsMessageHandler>();
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
namespace Shogi.UI.Shared.Modal
|
||||
{
|
||||
/// <summary>
|
||||
/// An injectible service which can be invoked to display preset modals via the <Modals /> razor component.
|
||||
/// Only one modal me be visible at a time.
|
||||
/// </summary>
|
||||
public class ModalService
|
||||
{
|
||||
public event EventHandler<ModalVisibilityChangedEventArgs>? ModalVisibilityChangedEvent;
|
||||
|
||||
public ModalService()
|
||||
{
|
||||
}
|
||||
|
||||
public bool LoginModalIsVisible { get; private set; }
|
||||
public bool GuestAccountDescriptionIsVisible { get; private set; }
|
||||
|
||||
public void ShowLoginModal()
|
||||
{
|
||||
SetAllVisibilitiesToFalse();
|
||||
LoginModalIsVisible = true;
|
||||
EmitCurrentState();
|
||||
}
|
||||
|
||||
public void ShowGuestAccountDescriptionModal()
|
||||
{
|
||||
SetAllVisibilitiesToFalse();
|
||||
GuestAccountDescriptionIsVisible = true;
|
||||
EmitCurrentState();
|
||||
}
|
||||
|
||||
public void HideAllModals()
|
||||
{
|
||||
SetAllVisibilitiesToFalse();
|
||||
EmitCurrentState();
|
||||
}
|
||||
|
||||
private void EmitCurrentState()
|
||||
{
|
||||
ModalVisibilityChangedEvent?.Invoke(this, new()
|
||||
{
|
||||
LoginModalIsVisible = LoginModalIsVisible,
|
||||
GuestAccountDescriptionIsVisible = GuestAccountDescriptionIsVisible
|
||||
});
|
||||
}
|
||||
|
||||
private void SetAllVisibilitiesToFalse()
|
||||
{
|
||||
LoginModalIsVisible = false;
|
||||
GuestAccountDescriptionIsVisible = false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
namespace Shogi.UI.Shared.Modal
|
||||
{
|
||||
public class ModalVisibilityChangedEventArgs : EventArgs
|
||||
{
|
||||
public bool LoginModalIsVisible { get; set; }
|
||||
public bool GuestAccountDescriptionIsVisible { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
@inject ModalService modalService
|
||||
@inject AccountManager Account
|
||||
@inject NavigationManager NavManager
|
||||
@inject ILocalStorage localStorage
|
||||
|
||||
@if (shouldShow)
|
||||
{
|
||||
<div class="my-modal-background">
|
||||
<div class="my-modal">
|
||||
@if (modalService.LoginModalIsVisible)
|
||||
{
|
||||
|
||||
}
|
||||
else if (modalService.GuestAccountDescriptionIsVisible)
|
||||
{
|
||||
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@code {
|
||||
bool shouldShow = false;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
modalService.ModalVisibilityChangedEvent += OnModalChange;
|
||||
}
|
||||
|
||||
void OnModalChange(object? sender, ModalVisibilityChangedEventArgs args)
|
||||
{
|
||||
if (args != null)
|
||||
{
|
||||
shouldShow = args.LoginModalIsVisible || args.GuestAccountDescriptionIsVisible;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
.my-modal-background {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
position: fixed;
|
||||
background-color: rgba(0,0,0,0.4);
|
||||
inset: 0;
|
||||
z-index: 900;
|
||||
}
|
||||
|
||||
.my-modal {
|
||||
text-align: center;
|
||||
background-color: var(--contrast-color);
|
||||
padding: 1rem;
|
||||
max-width: 40rem;
|
||||
}
|
||||
|
||||
.account-description {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr max-content max-content;
|
||||
column-gap: 1.5rem;
|
||||
}
|
||||
@@ -12,5 +12,4 @@
|
||||
@using Shogi.UI.Pages.Home.Api
|
||||
@using Shogi.UI.Pages.Home.GameBoard
|
||||
@using Shogi.UI.Pages.Home.Pieces
|
||||
@using Shogi.UI.Shared.Modal
|
||||
@using Shogi.UI.Shared
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
"api://c1e94676-cab0-42ba-8b6c-9532b8486fff/DefaultScope"
|
||||
]
|
||||
},
|
||||
"ShogiApiUrl": "https://localhost:5001",
|
||||
"SocketUrl": "wss://localhost:5001"
|
||||
"ShogiApiUrl2": "https://localhost:5001",
|
||||
"ShogiApiUrl": "https://api.lucaserver.space/Shogi.Api/",
|
||||
"SocketUrl": "wss://api.lucaserver.space/Shogi.Api/",
|
||||
"SocketUrl2": "wss://localhost:5001"
|
||||
}
|
||||
Reference in New Issue
Block a user