fix: correct conditionNotes, persist post history, remove redundant Dispatcher.Invoke

This commit is contained in:
2026-04-16 02:13:43 +01:00
parent 299c08248c
commit 1f7f28b3b9

View File

@@ -338,12 +338,9 @@ public partial class NewListingView : UserControl
if (cts.IsCancellationRequested) return; if (cts.IsCancellationRequested) return;
var suggestions = await _categoryService!.GetCategorySuggestionsAsync(text); var suggestions = await _categoryService!.GetCategorySuggestionsAsync(text);
if (cts.IsCancellationRequested) return; if (cts.IsCancellationRequested) return;
Dispatcher.Invoke(() =>
{
BCategoryList.ItemsSource = suggestions.Select(s => s.CategoryName).ToList(); BCategoryList.ItemsSource = suggestions.Select(s => s.CategoryName).ToList();
BCategoryList.Tag = suggestions; BCategoryList.Tag = suggestions;
BCategoryList.Visibility = suggestions.Count > 0 ? Visibility.Visible : Visibility.Collapsed; BCategoryList.Visibility = suggestions.Count > 0 ? Visibility.Visible : Visibility.Collapsed;
});
} }
catch (OperationCanceledException) { } catch (OperationCanceledException) { }
catch { } catch { }
@@ -623,7 +620,7 @@ public partial class NewListingView : UserControl
SetState(ListingState.DropZone); 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 (_savedService == null) return;
if (!ValidateDraft()) return; if (!ValidateDraft()) return;
@@ -632,15 +629,12 @@ public partial class NewListingView : UserControl
{ {
_savedService.Save( _savedService.Save(
_draft.Title, _draft.Description, _draft.Price, _draft.Title, _draft.Description, _draft.Price,
_draft.CategoryName, GetSelectedCondition().ToString(), _draft.CategoryName, "",
_draft.PhotoPaths, _draft.PhotoPaths,
_draft.CategoryId, _draft.Condition, _draft.Format, _draft.CategoryId, _draft.Condition, _draft.Format,
BPostcodeBox.Text); BPostcodeBox.Text);
GetWindow()?.RefreshSavedListings(); GetWindow()?.RefreshSavedListings();
GetWindow()?.SetStatus($"Draft saved: {_draft.Title}"); GetWindow()?.SetStatus($"Draft saved: {_draft.Title}");
SaveDraftBtn.IsEnabled = false;
await Task.Delay(600);
SaveDraftBtn.IsEnabled = true;
ResetToStateA(); ResetToStateA();
} }
catch (Exception ex) { ShowError("Save Failed", ex.Message); } catch (Exception ex) { ShowError("Save Failed", ex.Message); }
@@ -656,6 +650,23 @@ public partial class NewListingView : UserControl
{ {
var url = await _listingService.PostListingAsync(_draft); var url = await _listingService.PostListingAsync(_draft);
_draft.EbayListingUrl = url; _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; BSuccessUrl.Text = url;
SetState(ListingState.Success); SetState(ListingState.Success);
GetWindow()?.SetStatus($"Listed: {_draft.Title}"); GetWindow()?.SetStatus($"Listed: {_draft.Title}");