squash a bunch of commits
This commit is contained in:
54
Shogi.UI/Shared/Modal/ModalService.cs
Normal file
54
Shogi.UI/Shared/Modal/ModalService.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
9
Shogi.UI/Shared/Modal/ModalVisibilityChangedEventArgs.cs
Normal file
9
Shogi.UI/Shared/Modal/ModalVisibilityChangedEventArgs.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace Shogi.UI.Shared.Modal
|
||||
{
|
||||
public class ModalVisibilityChangedEventArgs : EventArgs
|
||||
{
|
||||
public bool LoginModalIsVisible { get; set; }
|
||||
public bool GuestAccountDescriptionIsVisible { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
39
Shogi.UI/Shared/Modal/Modals.razor
Normal file
39
Shogi.UI/Shared/Modal/Modals.razor
Normal file
@@ -0,0 +1,39 @@
|
||||
@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)
|
||||
{
|
||||
Console.WriteLine("Modal Change");
|
||||
if (args != null)
|
||||
{
|
||||
shouldShow = args.LoginModalIsVisible || args.GuestAccountDescriptionIsVisible;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
21
Shogi.UI/Shared/Modal/Modals.razor.css
Normal file
21
Shogi.UI/Shared/Modal/Modals.razor.css
Normal file
@@ -0,0 +1,21 @@
|
||||
.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;
|
||||
}
|
||||
Reference in New Issue
Block a user