Skip to content

Commit

Permalink
fix: 解決 Ready 頁面沒有辦法選擇的問題
Browse files Browse the repository at this point in the history
  • Loading branch information
aa89227 committed Jan 14, 2024
1 parent 04e741f commit 01aceee
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Client/Pages/Index.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private async Task SetupHubConnectionAsync()
options.AccessTokenProvider = async () => await Task.FromResult(AccessToken);
})
.Build();
Connection = new(Client);
Connection = new TypedHubConnection(Client);
Connection.WelcomeEventHandler += (e) =>
{
UserId = e.PlayerId;
Expand Down
12 changes: 0 additions & 12 deletions Client/Pages/Ready/ReadyPage.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,10 @@ public partial class ReadyPage
public Player? CurrentPlayer => Players.FirstOrDefault(x => x.Id == UserId);
protected override async Task OnInitializedAsync()
{
Connection.PlayerJoinGameEventHandler += OnPlayerJoinGameEvent;
Connection.GetReadyInfoEventHandler += OnGetReadyInfoEvent;
await Connection.GetReadyInfo();
}
public void Update() => StateHasChanged();
private void OnPlayerJoinGameEvent(PlayerJoinGameEvent e)
{
var player = new Player
{
Id = e.PlayerId,
Name = e.PlayerId,
IsReady = false,
};
Players = Players.Append(player).ToList();
Update();
}
private void OnGetReadyInfoEvent(GetReadyInfoEventArgs e)
{
Players = e.Players.Select(x => new Player
Expand Down
5 changes: 2 additions & 3 deletions Client/Pages/TypedHubConnection.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.AspNetCore.SignalR.Client;
using SharedLibrary.ResponseArgs;
using SharedLibrary.ResponseArgs.ReadyRoom;

namespace Client.Pages;
Expand All @@ -18,8 +17,8 @@ internal class TypedHubConnection
public TypedHubConnection(HubConnection hubConnection)
{
hubConnection.On<PlayerJoinGameEvent>(nameof(PlayerJoinGameEvent), (e) => PlayerJoinGameEventHandler?.Invoke(e));
hubConnection.On<GetReadyInfoEventArgs>(nameof(GetReadyInfoEventArgs), (e) => GetReadyInfoEventHandler?.Invoke(e));
hubConnection.On<WelcomeEventArgs>(nameof(WelcomeEventArgs), (e) => WelcomeEventHandler?.Invoke(e));
hubConnection.On<GetReadyInfoEventArgs>("GetReadyInfoEvent", (e) => GetReadyInfoEventHandler?.Invoke(e));
hubConnection.On<WelcomeEventArgs>("WelcomeEvent", (e) => WelcomeEventHandler?.Invoke(e));
this.hubConnection = hubConnection;
}
public async Task GetReadyInfo() => await hubConnection.SendAsync("GetReadyInfo");
Expand Down
1 change: 0 additions & 1 deletion Server/Hubs/MonopolyHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Microsoft.AspNetCore.SignalR;
using Server.Presenters;
using SharedLibrary;
using SharedLibrary.ResponseArgs;
using System.Security.Claims;
using SharedLibrary.ResponseArgs.Monopoly;
using SharedLibrary.ResponseArgs.ReadyRoom;
Expand Down

0 comments on commit 01aceee

Please sign in to comment.