fix: handle aspects load errors gracefully and preserve user values on category reselect

This commit is contained in:
Peter Foster
2026-04-15 09:42:31 +01:00
parent d4dd11ed3e
commit e03fc0a49c

View File

@@ -18,6 +18,7 @@ public partial class SingleItemView : UserControl
private EbayAuthService? _auth;
private EbayAspectsService? _aspectsService;
private List<CategoryAspect> _currentAspects = new();
private string _lastAspectsCategoryId = "";
private ListingDraft _draft = new();
private System.Threading.CancellationTokenSource? _categoryCts;
@@ -63,6 +64,7 @@ public partial class SingleItemView : UserControl
// is unexpected when arriving here automatically from the Photo Analysis tab.
_draft = new ListingDraft { Postcode = PostcodeBox.Text };
_currentAspects = new();
_lastAspectsCategoryId = "";
AspectsPanel.Visibility = Visibility.Collapsed;
TitleBox.Text = "";
DescriptionBox.Text = "";
@@ -639,6 +641,7 @@ public partial class SingleItemView : UserControl
_draft = new ListingDraft { Postcode = PostcodeBox.Text };
_currentAspects = new();
_lastAspectsCategoryId = "";
AspectsPanel.Visibility = Visibility.Collapsed;
TitleBox.Text = "";
DescriptionBox.Text = "";
@@ -775,13 +778,24 @@ public partial class SingleItemView : UserControl
try
{
_currentAspects = await _aspectsService.GetAspectsAsync(categoryId);
_draft.Aspects.Clear();
if (_lastAspectsCategoryId != categoryId)
{
_draft.Aspects.Clear();
_lastAspectsCategoryId = categoryId;
}
AspectsRequiredNote.Visibility = _currentAspects.Any(a => a.IsRequired)
? Visibility.Visible : Visibility.Collapsed;
RebuildAspectFields();
}
catch
{
// Non-critical — aspects are optional for the UI flow; hide panel on failure
_currentAspects = new();
AspectsPanel.Visibility = Visibility.Collapsed;
}
finally
{
AspectsSpinner.Visibility = Visibility.Collapsed;