fix: handle aspects load errors gracefully and preserve user values on category reselect
This commit is contained in:
@@ -18,6 +18,7 @@ public partial class SingleItemView : UserControl
|
|||||||
private EbayAuthService? _auth;
|
private EbayAuthService? _auth;
|
||||||
private EbayAspectsService? _aspectsService;
|
private EbayAspectsService? _aspectsService;
|
||||||
private List<CategoryAspect> _currentAspects = new();
|
private List<CategoryAspect> _currentAspects = new();
|
||||||
|
private string _lastAspectsCategoryId = "";
|
||||||
|
|
||||||
private ListingDraft _draft = new();
|
private ListingDraft _draft = new();
|
||||||
private System.Threading.CancellationTokenSource? _categoryCts;
|
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.
|
// is unexpected when arriving here automatically from the Photo Analysis tab.
|
||||||
_draft = new ListingDraft { Postcode = PostcodeBox.Text };
|
_draft = new ListingDraft { Postcode = PostcodeBox.Text };
|
||||||
_currentAspects = new();
|
_currentAspects = new();
|
||||||
|
_lastAspectsCategoryId = "";
|
||||||
AspectsPanel.Visibility = Visibility.Collapsed;
|
AspectsPanel.Visibility = Visibility.Collapsed;
|
||||||
TitleBox.Text = "";
|
TitleBox.Text = "";
|
||||||
DescriptionBox.Text = "";
|
DescriptionBox.Text = "";
|
||||||
@@ -639,6 +641,7 @@ public partial class SingleItemView : UserControl
|
|||||||
|
|
||||||
_draft = new ListingDraft { Postcode = PostcodeBox.Text };
|
_draft = new ListingDraft { Postcode = PostcodeBox.Text };
|
||||||
_currentAspects = new();
|
_currentAspects = new();
|
||||||
|
_lastAspectsCategoryId = "";
|
||||||
AspectsPanel.Visibility = Visibility.Collapsed;
|
AspectsPanel.Visibility = Visibility.Collapsed;
|
||||||
TitleBox.Text = "";
|
TitleBox.Text = "";
|
||||||
DescriptionBox.Text = "";
|
DescriptionBox.Text = "";
|
||||||
@@ -775,13 +778,24 @@ public partial class SingleItemView : UserControl
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
_currentAspects = await _aspectsService.GetAspectsAsync(categoryId);
|
_currentAspects = await _aspectsService.GetAspectsAsync(categoryId);
|
||||||
_draft.Aspects.Clear();
|
|
||||||
|
if (_lastAspectsCategoryId != categoryId)
|
||||||
|
{
|
||||||
|
_draft.Aspects.Clear();
|
||||||
|
_lastAspectsCategoryId = categoryId;
|
||||||
|
}
|
||||||
|
|
||||||
AspectsRequiredNote.Visibility = _currentAspects.Any(a => a.IsRequired)
|
AspectsRequiredNote.Visibility = _currentAspects.Any(a => a.IsRequired)
|
||||||
? Visibility.Visible : Visibility.Collapsed;
|
? Visibility.Visible : Visibility.Collapsed;
|
||||||
|
|
||||||
RebuildAspectFields();
|
RebuildAspectFields();
|
||||||
}
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// Non-critical — aspects are optional for the UI flow; hide panel on failure
|
||||||
|
_currentAspects = new();
|
||||||
|
AspectsPanel.Visibility = Visibility.Collapsed;
|
||||||
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
AspectsSpinner.Visibility = Visibility.Collapsed;
|
AspectsSpinner.Visibility = Visibility.Collapsed;
|
||||||
|
|||||||
Reference in New Issue
Block a user