feat: add State C success panel, expand SavedListingsService.Save with draft fields

This commit is contained in:
2026-04-16 01:52:31 +01:00
parent bad466be1f
commit 987c778ae2
3 changed files with 76 additions and 9 deletions

View File

@@ -1,4 +1,4 @@
using EbayListingTool.Models; using EbayListingTool.Models;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace EbayListingTool.Services; namespace EbayListingTool.Services;
@@ -35,7 +35,11 @@ public class SavedListingsService
public (SavedListing Listing, int SkippedPhotos) Save( public (SavedListing Listing, int SkippedPhotos) Save(
string title, string description, decimal price, string title, string description, decimal price,
string category, string conditionNotes, string category, string conditionNotes,
IEnumerable<string> sourcePaths) IEnumerable<string> sourcePaths,
string categoryId = "",
ItemCondition condition = ItemCondition.Used,
ListingFormat format = ListingFormat.FixedPrice,
string postcode = "")
{ {
var safeName = MakeSafeFilename(title); var safeName = MakeSafeFilename(title);
var exportDir = UniqueDir(Path.Combine(ExportsDir, safeName)); var exportDir = UniqueDir(Path.Combine(ExportsDir, safeName));
@@ -68,6 +72,10 @@ public class SavedListingsService
Description = description, Description = description,
Price = price, Price = price,
Category = category, Category = category,
CategoryId = categoryId,
Condition = condition,
Format = format,
Postcode = postcode,
ConditionNotes = conditionNotes, ConditionNotes = conditionNotes,
ExportFolder = exportDir, ExportFolder = exportDir,
PhotoPaths = photoPaths PhotoPaths = photoPaths

View File

@@ -1,4 +1,4 @@
<UserControl x:Class="EbayListingTool.Views.NewListingView" <UserControl x:Class="EbayListingTool.Views.NewListingView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls" xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
@@ -405,7 +405,49 @@
</DockPanel> </DockPanel>
</Grid> </Grid>
<!-- ══════════════════════════════════════ STATE C: Success (stub for now) --> <!-- ═══════════════════════════════════════════════════════ STATE C: Success -->
<Grid x:Name="StateC" Visibility="Collapsed"/> <Grid x:Name="StateC" Visibility="Collapsed">
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" MaxWidth="480">
<!-- Success banner -->
<Border Background="#1A4CAF50" BorderBrush="#4CAF50" BorderThickness="0,0,0,3"
CornerRadius="8" Padding="24,16" Margin="0,0,0,28">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<iconPacks:PackIconMaterial Kind="CheckCircleOutline" Width="24" Height="24"
Foreground="#4CAF50" VerticalAlignment="Center" Margin="0,0,12,0"/>
<TextBlock Text="Listed successfully!" FontSize="18" FontWeight="SemiBold"
Foreground="#4CAF50" VerticalAlignment="Center"/>
</StackPanel>
</Border>
<!-- URL -->
<TextBlock Text="Your listing is live at:" FontSize="12"
Foreground="{DynamicResource MahApps.Brushes.Gray5}"
HorizontalAlignment="Center" Margin="0,0,0,8"/>
<TextBlock x:Name="BSuccessUrl"
FontSize="13" TextDecorations="Underline"
Foreground="{DynamicResource MahApps.Brushes.Accent}"
HorizontalAlignment="Center" Cursor="Hand" TextWrapping="Wrap"
TextAlignment="Center" Margin="0,0,0,16"
MouseLeftButtonUp="SuccessUrl_Click"/>
<Button x:Name="CopyUrlBtn" Click="CopyUrl_Click"
Style="{StaticResource MahApps.Styles.Button.Square}"
HorizontalAlignment="Center" Padding="16,8" Margin="0,0,0,36">
<StackPanel Orientation="Horizontal">
<iconPacks:PackIconMaterial Kind="ContentCopy" Width="13" Height="13"
Margin="0,0,6,0" VerticalAlignment="Center"/>
<TextBlock Text="Copy URL" VerticalAlignment="Center"/>
</StackPanel>
</Button>
<!-- List Another -->
<Button Click="ListAnother_Click"
Style="{StaticResource MahApps.Styles.Button.Square.Accent}"
HorizontalAlignment="Center" Padding="24,12" FontSize="14">
<StackPanel Orientation="Horizontal">
<iconPacks:PackIconMaterial Kind="Plus" Width="16" Height="16"
Margin="0,0,8,0" VerticalAlignment="Center"/>
<TextBlock Text="List Another Item" VerticalAlignment="Center"/>
</StackPanel>
</Button>
</StackPanel>
</Grid>
</Grid> </Grid>
</UserControl> </UserControl>

View File

@@ -1,4 +1,4 @@
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
@@ -633,7 +633,9 @@ 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, GetSelectedCondition().ToString(),
_draft.PhotoPaths); _draft.PhotoPaths,
_draft.CategoryId, _draft.Condition, _draft.Format,
BPostcodeBox.Text);
GetWindow()?.RefreshSavedListings(); GetWindow()?.RefreshSavedListings();
GetWindow()?.SetStatus($"Draft saved: {_draft.Title}"); GetWindow()?.SetStatus($"Draft saved: {_draft.Title}");
SaveDraftBtn.IsEnabled = false; SaveDraftBtn.IsEnabled = false;
@@ -654,8 +656,7 @@ public partial class NewListingView : UserControl
{ {
var url = await _listingService.PostListingAsync(_draft); var url = await _listingService.PostListingAsync(_draft);
_draft.EbayListingUrl = url; _draft.EbayListingUrl = url;
var urlBox = FindName("BSuccessUrl") as TextBlock; BSuccessUrl.Text = url;
if (urlBox != null) urlBox.Text = url;
SetState(ListingState.Success); SetState(ListingState.Success);
GetWindow()?.SetStatus($"Listed: {_draft.Title}"); GetWindow()?.SetStatus($"Listed: {_draft.Title}");
} }
@@ -698,6 +699,22 @@ public partial class NewListingView : UserControl
private void ShowError(string title, string msg) private void ShowError(string title, string msg)
=> MessageBox.Show(msg, title, MessageBoxButton.OK, MessageBoxImage.Warning); => MessageBox.Show(msg, title, MessageBoxButton.OK, MessageBoxImage.Warning);
// ---- State C handlers ----
private void SuccessUrl_Click(object sender, MouseButtonEventArgs e)
{
var url = BSuccessUrl.Text;
if (!string.IsNullOrEmpty(url))
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(url)
{ UseShellExecute = true });
}
private void CopyUrl_Click(object sender, RoutedEventArgs e)
=> System.Windows.Clipboard.SetText(BSuccessUrl.Text);
private void ListAnother_Click(object sender, RoutedEventArgs e)
=> ResetToStateA();
private static bool IsImageFile(string path) private static bool IsImageFile(string path)
{ {
var ext = System.IO.Path.GetExtension(path).ToLowerInvariant(); var ext = System.IO.Path.GetExtension(path).ToLowerInvariant();