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