Browse Source

fix add to collection typing lag (#170)

pull/171/head
Jason Dove 5 years ago committed by GitHub
parent
commit
466059e2aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 30
      ErsatzTV/Shared/AddToCollectionDialog.razor

30
ErsatzTV/Shared/AddToCollectionDialog.razor

@ -7,16 +7,16 @@ @@ -7,16 +7,16 @@
@inject ISnackbar Snackbar
@inject ILogger<AddToCollectionDialog> Logger
<div @onkeydown="@OnKeyDown">
<MudDialog>
<DialogContent>
<EditForm Model="@_dummyModel" OnSubmit="@(_ => Submit())">
<MudContainer Class="mb-6">
<MudHighlighter Class="mud-primary-text"
Style="background-color: transparent; font-weight: bold"
Text="@FormatText()"
HighlightedText="@EntityName"/>
</MudContainer>
<MudSelect Label="Collection" @bind-Value="_selectedCollection" For="@(() => _selectedCollection)" Class="mb-6 mx-4">
<MudSelect Label="Collection" @bind-Value="_selectedCollection" Class="mb-6 mx-4">
@foreach (MediaCollectionViewModel collection in _collections)
{
<MudSelectItem Value="@collection">@collection.Name</MudSelectItem>
@ -25,18 +25,17 @@ @@ -25,18 +25,17 @@
<MudTextFieldString Label="New Collection Name"
Disabled="@(_selectedCollection != _newCollection)"
@bind-Text="@_newCollectionName"
Immediate="true"
Class="mb-6 mx-4">
</MudTextFieldString>
</EditForm>
</DialogContent>
<DialogActions>
<MudButton OnClick="Cancel">Cancel</MudButton>
<MudButton Color="Color.Primary" Variant="Variant.Filled" Disabled="@(!CanSubmit())" OnClick="Submit">
<MudButton OnClick="Cancel" ButtonType="ButtonType.Reset">Cancel</MudButton>
<MudButton Color="Color.Primary" Variant="Variant.Filled" OnClick="Submit">
Add To Collection
</MudButton>
</DialogActions>
</MudDialog>
</div>
@code {
@ -63,6 +62,9 @@ @@ -63,6 +62,9 @@
private MediaCollectionViewModel _selectedCollection;
private record DummyModel;
private DummyModel _dummyModel = new();
private bool CanSubmit() =>
_selectedCollection != null && (_selectedCollection != _newCollection || !string.IsNullOrWhiteSpace(_newCollectionName));
@ -85,6 +87,11 @@ @@ -85,6 +87,11 @@
private async Task Submit()
{
if (!CanSubmit())
{
return;
}
if (_selectedCollection == _newCollection)
{
Either<BaseError, MediaCollectionViewModel> maybeResult =
@ -110,14 +117,17 @@ @@ -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();
}
}
}
Loading…
Cancel
Save