Skip to content

Commit

Permalink
Add basic error alert
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobjmarks committed May 5, 2024
1 parent 9418808 commit d94e3d0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
16 changes: 13 additions & 3 deletions Client/Pages/Home.razor
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,12 @@
<MudTh>Binding Result</MudTh>
</HeaderContent>
<NoRecordsContent>
<MudText Typo="Typo.body2" Class="mud-text-secondary mx-5" Align="Align.Left">
No results
</MudText>
@if (!_showErrorAlert)
{
<MudText Typo="Typo.body2" Class="mud-text-secondary mx-5" Align="Align.Left">
No results
</MudText>
}
</NoRecordsContent>
<RowTemplate>
<MudTd DataLabel="Parameter Type">
Expand Down Expand Up @@ -133,4 +136,11 @@
</MudStack>
}
}

@if (_showErrorAlert)
{
<MudAlert Severity="Severity.Error" ShowCloseIcon="true" CloseIconClicked="@(() => _showErrorAlert = false)">
Oops! Something went wrong. Please try again.
</MudAlert>
}
</MudStack>
10 changes: 10 additions & 0 deletions Client/Pages/Home.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public sealed partial class Home : IDisposable

private MudTextField<string> _input = null!;
private bool loadingIndicator = false;
private bool _showErrorAlert;

private IEnumerable<BindingResults> bindingResults = [];

Expand All @@ -42,6 +43,9 @@ private void InputOnChange(string? value)
if (!loadingIndicator)
loadingIndicator = true;

if (_showErrorAlert)
_showErrorAlert = false;

RestartDebounceTimer();
}

Expand Down Expand Up @@ -116,6 +120,12 @@ private async Task GetBindingResultsAsync(string inputValue)
var results = await response.Content.ReadFromJsonAsync<IEnumerable<BindingResults>>() ?? [];
bindingResults = results.OrderBy(r => r.AllErroneous);
}
catch
{
bindingResults = [];
_showErrorAlert = true;
throw;
}
finally
{
isFetchingResults = false;
Expand Down

0 comments on commit d94e3d0

Please sign in to comment.