From e03fc0a49ce4c2dd0dfbfa8f9d9b35551c517e28 Mon Sep 17 00:00:00 2001 From: Peter Foster Date: Wed, 15 Apr 2026 09:42:31 +0100 Subject: [PATCH] fix: handle aspects load errors gracefully and preserve user values on category reselect --- EbayListingTool/Views/SingleItemView.xaml.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/EbayListingTool/Views/SingleItemView.xaml.cs b/EbayListingTool/Views/SingleItemView.xaml.cs index 164f089..e7911e2 100644 --- a/EbayListingTool/Views/SingleItemView.xaml.cs +++ b/EbayListingTool/Views/SingleItemView.xaml.cs @@ -18,6 +18,7 @@ public partial class SingleItemView : UserControl private EbayAuthService? _auth; private EbayAspectsService? _aspectsService; private List _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;