From 1f7f28b3b98effc2ede4f0e6bab59048f4928edc Mon Sep 17 00:00:00 2001 From: Peter Date: Thu, 16 Apr 2026 02:13:43 +0100 Subject: [PATCH] fix: correct conditionNotes, persist post history, remove redundant Dispatcher.Invoke --- EbayListingTool/Views/NewListingView.xaml.cs | 33 +++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/EbayListingTool/Views/NewListingView.xaml.cs b/EbayListingTool/Views/NewListingView.xaml.cs index f223568..ac03b3a 100644 --- a/EbayListingTool/Views/NewListingView.xaml.cs +++ b/EbayListingTool/Views/NewListingView.xaml.cs @@ -338,12 +338,9 @@ public partial class NewListingView : UserControl if (cts.IsCancellationRequested) return; var suggestions = await _categoryService!.GetCategorySuggestionsAsync(text); if (cts.IsCancellationRequested) return; - Dispatcher.Invoke(() => - { - BCategoryList.ItemsSource = suggestions.Select(s => s.CategoryName).ToList(); - BCategoryList.Tag = suggestions; - BCategoryList.Visibility = suggestions.Count > 0 ? Visibility.Visible : Visibility.Collapsed; - }); + BCategoryList.ItemsSource = suggestions.Select(s => s.CategoryName).ToList(); + BCategoryList.Tag = suggestions; + BCategoryList.Visibility = suggestions.Count > 0 ? Visibility.Visible : Visibility.Collapsed; } catch (OperationCanceledException) { } catch { } @@ -623,7 +620,7 @@ public partial class NewListingView : UserControl SetState(ListingState.DropZone); } - private async void SaveDraft_Click(object sender, RoutedEventArgs e) + private void SaveDraft_Click(object sender, RoutedEventArgs e) { if (_savedService == null) return; if (!ValidateDraft()) return; @@ -632,15 +629,12 @@ public partial class NewListingView : UserControl { _savedService.Save( _draft.Title, _draft.Description, _draft.Price, - _draft.CategoryName, GetSelectedCondition().ToString(), + _draft.CategoryName, "", _draft.PhotoPaths, _draft.CategoryId, _draft.Condition, _draft.Format, BPostcodeBox.Text); GetWindow()?.RefreshSavedListings(); GetWindow()?.SetStatus($"Draft saved: {_draft.Title}"); - SaveDraftBtn.IsEnabled = false; - await Task.Delay(600); - SaveDraftBtn.IsEnabled = true; ResetToStateA(); } catch (Exception ex) { ShowError("Save Failed", ex.Message); } @@ -656,6 +650,23 @@ public partial class NewListingView : UserControl { var url = await _listingService.PostListingAsync(_draft); _draft.EbayListingUrl = url; + + // Persist a record of the posting + if (_savedService != null) + { + try + { + _savedService.Save( + _draft.Title, _draft.Description, _draft.Price, + _draft.CategoryName, $"Posted: {url}", + _draft.PhotoPaths, + _draft.CategoryId, _draft.Condition, _draft.Format, + _draft.Postcode); + GetWindow()?.RefreshSavedListings(); + } + catch { /* non-critical — posting succeeded, history save is best-effort */ } + } + BSuccessUrl.Text = url; SetState(ListingState.Success); GetWindow()?.SetStatus($"Listed: {_draft.Title}");