mirror of
https://github.com/lantean-code/qbtmud.git
synced 2025-11-02 13:03:23 +00:00
Update project name and namespaces
This commit is contained in:
46
Lantean.QBTMud/Components/Dialogs/SubmittableDialog.cs
Normal file
46
Lantean.QBTMud/Components/Dialogs/SubmittableDialog.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using Lantean.QBTMud.Models;
|
||||
using Lantean.QBTMud.Services;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
namespace Lantean.QBTMud.Components.Dialogs
|
||||
{
|
||||
public abstract class SubmittableDialog : ComponentBase, IAsyncDisposable
|
||||
{
|
||||
private bool _disposedValue;
|
||||
|
||||
[Inject]
|
||||
protected IKeyboardService KeyboardService { get; set; } = default!;
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (firstRender)
|
||||
{
|
||||
await KeyboardService.RegisterKeypressEvent("Enter", k => Submit(k));
|
||||
await KeyboardService.Focus();
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract Task Submit(KeyboardEvent keyboardEvent);
|
||||
|
||||
protected virtual async ValueTask DisposeAsync(bool disposing)
|
||||
{
|
||||
if (!_disposedValue)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
await KeyboardService.UnregisterKeypressEvent("Enter");
|
||||
await KeyboardService.UnFocus();
|
||||
}
|
||||
|
||||
_disposedValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
||||
await DisposeAsync(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user