Refactor email suggestion handling logic

Refactored the handling of email suggestions to separate selection
and commitment logic. Updated `<DxListBox>`'s `ValueChanged`
handler to use `OnReceiverEmailSuggestionCommittedAsync` for
finalizing selections. Introduced `SelectReceiverEmailSuggestion`
as a synchronous helper method for managing selection updates.
Centralized clearing of suggestions in the new
`OnReceiverEmailSuggestionCommittedAsync` method. Simplified
keyboard navigation logic by replacing asynchronous calls with
synchronous selection handling. These changes improve code
clarity and reduce unnecessary asynchronous operations.
This commit is contained in:
2026-07-01 19:15:40 +02:00
parent 4d069cdaa0
commit 56ccab6377

View File

@@ -312,7 +312,7 @@
TValue="string"
Data="@_receiverEmailSuggestions"
Value="@_selectedReceiverEmailSuggestion"
ValueChanged="OnReceiverEmailSuggestionSelectedAsync"
ValueChanged="OnReceiverEmailSuggestionCommittedAsync"
SelectionMode="ListBoxSelectionMode.Single"
CssClass="w-100" />
</div>
@@ -535,12 +535,12 @@
if (e.Key == "ArrowDown")
{
var nextIndex = currentIndex < _receiverEmailSuggestions.Count - 1 ? currentIndex + 1 : 0;
await OnReceiverEmailSuggestionSelectedAsync(_receiverEmailSuggestions[nextIndex]);
SelectReceiverEmailSuggestion(_receiverEmailSuggestions[nextIndex]);
}
else if (e.Key == "ArrowUp")
{
var nextIndex = currentIndex > 0 ? currentIndex - 1 : _receiverEmailSuggestions.Count - 1;
await OnReceiverEmailSuggestionSelectedAsync(_receiverEmailSuggestions[nextIndex]);
SelectReceiverEmailSuggestion(_receiverEmailSuggestions[nextIndex]);
}
else if (e.Key == "Enter")
{
@@ -549,10 +549,7 @@
: _receiverEmailSuggestions.FirstOrDefault();
if (!string.IsNullOrWhiteSpace(selectedValue))
{
await OnReceiverEmailSuggestionSelectedAsync(selectedValue);
_receiverEmailSuggestions.Clear();
}
await OnReceiverEmailSuggestionCommittedAsync(selectedValue);
}
else if (e.Key == "Escape")
{
@@ -561,14 +558,26 @@
}
}
Task OnReceiverEmailSuggestionSelectedAsync(string? value)
void SelectReceiverEmailSuggestion(string? value)
{
if (string.IsNullOrWhiteSpace(value))
return Task.CompletedTask;
return;
_selectedReceiverEmailSuggestion = value.Trim();
_receiverDraftEmail = _selectedReceiverEmailSuggestion;
_receiverPopupValidationMessage = null;
}
Task OnReceiverEmailSuggestionSelectedAsync(string? value)
{
SelectReceiverEmailSuggestion(value);
return Task.CompletedTask;
}
Task OnReceiverEmailSuggestionCommittedAsync(string? value)
{
SelectReceiverEmailSuggestion(value);
_receiverEmailSuggestions.Clear();
return Task.CompletedTask;
}