diff --git a/Shogi.UI/Pages/Home/Account/AccountManager.cs b/Shogi.UI/Pages/Home/Account/AccountManager.cs index 97fc001..5865c18 100644 --- a/Shogi.UI/Pages/Home/Account/AccountManager.cs +++ b/Shogi.UI/Pages/Home/Account/AccountManager.cs @@ -75,9 +75,9 @@ public class AccountManager public async Task 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) { diff --git a/Shogi.UI/Pages/Home/Api/CookieMessageHandler.cs b/Shogi.UI/Pages/Home/Api/CookieMessageHandler.cs index 2aac297..cf20575 100644 --- a/Shogi.UI/Pages/Home/Api/CookieMessageHandler.cs +++ b/Shogi.UI/Pages/Home/Api/CookieMessageHandler.cs @@ -12,6 +12,7 @@ namespace Shogi.UI.Pages.Home.Api protected override Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { request.SetBrowserRequestCredentials(BrowserRequestCredentials.Include); + Console.WriteLine("cookie handler: {0}", request.RequestUri); return base.SendAsync(request, cancellationToken); } } diff --git a/Shogi.UI/Pages/Home/Api/ShogiApi.cs b/Shogi.UI/Pages/Home/Api/ShogiApi.cs index 6607188..b2af3a6 100644 --- a/Shogi.UI/Pages/Home/Api/ShogiApi.cs +++ b/Shogi.UI/Pages/Home/Api/ShogiApi.cs @@ -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 PostSession(string name, bool isPrivate) diff --git a/Shogi.UI/Pages/Home/Home.razor b/Shogi.UI/Pages/Home/Home.razor index c6d38b9..70a73a5 100644 --- a/Shogi.UI/Pages/Home/Home.razor +++ b/Shogi.UI/Pages/Home/Home.razor @@ -2,11 +2,9 @@ @using Shogi.Contracts.Types @using System.Net.WebSockets @using System.Text -@inject ModalService modalService @inject AccountManager AccountManager @inject AccountState Account -@**@
@if (welcomeModalIsVisible) diff --git a/Shogi.UI/Program.cs b/Shogi.UI/Program.cs index c52fcae..a977d74 100644 --- a/Shogi.UI/Program.cs +++ b/Shogi.UI/Program.cs @@ -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(); services.AddScoped(); services.AddScoped(); - services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); diff --git a/Shogi.UI/Shared/Modal/ModalService.cs b/Shogi.UI/Shared/Modal/ModalService.cs deleted file mode 100644 index 7068213..0000000 --- a/Shogi.UI/Shared/Modal/ModalService.cs +++ /dev/null @@ -1,54 +0,0 @@ -namespace Shogi.UI.Shared.Modal -{ - /// - /// An injectible service which can be invoked to display preset modals via the razor component. - /// Only one modal me be visible at a time. - /// - public class ModalService - { - public event EventHandler? 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; - } - - } -} diff --git a/Shogi.UI/Shared/Modal/ModalVisibilityChangedEventArgs.cs b/Shogi.UI/Shared/Modal/ModalVisibilityChangedEventArgs.cs deleted file mode 100644 index 4ab2064..0000000 --- a/Shogi.UI/Shared/Modal/ModalVisibilityChangedEventArgs.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Shogi.UI.Shared.Modal -{ - public class ModalVisibilityChangedEventArgs : EventArgs - { - public bool LoginModalIsVisible { get; set; } - public bool GuestAccountDescriptionIsVisible { get; set; } - - } -} diff --git a/Shogi.UI/Shared/Modal/Modals.razor b/Shogi.UI/Shared/Modal/Modals.razor deleted file mode 100644 index f4e8f1a..0000000 --- a/Shogi.UI/Shared/Modal/Modals.razor +++ /dev/null @@ -1,38 +0,0 @@ -@inject ModalService modalService -@inject AccountManager Account -@inject NavigationManager NavManager -@inject ILocalStorage localStorage - -@if (shouldShow) -{ -
-
- @if (modalService.LoginModalIsVisible) - { - - } - else if (modalService.GuestAccountDescriptionIsVisible) - { - - } -
-
-} - -@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(); - } - } -} diff --git a/Shogi.UI/Shared/Modal/Modals.razor.css b/Shogi.UI/Shared/Modal/Modals.razor.css deleted file mode 100644 index 2f3b721..0000000 --- a/Shogi.UI/Shared/Modal/Modals.razor.css +++ /dev/null @@ -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; -} \ No newline at end of file diff --git a/Shogi.UI/_Imports.razor b/Shogi.UI/_Imports.razor index 0cdacaf..a27b233 100644 --- a/Shogi.UI/_Imports.razor +++ b/Shogi.UI/_Imports.razor @@ -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 diff --git a/Shogi.UI/wwwroot/appsettings.json b/Shogi.UI/wwwroot/appsettings.json index 66f4809..8401787 100644 --- a/Shogi.UI/wwwroot/appsettings.json +++ b/Shogi.UI/wwwroot/appsettings.json @@ -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" } \ No newline at end of file