mirror of
https://github.com/lantean-code/qbtmud.git
synced 2025-10-31 20:13:31 +00:00
45 lines
1.3 KiB
C#
45 lines
1.3 KiB
C#
using Lantean.QBTMudBlade.Models;
|
|
using Lantean.QBTMudBlade.Services;
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
namespace Lantean.QBTMudBlade.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));
|
|
}
|
|
}
|
|
|
|
protected abstract Task Submit(KeyboardEvent keyboardEvent);
|
|
|
|
protected virtual async ValueTask DisposeAsync(bool disposing)
|
|
{
|
|
if (!_disposedValue)
|
|
{
|
|
if (disposing)
|
|
{
|
|
await KeyboardService.UnregisterKeypressEvent("Enter");
|
|
}
|
|
|
|
_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);
|
|
}
|
|
}
|
|
}
|