From 466059e2aa1f9151d37acf57f26e9cca5b5ab4d5 Mon Sep 17 00:00:00 2001 From: Jason Dove Date: Thu, 15 Apr 2021 20:35:07 -0500 Subject: [PATCH] fix add to collection typing lag (#170) --- ErsatzTV/Shared/AddToCollectionDialog.razor | 78 ++++++++++++--------- 1 file changed, 44 insertions(+), 34 deletions(-) diff --git a/ErsatzTV/Shared/AddToCollectionDialog.razor b/ErsatzTV/Shared/AddToCollectionDialog.razor index a95e9a599..c6e116262 100644 --- a/ErsatzTV/Shared/AddToCollectionDialog.razor +++ b/ErsatzTV/Shared/AddToCollectionDialog.razor @@ -7,36 +7,35 @@ @inject ISnackbar Snackbar @inject ILogger Logger -
- - - - - - - @foreach (MediaCollectionViewModel collection in _collections) - { - @collection.Name - } - - - - - - Cancel - - Add To Collection - - - -
+ + + + + + + + @foreach (MediaCollectionViewModel collection in _collections) + { + @collection.Name + } + + + + + + + Cancel + + Add To Collection + + + @code { @@ -62,6 +61,9 @@ private List _collections; private MediaCollectionViewModel _selectedCollection; + + private record DummyModel; + private DummyModel _dummyModel = new(); private bool CanSubmit() => _selectedCollection != null && (_selectedCollection != _newCollection || !string.IsNullOrWhiteSpace(_newCollectionName)); @@ -85,6 +87,11 @@ private async Task Submit() { + if (!CanSubmit()) + { + return; + } + if (_selectedCollection == _newCollection) { Either maybeResult = @@ -110,14 +117,17 @@ } } - private void Cancel() => MudDialog.Cancel(); - - private async Task OnKeyDown(KeyboardEventArgs e) + private async Task Cancel(MouseEventArgs e) { - if (e.Code is "Enter" or "NumpadEnter" && CanSubmit()) + // this is gross, but [enter] seems to sometimes trigger cancel instead of submit + if (e.Detail == 0) { await Submit(); } + else + { + MudDialog.Cancel(); + } } } \ No newline at end of file