diff --git a/Clients/Monopoly.Clients.Web/Pages/Index.razor b/Clients/Monopoly.Clients.Web/Pages/Index.razor index 12608a3..5f28270 100644 --- a/Clients/Monopoly.Clients.Web/Pages/Index.razor +++ b/Clients/Monopoly.Clients.Web/Pages/Index.razor @@ -1,13 +1 @@ -@page "/games/{gameid}" -@using Client.Pages.Gaming -@using Client.Pages.Ready - - @if (IsGameStarted) - { - - } - else - { - - } - \ No newline at end of file + \ No newline at end of file diff --git a/Clients/Monopoly.Clients.Web/Pages/Index.razor.cs b/Clients/Monopoly.Clients.Web/Pages/Index.razor.cs index 850e825..5f28270 100644 --- a/Clients/Monopoly.Clients.Web/Pages/Index.razor.cs +++ b/Clients/Monopoly.Clients.Web/Pages/Index.razor.cs @@ -1,65 +1 @@ -using Client.Options; -using Microsoft.AspNetCore.Components; -using Microsoft.AspNetCore.SignalR.Client; -using Microsoft.Extensions.Options; -using SharedLibrary.ResponseArgs.ReadyRoom; - -namespace Client.Pages; - -public partial class Index -{ - [Parameter] public string GameId { get; set; } = null!; - - [Parameter, SupplyParameterFromQuery(Name = "token")] - public string AccessToken { get; set; } = default!; - [Inject] private IOptions BackendApiOptions { get; set; } = default!; - private string UserId { get; set; } = string.Empty; - private List Messages { get; } = []; - public bool IsGameStarted { get; set; } = false; - private TypedHubConnection Connection { get; set; } = default!; - - protected override async Task OnInitializedAsync() - { - await SetupHubConnectionAsync(); - } - - private async Task SetupHubConnectionAsync() - { - var baseUri = new Uri(BackendApiOptions.Value.BaseUrl); - var url = new Uri(baseUri, $"/monopoly?gameid={GameId}"); - var client = new HubConnectionBuilder() - .WithUrl(url, options => - { - options.AccessTokenProvider = async () => await Task.FromResult(AccessToken); - }) - .Build(); - Connection = new TypedHubConnection(client); - Connection.WelcomeEventHandler += OnWelcomeEventHandler; - client.Closed += OnConnectionClosed; - try - { - await client.StartAsync(); - Messages.Add("連線成功!"); - } - catch (Exception ex) - { - Messages.Add(ex.Message); - } - } - - private async Task OnConnectionClosed(Exception? exception) - { - var errorMessage = exception?.Message; - Messages.Add($"中斷連線: {errorMessage}"); - - await Task.CompletedTask; - } - - private Task OnWelcomeEventHandler(WelcomeEventArgs e) - { - UserId = e.PlayerId; - Messages.Add($"歡迎 {e.PlayerId} 加入遊戲!"); - StateHasChanged(); - return Task.CompletedTask; - } -} \ No newline at end of file + \ No newline at end of file diff --git a/Clients/Monopoly.Clients.Web/Pages/Ready/ReadyPage.razor.cs b/Clients/Monopoly.Clients.Web/Pages/Ready/ReadyPage.razor.cs index d6bbca5..d77ff45 100644 --- a/Clients/Monopoly.Clients.Web/Pages/Ready/ReadyPage.razor.cs +++ b/Clients/Monopoly.Clients.Web/Pages/Ready/ReadyPage.razor.cs @@ -5,7 +5,6 @@ using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.SignalR.Client; using Microsoft.Extensions.Options; -using SharedLibrary.ResponseArgs.Monopoly; using SharedLibrary.ResponseArgs.ReadyRoom; using SharedLibrary.ResponseArgs.ReadyRoom.Models; using Player = Client.Pages.Ready.Entities.Player; @@ -100,20 +99,6 @@ private Task OnPlayerReadyEvent(PlayerReadyEventArgs e) return Task.CompletedTask; } - private async Task OnPlayerCannotSelectLocationEvent(PlayerCannotSelectLocationEventArgs e) - { - if (Popup is null) - { - return; - } - - await Popup.Show(new Popup.PopupParameter - { - Message = "Cannot select location.", - Delay = 500 - }); - } - private async Task OnGameStartEvent(GameStartedEventArgs e) { if (Popup is null)