Replace custom socket implementation with SignalR.
Replace MSAL and custom cookie auth with Microsoft.Identity.EntityFramework Also some UI redesign to accommodate different login experience.
This commit is contained in:
58
Shogi.UI/Pages/Play/PromotePrompt.cs
Normal file
58
Shogi.UI/Pages/Play/PromotePrompt.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using Shogi.Contracts.Api;
|
||||
using Shogi.UI.Shared;
|
||||
|
||||
namespace Shogi.UI.Pages.Play;
|
||||
|
||||
public class PromotePrompt
|
||||
{
|
||||
private readonly ShogiApi shogiApi;
|
||||
private string? sessionName;
|
||||
private MovePieceCommand? command;
|
||||
|
||||
public PromotePrompt(ShogiApi shogiApi)
|
||||
{
|
||||
this.shogiApi = shogiApi;
|
||||
this.IsVisible = false;
|
||||
this.OnClickCancel = this.Hide;
|
||||
}
|
||||
|
||||
public bool IsVisible { get; private set; }
|
||||
public Action OnClickCancel;
|
||||
public Func<Task>? OnClickNo;
|
||||
public Func<Task>? OnClickYes;
|
||||
|
||||
public void Show(string sessionName, MovePieceCommand command)
|
||||
{
|
||||
this.sessionName = sessionName;
|
||||
this.command = command;
|
||||
this.IsVisible = true;
|
||||
this.OnClickNo = this.Move;
|
||||
this.OnClickYes = this.MoveAndPromote;
|
||||
}
|
||||
|
||||
public void Hide()
|
||||
{
|
||||
this.IsVisible = false;
|
||||
this.OnClickNo = null;
|
||||
this.OnClickYes = null;
|
||||
}
|
||||
|
||||
private Task Move()
|
||||
{
|
||||
if (this.command != null && this.sessionName != null)
|
||||
{
|
||||
this.command.IsPromotion = false;
|
||||
return this.shogiApi.Move(this.sessionName, this.command);
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
private Task MoveAndPromote()
|
||||
{
|
||||
if (this.command != null && this.sessionName != null)
|
||||
{
|
||||
this.command.IsPromotion = true;
|
||||
return this.shogiApi.Move(this.sessionName, this.command);
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user