Compare commits

18 Commits

Author SHA1 Message Date
Peter Foster
d9072a6018 fix: Content-Language header on offer creation; double photo thumbnails; sync Windows diverged files
- Add Content-Language: en-US to CreateOfferAsync (eBay Inventory API requires it)
- Double thumbnail sizes in NewListingView (96→192, 100→200)
- Sync NewListingView.xaml/.cs from Windows (replaces SingleItemView)
- Sync latest AiAssistantService, SavedListingsService, MainWindow, SavedListingsView from Windows

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-17 12:59:15 +01:00
Peter Foster
61bbe86323 fix: use Inventory API condition enum strings instead of legacy numeric IDs
eBay Inventory API rejects numeric condition IDs (e.g. "3000") and requires
string enums (e.g. "USED_VERY_GOOD"). Was causing 400 errors on every post attempt.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-17 12:52:15 +01:00
Peter Foster
3e476cbdf1 fix: pass empty string for conditionNotes in Save(ListingDraft) overload 2026-04-15 09:59:52 +01:00
Peter Foster
4cf5f11c9f feat: Relist button pre-populates form with aspects and shipping from saved listing
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-15 09:57:32 +01:00
Peter Foster
18bd3b910f feat: show aspects and shipping in saved listings detail panel
Adds postage/shipping-cost display, item specifics (aspects) panel, and
Relist button stub to the SavedListingsView detail panel.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-15 09:55:30 +01:00
Peter Foster
40c62dbf34 feat: auto-save listing to archive after successful eBay post 2026-04-15 09:53:01 +01:00
Peter Foster
8564c3d51c feat: add Save(ListingDraft) overload capturing aspects and shipping 2026-04-15 09:51:59 +01:00
Peter Foster
52f257b5ad feat: add CategoryId, Condition, Postage, ShippingCost, Aspects to SavedListing 2026-04-15 09:50:57 +01:00
Peter Foster
e03fc0a49c fix: handle aspects load errors gracefully and preserve user values on category reselect 2026-04-15 09:42:31 +01:00
Peter Foster
d4dd11ed3e feat: pass item aspects to eBay and set shipping defaults on bulk import
- Task 8: Convert aspects Dictionary<string,string> to Dictionary<string,string[]> in CreateInventoryItemAsync
- Task 9: Set Postage to RoyalMailTracked48 and ShippingCost to 3.49m on BulkImportRow.ToListingDraft()
2026-04-15 09:39:11 +01:00
Peter Foster
c9bdb6f7fe feat: create fulfillment policies on-demand per postage option and cost
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-15 09:37:25 +01:00
Peter Foster
a22e11b2f7 feat: wire aspects panel and shipping cost in SingleItemView code-behind
Implements LoadAspectsAsync/RebuildAspectFields, real PostageBox and AiAspects
handlers, ShippingCostBox wiring, required-aspects validation, and aspects
reset on new listing. Also registers EbayAspectsService in MainWindow (Task 6).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-15 09:34:07 +01:00
Peter Foster
f7b34b6a75 feat: add aspects panel and shipping cost field to SingleItemView XAML
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-15 09:30:02 +01:00
Peter Foster
0ae47e9427 feat: add SuggestAspectsAsync to AiAssistantService 2026-04-15 09:27:43 +01:00
Peter Foster
e70fb9ee5c feat: add EbayAspectsService with Taxonomy API aspect fetching
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-15 09:26:38 +01:00
Peter Foster
af6f3f9234 feat: add Aspects dict and ShippingCost to ListingDraft 2026-04-15 09:25:13 +01:00
Peter Foster
a9cfb7f613 Fix NullReferenceException in PriceSliderCard_ValueChanged
Slider ValueChanged fires during XAML init before named controls exist.
Guard with IsLoaded check, same pattern as UpdateCardTitleBar.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-15 03:06:17 +01:00
Peter Foster
b3ef79e495 Add dyscalculia-friendly UI: card preview, verbal prices, relative dates
- NumberWords helper: decimal → "about seventeen pounds", DateTime → "3 days ago"
- PhotoAnalysisView: after analysis shows a card preview with large verbal price,
  photo dots, "Looks good ✓" to save instantly, "Change something ▼" to reveal
  a price slider (snaps to 50p, updates verbally as you drag) and title bar
- Card preview updates when live eBay price lookup completes
- SavedListingsView cards: verbal price as primary, £x.xx small beneath,
  relative date ("yesterday", "3 days ago") instead of raw timestamp
- Detail panel also shows relative date

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-15 03:00:36 +01:00
20 changed files with 1892 additions and 1033 deletions

View File

@@ -0,0 +1,79 @@
namespace EbayListingTool.Helpers;
public static class NumberWords
{
private static readonly string[] Ones =
[
"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine",
"ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen",
"seventeen", "eighteen", "nineteen"
];
private static readonly string[] Tens =
[
"", "", "twenty", "thirty", "forty", "fifty",
"sixty", "seventy", "eighty", "ninety"
];
/// <summary>
/// Converts a price to a friendly verbal string.
/// £17.49 → "about seventeen pounds"
/// £17.50 → "about seventeen pounds fifty"
/// £0.50 → "fifty pence"
/// </summary>
public static string ToVerbalPrice(decimal price)
{
if (price <= 0) return "no price set";
// Snap to nearest 50p
var rounded = Math.Round(price * 2) / 2m;
int pounds = (int)rounded;
bool hasFifty = (rounded - pounds) >= 0.5m;
if (pounds == 0)
return "fifty pence";
var poundsWord = IntToWords(pounds);
var poundsLabel = pounds == 1 ? "pound" : "pounds";
var suffix = hasFifty ? " fifty" : "";
return $"about {poundsWord} {poundsLabel}{suffix}";
}
/// <summary>
/// Converts a UTC DateTime to a human-friendly relative string.
/// </summary>
public static string ToRelativeDate(DateTime utcTime)
{
var diff = DateTime.UtcNow - utcTime;
if (diff.TotalSeconds < 60) return "just now";
if (diff.TotalMinutes < 60) return $"{(int)diff.TotalMinutes} minutes ago";
if (diff.TotalHours < 2) return "about an hour ago";
if (diff.TotalHours < 24) return $"{(int)diff.TotalHours} hours ago";
if (diff.TotalDays < 2) return "yesterday";
if (diff.TotalDays < 7) return $"{(int)diff.TotalDays} days ago";
if (diff.TotalDays < 14) return "last week";
if (diff.TotalDays < 30) return $"{(int)(diff.TotalDays / 7)} weeks ago";
if (diff.TotalDays < 60) return "last month";
return $"{(int)(diff.TotalDays / 30)} months ago";
}
private static string IntToWords(int n)
{
if (n < 20) return Ones[n];
if (n < 100)
{
var t = Tens[n / 10];
var o = n % 10;
return o == 0 ? t : $"{t}-{Ones[o]}";
}
if (n < 1000)
{
var h = Ones[n / 100];
var rest = n % 100;
return rest == 0 ? $"{h} hundred" : $"{h} hundred and {IntToWords(rest)}";
}
return n.ToString(); // fallback for very large prices
}
}

View File

@@ -124,7 +124,9 @@ public class BulkImportRow : INotifyPropertyChanged
PhotoPaths = PhotoPaths.Split(',', StringSplitOptions.RemoveEmptyEntries)
.Select(x => x.Trim())
.Where(x => !string.IsNullOrEmpty(x))
.ToList()
.ToList(),
Postage = PostageOption.RoyalMailTracked48,
ShippingCost = 3.49m
};
}

View File

@@ -37,6 +37,8 @@ public class ListingDraft : INotifyPropertyChanged
private ItemCondition _condition = ItemCondition.Used;
private ListingFormat _format = ListingFormat.FixedPrice;
private PostageOption _postage = PostageOption.RoyalMailSecondClass;
private Dictionary<string, string> _aspects = new();
private decimal _shippingCost;
private string _categoryId = "";
private string _categoryName = "";
private string _postcode = "";
@@ -92,6 +94,18 @@ public class ListingDraft : INotifyPropertyChanged
set { _postage = value; OnPropertyChanged(); }
}
public Dictionary<string, string> Aspects
{
get => _aspects;
set { _aspects = value; OnPropertyChanged(); }
}
public decimal ShippingCost
{
get => _shippingCost;
set { _shippingCost = value; OnPropertyChanged(); }
}
public string CategoryId
{
get => _categoryId;
@@ -150,12 +164,12 @@ public class ListingDraft : INotifyPropertyChanged
public string ConditionId => Condition switch
{
ItemCondition.New => "1000",
ItemCondition.OpenBox => "1500",
ItemCondition.Refurbished => "2500",
ItemCondition.Used => "3000",
ItemCondition.ForPartsOrNotWorking => "7000",
_ => "3000"
ItemCondition.New => "NEW",
ItemCondition.OpenBox => "NEW_OTHER",
ItemCondition.Refurbished => "SELLER_REFURBISHED",
ItemCondition.Used => "USED_VERY_GOOD",
ItemCondition.ForPartsOrNotWorking => "FOR_PARTS_OR_NOT_WORKING",
_ => "USED_VERY_GOOD"
};
public event PropertyChangedEventHandler? PropertyChanged;

View File

@@ -1,4 +1,4 @@
namespace EbayListingTool.Models;
namespace EbayListingTool.Models;
public class PhotoAnalysisResult
{
@@ -18,6 +18,6 @@ public class PhotoAnalysisResult
public string PriceRangeDisplay =>
PriceMin > 0 && PriceMax > 0
? $"£{PriceMin:F2} £{PriceMax:F2} (suggested £{PriceSuggested:F2})"
: PriceSuggested > 0 ? $"£{PriceSuggested:F2}" : "";
? $"\u00A3{PriceMin:F2} \u00A3{PriceMax:F2} (suggested \u00A3{PriceSuggested:F2})"
: PriceSuggested > 0 ? $"\u00A3{PriceSuggested:F2}" : "";
}

View File

@@ -1,4 +1,4 @@
namespace EbayListingTool.Models;
namespace EbayListingTool.Models;
public class SavedListing
{
@@ -28,7 +28,7 @@ public class SavedListing
public string FirstPhotoPath => PhotoPaths.Count > 0 ? PhotoPaths[0] : "";
public string PriceDisplay => Price > 0 ? $"£{Price:F2}" : "—";
public string PriceDisplay => Price > 0 ? $"\u00A3{Price:F2}" : "—";
public string SavedAtDisplay => SavedAt.ToLocalTime().ToString("d MMM yyyy, HH:mm");

View File

@@ -1,4 +1,4 @@
using System.Net.Http;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using EbayListingTool.Models;
@@ -65,7 +65,7 @@ public class AiAssistantService
string priceContext = "";
if (soldPrices != null && soldPrices.Any())
{
var prices = soldPrices.Select(p => $"£{p:F2}");
var prices = soldPrices.Select(p => $"\u00A3{p:F2}");
priceContext = $"\nRecent eBay UK sold prices for similar items: {string.Join(", ", prices)}";
}
@@ -143,7 +143,7 @@ public class AiAssistantService
RefineWithCorrectionsAsync(string title, string description, decimal price, string corrections)
{
var priceContext = price > 0
? $"Current price: £{price:F2}\n\n"
? $"Current price: \u00A3{price:F2}\n\n"
: "";
var prompt =
@@ -246,7 +246,7 @@ public class AiAssistantService
" \"confidence_notes\": \"one sentence explaining confidence level, e.g. brand clearly visible on label\"\n" +
"}\n\n" +
"For prices: research realistic eBay UK sold prices in your knowledge. " +
"price_suggested should be a good Buy It Now price. Use GBP numbers only (no £ symbol).";
"price_suggested should be a good Buy It Now price. Use GBP numbers only (no \u00A3 symbol).";
var json = await CallWithVisionAsync(dataUrls, prompt);

View File

@@ -0,0 +1,74 @@
using System.Net.Http.Headers;
using Newtonsoft.Json.Linq;
namespace EbayListingTool.Services;
public class CategoryAspect
{
public string Name { get; set; } = "";
public bool IsRequired { get; set; }
public bool IsFreeText { get; set; } = true;
public List<string> AllowedValues { get; set; } = new();
}
public class EbayAspectsService
{
private readonly EbayAuthService _auth;
private static readonly HttpClient _http = new();
private readonly Dictionary<string, List<CategoryAspect>> _cache = new();
public EbayAspectsService(EbayAuthService auth) => _auth = auth;
public async Task<List<CategoryAspect>> GetAspectsAsync(string categoryId)
{
if (string.IsNullOrWhiteSpace(categoryId)) return new();
if (_cache.TryGetValue(categoryId, out var cached)) return cached;
var token = await _auth.GetAppTokenAsync();
var url = $"{_auth.BaseUrl}/commerce/taxonomy/v1/category_tree/3" +
$"/get_item_aspects_for_category?category_id={Uri.EscapeDataString(categoryId)}";
using var req = new HttpRequestMessage(HttpMethod.Get, url);
req.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
req.Headers.Add("X-EBAY-C-MARKETPLACE-ID", "EBAY_GB");
var res = await _http.SendAsync(req);
var json = await res.Content.ReadAsStringAsync();
if (!res.IsSuccessStatusCode) return new();
var aspects = new List<CategoryAspect>();
var arr = JObject.Parse(json)["aspects"] as JArray;
if (arr == null) { _cache[categoryId] = aspects; return aspects; }
foreach (var item in arr)
{
var constraint = item["aspectConstraint"];
if (constraint == null) continue;
var required = constraint["aspectRequired"]?.Value<bool>() ?? false;
var usage = constraint["aspectUsage"]?.ToString() ?? "";
if (!required && usage != "RECOMMENDED") continue;
var aspect = new CategoryAspect
{
Name = item["localizedAspectName"]?.ToString() ?? "",
IsRequired = required,
IsFreeText = constraint["aspectMode"]?.ToString() != "SELECTION_ONLY"
};
var values = item["aspectValues"] as JArray;
if (values != null)
aspect.AllowedValues = values
.Select(v => v["localizedValue"]?.ToString() ?? "")
.Where(v => !string.IsNullOrEmpty(v))
.Take(50)
.ToList();
if (!string.IsNullOrEmpty(aspect.Name))
aspects.Add(aspect);
}
_cache[categoryId] = aspects;
return aspects;
}
}

View File

@@ -22,27 +22,56 @@ public class EbayListingService
private string? _returnPolicyId;
private string? _merchantLocationKey;
private readonly Dictionary<string, string> _policyCache = new();
private static readonly string PolicyCacheFile =
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"EbayListingTool", "fulfillment_policies.json");
public EbayListingService(EbayAuthService auth, EbayCategoryService categoryService)
{
_auth = auth;
_categoryService = categoryService;
LoadPolicyCacheFromDisk();
}
/// <summary>Call when the user disconnects so stale IDs are not reused after re-login.</summary>
public void ClearCache()
{
_fulfillmentPolicyId = null;
_paymentPolicyId = null;
_returnPolicyId = null;
_merchantLocationKey = null;
}
private void LoadPolicyCacheFromDisk()
{
try
{
if (!File.Exists(PolicyCacheFile)) return;
var json = File.ReadAllText(PolicyCacheFile);
var dict = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
if (dict != null)
foreach (var kv in dict) _policyCache[kv.Key] = kv.Value;
}
catch { /* ignore corrupt cache */ }
}
private void SavePolicyCacheToDisk()
{
try
{
Directory.CreateDirectory(Path.GetDirectoryName(PolicyCacheFile)!);
File.WriteAllText(PolicyCacheFile, JsonConvert.SerializeObject(_policyCache));
}
catch { /* non-critical */ }
}
public async Task<string> PostListingAsync(ListingDraft draft)
{
var token = await _auth.GetValidAccessTokenAsync();
// Resolve business policies and merchant location before touching inventory/offers
await EnsurePoliciesAndLocationAsync(token, draft.Postcode);
_fulfillmentPolicyId = await GetOrCreateFulfillmentPolicyAsync(draft.Postage, draft.ShippingCost, token);
// 1. Upload photos and get eBay-hosted URLs
var imageUrls = await UploadPhotosAsync(draft.PhotoPaths, token);
@@ -73,6 +102,94 @@ public class EbayListingService
return draft.EbayListingUrl;
}
// ---- Fulfillment policy: on-demand creation ----
private static string ToShippingServiceCode(PostageOption option) => option switch
{
PostageOption.RoyalMailFirstClass => "UK_RoyalMailFirstClassStandard",
PostageOption.RoyalMailSecondClass => "UK_RoyalMailSecondClassStandard",
PostageOption.RoyalMailTracked24 => "UK_RoyalMailTracked24",
PostageOption.RoyalMailTracked48 => "UK_RoyalMailTracked48",
PostageOption.CollectionOnly => "UK_CollectInPerson",
PostageOption.FreePostage => "UK_RoyalMailSecondClassStandard",
_ => "UK_RoyalMailSecondClassStandard"
};
private async Task<string> GetOrCreateFulfillmentPolicyAsync(
PostageOption postage, decimal shippingCost, string token)
{
var free = postage == PostageOption.FreePostage || postage == PostageOption.CollectionOnly;
var cost = free ? 0m : shippingCost;
var cacheKey = $"{postage}_{cost:F2}";
if (_policyCache.TryGetValue(cacheKey, out var cached)) return cached;
var serviceCode = ToShippingServiceCode(postage);
var policyName = $"ELT_{postage}_{cost:F2}".Replace(" ", "");
object shippingServiceObj;
if (postage == PostageOption.CollectionOnly)
{
shippingServiceObj = new
{
shippingServiceCode = serviceCode,
shippingCost = new { value = "0.00", currency = "GBP" },
freeShipping = false,
buyerResponsibleForShipping = true,
sortOrder = 1
};
}
else
{
shippingServiceObj = new
{
shippingCarrierCode = "RoyalMail",
shippingServiceCode = serviceCode,
shippingCost = new { value = cost.ToString("F2"), currency = "GBP" },
freeShipping = free,
sortOrder = 1
};
}
var body = new
{
name = policyName,
marketplaceId = "EBAY_GB",
categoryTypes = new[] { new { name = "ALL_EXCLUDING_MOTORS_VEHICLES" } },
handlingTime = new { value = 2, unit = "DAY" },
shippingOptions = new[]
{
new
{
optionType = "DOMESTIC",
costType = postage == PostageOption.CollectionOnly ? "NOT_SPECIFIED" : "FLAT_RATE",
shippingServices = new[] { shippingServiceObj }
}
}
};
var json = JsonConvert.SerializeObject(body,
new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
using var req = MakeRequest(HttpMethod.Post,
$"{_auth.BaseUrl}/sell/account/v1/fulfillment_policy", token);
req.Content = new StringContent(json, Encoding.UTF8, "application/json");
var res = await _http.SendAsync(req);
var resJson = await res.Content.ReadAsStringAsync();
if (!res.IsSuccessStatusCode)
throw new HttpRequestException(
$"Could not create fulfillment policy ({(int)res.StatusCode}): {resJson}");
var policyId = JObject.Parse(resJson)["fulfillmentPolicyId"]?.ToString()
?? throw new InvalidOperationException("No fulfillmentPolicyId in response.");
_policyCache[cacheKey] = policyId;
SavePolicyCacheToDisk();
return policyId;
}
// ---- Setup: policies + location ----
/// <summary>
@@ -84,28 +201,6 @@ public class EbayListingService
{
var baseUrl = _auth.BaseUrl;
if (_fulfillmentPolicyId == null)
{
using var req = MakeRequest(HttpMethod.Get,
$"{baseUrl}/sell/account/v1/fulfillment_policy?marketplace_id=EBAY_GB", token);
var res = await _http.SendAsync(req);
var json = await res.Content.ReadAsStringAsync();
if (!res.IsSuccessStatusCode)
throw new HttpRequestException(
$"Could not fetch fulfillment policies ({(int)res.StatusCode}): {json}");
var arr = JObject.Parse(json)["fulfillmentPolicies"] as JArray;
_fulfillmentPolicyId = arr?.Count > 0
? arr[0]["fulfillmentPolicyId"]?.ToString()
: null;
if (_fulfillmentPolicyId == null)
throw new InvalidOperationException(
"No fulfillment policy found on your eBay account.\n\n" +
"Please set one up in My eBay → Account → Business policies, then try again.");
}
if (_paymentPolicyId == null)
{
using var req = MakeRequest(HttpMethod.Get,
@@ -222,7 +317,9 @@ public class EbayListingService
title = draft.Title,
description = draft.Description,
imageUrls = imageUrls.Count > 0 ? imageUrls : null,
aspects = (object?)null
aspects = draft.Aspects.Count > 0
? draft.Aspects.ToDictionary(kv => kv.Key, kv => new[] { kv.Value })
: (object?)null
}
};
@@ -278,6 +375,7 @@ public class EbayListingService
using var req = MakeRequest(HttpMethod.Post,
$"{_auth.BaseUrl}/sell/inventory/v1/offer", token);
req.Content = new StringContent(json, Encoding.UTF8, "application/json");
req.Content.Headers.Add("Content-Language", "en-US");
var res = await _http.SendAsync(req);
var responseJson = await res.Content.ReadAsStringAsync();

View File

@@ -1,4 +1,4 @@
using System.Text.RegularExpressions;
using System.Text.RegularExpressions;
using EbayListingTool.Models;
namespace EbayListingTool.Services;
@@ -39,7 +39,7 @@ public class PriceLookupService
return new PriceSuggestion(
result.Suggested,
"ebay",
$"eBay suggests £{result.Suggested:F2} (from {result.Count} listings)");
$"eBay suggests \u00A3{result.Suggested:F2} (from {result.Count} listings)");
}
catch { /* eBay unavailable — fall through */ }
@@ -58,7 +58,7 @@ public class PriceLookupService
return new PriceSuggestion(
avg,
"history",
$"Your avg for {listing.Category}: £{avg:F2} ({sameCat.Count} listings)");
$"Your avg for {listing.Category}: \u00A3{avg:F2} ({sameCat.Count} listings)");
}
// 3. AI estimate
@@ -73,7 +73,7 @@ public class PriceLookupService
out var price)
&& price > 0)
{
return new PriceSuggestion(price, "ai", $"AI estimate: £{price:F2}");
return new PriceSuggestion(price, "ai", $"AI estimate: \u00A3{price:F2}");
}
}
catch { /* AI unavailable */ }

View File

@@ -1,4 +1,4 @@
using EbayListingTool.Models;
using EbayListingTool.Models;
using Newtonsoft.Json;
namespace EbayListingTool.Services;
@@ -35,7 +35,11 @@ public class SavedListingsService
public (SavedListing Listing, int SkippedPhotos) Save(
string title, string description, decimal price,
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 exportDir = UniqueDir(Path.Combine(ExportsDir, safeName));
@@ -68,6 +72,10 @@ public class SavedListingsService
Description = description,
Price = price,
Category = category,
CategoryId = categoryId,
Condition = condition,
Format = format,
Postcode = postcode,
ConditionNotes = conditionNotes,
ExportFolder = exportDir,
PhotoPaths = photoPaths
@@ -188,7 +196,7 @@ public class SavedListingsService
var sb = new System.Text.StringBuilder();
sb.AppendLine($"Title: {title}");
sb.AppendLine($"Category: {category}");
sb.AppendLine($"Price: £{price:F2}");
sb.AppendLine($"Price: \u00A3{price:F2}");
if (!string.IsNullOrWhiteSpace(conditionNotes))
sb.AppendLine($"Condition: {conditionNotes}");
sb.AppendLine();

View File

@@ -1,13 +1,14 @@
<mah:MetroWindow x:Class="EbayListingTool.Views.MainWindow"
<mah:MetroWindow x:Class="EbayListingTool.Views.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
xmlns:local="clr-namespace:EbayListingTool.Views"
Title="eBay Listing Tool UK"
Title="eBay Listing Tool - UK"
Height="820" Width="1180"
MinHeight="600" MinWidth="900"
WindowStartupLocation="CenterScreen"
Icon="/EbayListingTool;component/app_icon.ico"
GlowBrush="{DynamicResource MahApps.Brushes.Accent}">
<mah:MetroWindow.Resources>
@@ -59,105 +60,62 @@
</EventTrigger>
</Style.Triggers>
</Style>
<!-- Shared style for tab header icon -->
<Style x:Key="TabHeaderIcon" TargetType="iconPacks:PackIconMaterial">
<Setter Property="Width" Value="15"/>
<Setter Property="Height" Value="15"/>
<Setter Property="Margin" Value="0,0,7,0"/>
<Setter Property="VerticalAlignment" Value="Center"/>
</Style>
</mah:MetroWindow.Resources>
<mah:MetroWindow.RightWindowCommands>
<mah:WindowCommands>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" Margin="0,0,8,0">
<Border CornerRadius="10" Padding="8,3" Margin="0,0,8,0"
Background="#22FFFFFF" VerticalAlignment="Center">
<StackPanel Orientation="Horizontal">
<Ellipse x:Name="StatusDot" Style="{StaticResource ConnectedDotStyle}" Fill="#777"/>
<TextBlock x:Name="StatusLabel" Text="eBay: not connected"
Foreground="White" VerticalAlignment="Center"
FontSize="11" FontWeight="SemiBold"/>
</StackPanel>
</Border>
<Button x:Name="ConnectBtn" Click="ConnectBtn_Click"
Style="{DynamicResource MahApps.Styles.Button.Square.Accent}"
Height="28" Padding="10,0">
<StackPanel Orientation="Horizontal">
<iconPacks:PackIconMaterial Kind="Link" Width="12" Height="12"
Margin="0,0,4,0" VerticalAlignment="Center"/>
<TextBlock Text="Connect to eBay" VerticalAlignment="Center" FontSize="12"/>
</StackPanel>
</Button>
<Button x:Name="DisconnectBtn" Visibility="Collapsed"
Margin="6,0,0,0" Click="DisconnectBtn_Click"
Style="{DynamicResource MahApps.Styles.Button.Square}"
Height="28" Padding="8,0">
<StackPanel Orientation="Horizontal">
<iconPacks:PackIconMaterial Kind="LinkVariantOff" Width="12" Height="12"
Margin="0,0,4,0" VerticalAlignment="Center"/>
<TextBlock Text="Disconnect" VerticalAlignment="Center" FontSize="12"/>
</StackPanel>
</Button>
</StackPanel>
</mah:WindowCommands>
</mah:MetroWindow.RightWindowCommands>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TabControl x:Name="MainTabs" Grid.Row="0"
<!-- Menu bar -->
<Menu Grid.Row="0"
Background="{DynamicResource MahApps.Brushes.Gray9}"
BorderThickness="0,0,0,1"
BorderBrush="{DynamicResource MahApps.Brushes.Gray7}">
<MenuItem Header="_File">
<MenuItem x:Name="BulkImportMenuItem" Header="Bulk Import..."
Click="BulkImport_Click">
<MenuItem.Icon>
<iconPacks:PackIconMaterial Kind="TableMultiple" Width="14" Height="14"/>
</MenuItem.Icon>
</MenuItem>
<Separator/>
<MenuItem Header="E_xit" Click="Exit_Click"/>
</MenuItem>
</Menu>
<!-- 2 tabs -->
<TabControl x:Name="MainTabs" Grid.Row="1"
Style="{DynamicResource MahApps.Styles.TabControl.Animated}">
<!-- ① Photo Analysis — always available, no eBay login needed -->
<TabItem Style="{StaticResource AppTabItem}">
<TabItem.Header>
<StackPanel Orientation="Horizontal">
<iconPacks:PackIconMaterial Kind="Camera" Width="15" Height="15"
Margin="0,0,7,0" VerticalAlignment="Center"/>
<TextBlock Text="Photo Analyser" VerticalAlignment="Center"/>
</StackPanel>
</TabItem.Header>
<!-- Tab content: welcome banner + actual view stacked -->
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!-- Welcome banner — only shown when no photo loaded yet (PhotoView sets Visibility via x:Name) -->
<Border x:Name="WelcomeBanner" Grid.Row="0"
Background="{DynamicResource MahApps.Brushes.Accent}"
Padding="14,7" Visibility="Visible">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<iconPacks:PackIconMaterial Kind="Camera" Width="14" Height="14"
Margin="0,0,8,0" VerticalAlignment="Center"
Foreground="White"/>
<TextBlock Text="Drop a photo to identify any item and get an instant eBay price"
Foreground="White" FontSize="12" FontWeight="SemiBold"
VerticalAlignment="Center"/>
</StackPanel>
</Border>
<local:PhotoAnalysisView x:Name="PhotoView" Grid.Row="1"/>
</Grid>
</TabItem>
<!-- ② New Listing — requires eBay connection -->
<!-- New Listing tab -->
<TabItem x:Name="NewListingTab" Style="{StaticResource AppTabItem}">
<TabItem.Header>
<StackPanel Orientation="Horizontal">
<iconPacks:PackIconMaterial Kind="TagPlusOutline" Width="15" Height="15"
Margin="0,0,7,0" VerticalAlignment="Center"/>
<iconPacks:PackIconMaterial Kind="CameraPlus"
Style="{StaticResource TabHeaderIcon}"/>
<TextBlock Text="New Listing" VerticalAlignment="Center"/>
</StackPanel>
</TabItem.Header>
<Grid>
<local:SingleItemView x:Name="SingleView"/>
<!-- Overlay shown when not connected -->
<local:NewListingView x:Name="NewListingView"/>
<!-- Overlay when not connected to eBay -->
<Border x:Name="NewListingOverlay" Visibility="Visible"
Background="{DynamicResource MahApps.Brushes.ThemeBackground}">
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center"
MaxWidth="340">
<!-- eBay logo circle -->
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" MaxWidth="340">
<Border Width="72" Height="72" CornerRadius="36"
HorizontalAlignment="Center" Margin="0,0,0,18">
<Border.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
<GradientStop Color="#7C3AED" Offset="0"/>
@@ -167,20 +125,21 @@
<iconPacks:PackIconMaterial Kind="CartOutline" Width="32" Height="32"
Foreground="White"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
VerticalAlignment="Center"
/>
</Border>
<TextBlock Text="Connect to eBay"
FontSize="20" FontWeight="Bold"
<TextBlock Text="Connect to eBay" FontSize="20" FontWeight="Bold"
HorizontalAlignment="Center"
Foreground="{DynamicResource MahApps.Brushes.ThemeForeground}"
Margin="0,0,0,8"/>
<TextBlock Text="Sign in with your eBay account to start posting listings and managing your inventory."
<TextBlock Text="Sign in with your eBay account to identify items, get prices, and post listings."
FontSize="13" TextWrapping="Wrap" TextAlignment="Center"
Foreground="{DynamicResource MahApps.Brushes.Gray5}"
Margin="0,0,0,24"/>
<Button Click="ConnectBtn_Click"
<Button x:Name="ConnectBtn" Click="ConnectBtn_Click"
Style="{StaticResource LockConnectButton}"
HorizontalAlignment="Center">
HorizontalAlignment="Center"
AutomationProperties.Name="Connect to eBay account">
<StackPanel Orientation="Horizontal">
<iconPacks:PackIconMaterial Kind="Link" Width="14" Height="14"
Margin="0,0,7,0" VerticalAlignment="Center"/>
@@ -192,73 +151,21 @@
</Grid>
</TabItem>
<!-- ③ Saved Listings — always available -->
<TabItem x:Name="SavedTab" Style="{StaticResource AppTabItem}">
<!-- Drafts tab -->
<TabItem x:Name="DraftsTab" Style="{StaticResource AppTabItem}">
<TabItem.Header>
<StackPanel Orientation="Horizontal">
<iconPacks:PackIconMaterial Kind="BookmarkMultiple" Width="15" Height="15"
Margin="0,0,7,0" VerticalAlignment="Center"/>
<TextBlock Text="Saved Listings" VerticalAlignment="Center"/>
<iconPacks:PackIconMaterial Kind="BookmarkMultiple"
Style="{StaticResource TabHeaderIcon}"/>
<TextBlock Text="Drafts" VerticalAlignment="Center"/>
</StackPanel>
</TabItem.Header>
<local:SavedListingsView x:Name="SavedView"/>
</TabItem>
<!-- ④ Bulk Import — requires eBay connection -->
<TabItem x:Name="BulkTab" Style="{StaticResource AppTabItem}">
<TabItem.Header>
<StackPanel Orientation="Horizontal">
<iconPacks:PackIconMaterial Kind="TableMultiple" Width="15" Height="15"
Margin="0,0,7,0" VerticalAlignment="Center"/>
<TextBlock Text="Bulk Import" VerticalAlignment="Center"/>
</StackPanel>
</TabItem.Header>
<Grid>
<local:BulkImportView x:Name="BulkView"/>
<Border x:Name="BulkOverlay" Visibility="Visible"
Background="{DynamicResource MahApps.Brushes.ThemeBackground}">
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center"
MaxWidth="340">
<!-- eBay logo circle -->
<Border Width="72" Height="72" CornerRadius="36"
HorizontalAlignment="Center" Margin="0,0,0,18">
<Border.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
<GradientStop Color="#7C3AED" Offset="0"/>
<GradientStop Color="#4F46E5" Offset="1"/>
</LinearGradientBrush>
</Border.Background>
<iconPacks:PackIconMaterial Kind="TableArrowUp" Width="32" Height="32"
Foreground="White"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
</Border>
<TextBlock Text="Connect to eBay"
FontSize="20" FontWeight="Bold"
HorizontalAlignment="Center"
Foreground="{DynamicResource MahApps.Brushes.ThemeForeground}"
Margin="0,0,0,8"/>
<TextBlock Text="Sign in with your eBay account to bulk import and post multiple listings at once."
FontSize="13" TextWrapping="Wrap" TextAlignment="Center"
Foreground="{DynamicResource MahApps.Brushes.Gray5}"
Margin="0,0,0,24"/>
<Button Click="ConnectBtn_Click"
Style="{StaticResource LockConnectButton}"
HorizontalAlignment="Center">
<StackPanel Orientation="Horizontal">
<iconPacks:PackIconMaterial Kind="Link" Width="14" Height="14"
Margin="0,0,7,0" VerticalAlignment="Center"/>
<TextBlock Text="Connect to eBay" VerticalAlignment="Center"/>
</StackPanel>
</Button>
</StackPanel>
</Border>
</Grid>
</TabItem>
</TabControl>
<!-- Status bar -->
<Border Grid.Row="1"
<Border Grid.Row="2"
Background="{DynamicResource MahApps.Brushes.Gray9}"
BorderThickness="0,1,0,0"
BorderBrush="{DynamicResource MahApps.Brushes.Gray7}">
@@ -271,7 +178,8 @@
<iconPacks:PackIconMaterial Kind="AlertCircleOutline"
Width="12" Height="12" Margin="0,0,5,0"
VerticalAlignment="Center"
Foreground="{DynamicResource MahApps.Brushes.Gray5}"/>
Foreground="{DynamicResource MahApps.Brushes.Gray5}"
/>
<TextBlock x:Name="StatusBar" Text="Ready" FontSize="11"
Foreground="{DynamicResource MahApps.Brushes.Gray5}"
VerticalAlignment="Center"/>
@@ -282,6 +190,14 @@
<TextBlock x:Name="StatusBarEbay" Text="eBay: disconnected"
FontSize="11" VerticalAlignment="Center"
Foreground="{DynamicResource MahApps.Brushes.Gray3}"/>
<!-- Disconnect button shown when connected -->
<Button x:Name="DisconnectBtn" Click="DisconnectBtn_Click"
Visibility="Collapsed"
Style="{StaticResource MahApps.Styles.Button.Square}"
Padding="6,2" Margin="8,0,0,0" FontSize="10"
AutomationProperties.Name="Disconnect from eBay">
<TextBlock Text="Disconnect"/>
</Button>
</StackPanel>
</Grid>
</Border>

View File

@@ -31,18 +31,13 @@ public partial class MainWindow : MetroWindow
_priceService = new EbayPriceResearchService(_auth);
_priceLookupService = new PriceLookupService(_priceService, _savedService, _aiService);
// Photo Analysis tab — no eBay needed
PhotoView.Initialise(_aiService, _savedService, _priceService);
PhotoView.UseDetailsRequested += OnUseDetailsRequested;
var defaultPostcode = config["Ebay:DefaultPostcode"] ?? "";
// Saved Listings tab
SavedView.Initialise(_savedService, _priceLookupService);
NewListingView.Initialise(_listingService, _categoryService, _aiService, _auth,
_savedService, defaultPostcode);
// New Listing + Bulk tabs
SingleView.Initialise(_listingService, _categoryService, _aiService, _auth);
BulkView.Initialise(_listingService, _categoryService, _aiService, _bulkService, _auth);
SavedView.Initialise(_savedService, _priceLookupService, _listingService, _auth);
// Try to restore saved eBay session
_auth.TryLoadSavedToken();
UpdateConnectionState();
}
@@ -52,7 +47,7 @@ public partial class MainWindow : MetroWindow
private async void ConnectBtn_Click(object sender, RoutedEventArgs e)
{
ConnectBtn.IsEnabled = false;
SetStatus("Connecting to eBay");
SetStatus("Connecting to eBay...");
try
{
var username = await _auth.LoginAsync();
@@ -68,14 +63,14 @@ public partial class MainWindow : MetroWindow
finally
{
ConnectBtn.IsEnabled = true;
UpdateConnectionState(); // always sync UI to actual auth state
UpdateConnectionState();
}
}
private void DisconnectBtn_Click(object sender, RoutedEventArgs e)
{
_auth.Disconnect();
_listingService.ClearCache(); // clear cached policy/location IDs for next login
_listingService.ClearCache();
UpdateConnectionState();
SetStatus("Disconnected from eBay.");
}
@@ -83,50 +78,48 @@ public partial class MainWindow : MetroWindow
private void UpdateConnectionState()
{
var connected = _auth.IsConnected;
// Per-tab overlays (Photo Analysis tab has no overlay)
NewListingOverlay.Visibility = connected ? Visibility.Collapsed : Visibility.Visible;
BulkOverlay.Visibility = connected ? Visibility.Collapsed : Visibility.Visible;
ConnectBtn.Visibility = connected ? Visibility.Collapsed : Visibility.Visible;
DisconnectBtn.Visibility = connected ? Visibility.Visible : Visibility.Collapsed;
if (connected)
{
StatusDot.Fill = new SolidColorBrush(Colors.LimeGreen);
StatusLabel.Text = $"eBay: {_auth.ConnectedUsername}";
StatusBarDot.Fill = new SolidColorBrush(Colors.LimeGreen);
StatusBarEbay.Text = $"eBay: {_auth.ConnectedUsername}";
StatusBarEbay.Foreground = new SolidColorBrush(Colors.LimeGreen);
DisconnectBtn.Visibility = Visibility.Visible;
}
else
{
StatusDot.Fill = new SolidColorBrush(Colors.Gray);
StatusLabel.Text = "eBay: not connected";
StatusBarDot.Fill = new SolidColorBrush(Color.FromRgb(0x88, 0x88, 0x88));
StatusBarEbay.Text = "eBay: disconnected";
StatusBarEbay.Foreground = (Brush)FindResource("MahApps.Brushes.Gray5");
DisconnectBtn.Visibility = Visibility.Collapsed;
}
}
// ---- Photo Analysis → New Listing handoff ----
// ---- File menu ----
private void OnUseDetailsRequested(PhotoAnalysisResult result, IReadOnlyList<string> photoPaths, decimal price)
private void BulkImport_Click(object sender, RoutedEventArgs e)
{
SingleView.PopulateFromAnalysis(result, photoPaths, price); // Q1: forward all photos
}
public void SwitchToNewListingTab()
if (!_auth.IsConnected)
{
MainTabs.SelectedItem = NewListingTab;
MessageBox.Show("Please connect to eBay before using Bulk Import.",
"Not Connected", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
var win = new BulkImportWindow(_listingService, _categoryService, _aiService, _bulkService, _auth);
win.Owner = this;
win.ShowDialog();
}
public void RefreshSavedListings()
{
SavedView.RefreshList();
}
private void Exit_Click(object sender, RoutedEventArgs e) => Close();
// ---- Helpers ----
// ---- Public interface for child views ----
public void SetStatus(string message) => StatusBar.Text = message;
public void SwitchToNewListingTab() => MainTabs.SelectedItem = NewListingTab;
public void RefreshDrafts() => SavedView.RefreshList();
public void RefreshSavedListings() => RefreshDrafts(); // backwards compat for NewListingView
}

View File

@@ -1,17 +1,67 @@
<UserControl x:Class="EbayListingTool.Views.NewListingView"
<UserControl x:Class="EbayListingTool.Views.NewListingView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
Loaded="UserControl_Loaded">
<UserControl.Resources>
<!-- Shared style for AI action buttons (Title AI, Desc AI, Price Research) -->
<Style x:Key="AiActionButton" TargetType="Button"
BasedOn="{StaticResource MahApps.Styles.Button.Square}">
<Setter Property="Padding" Value="6,2"/>
</Style>
<!-- Shared style for field labels -->
<Style x:Key="FieldLabel" TargetType="TextBlock">
<Setter Property="FontSize" Value="13"/>
<Setter Property="FontWeight" Value="SemiBold"/>
<Setter Property="Foreground" Value="{DynamicResource MahApps.Brushes.Gray3}"/>
</Style>
<!-- Shared style for section headers (PHOTOS, LISTING DETAILS) -->
<Style x:Key="SectionHeader" TargetType="TextBlock">
<Setter Property="FontSize" Value="12"/>
<Setter Property="FontWeight" Value="SemiBold"/>
<Setter Property="Foreground" Value="{DynamicResource MahApps.Brushes.Gray5}"/>
</Style>
<!-- Shared style for subtitle/hint text -->
<Style x:Key="HintText" TargetType="TextBlock">
<Setter Property="FontSize" Value="13"/>
<Setter Property="Foreground" Value="{DynamicResource MahApps.Brushes.Gray5}"/>
</Style>
<!-- Shared style for character count labels -->
<Style x:Key="CharCountLabel" TargetType="TextBlock">
<Setter Property="FontSize" Value="12"/>
<Setter Property="Margin" Value="6,0,0,0"/>
<Setter Property="Foreground" Value="{DynamicResource MahApps.Brushes.Gray5}"/>
</Style>
<!-- Shared style for progress track background -->
<Style x:Key="ProgressTrack" TargetType="Border">
<Setter Property="Height" Value="3"/>
<Setter Property="CornerRadius" Value="1.5"/>
<Setter Property="Background" Value="{DynamicResource MahApps.Brushes.Gray8}"/>
</Style>
<!-- Shared style for progress track fill -->
<Style x:Key="ProgressFill" TargetType="Border">
<Setter Property="Height" Value="3"/>
<Setter Property="CornerRadius" Value="1.5"/>
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="Width" Value="0"/>
</Style>
</UserControl.Resources>
<!-- Root grid hosts all three states; Visibility toggled in code-behind -->
<Grid>
<!-- ══════════════════════════════════════ STATE A: Drop Zone -->
<!-- STATE A: Drop Zone -->
<Grid x:Name="StateA" Visibility="Visible">
<DockPanel LastChildFill="True">
<!-- Loading panel shown while AI runs -->
<!-- Loading panel - shown while AI runs -->
<Border x:Name="LoadingPanel" DockPanel.Dock="Top"
Visibility="Collapsed"
Margin="60,30,60,0" Padding="30,40"
@@ -19,15 +69,16 @@
CornerRadius="10">
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<mah:ProgressRing Width="36" Height="36"
IsTabStop="False"
HorizontalAlignment="Center" Margin="0,0,0,16"/>
<TextBlock x:Name="LoadingStepText"
Text="Examining the photo"
Text="Examining the photo."
FontSize="14" FontWeight="SemiBold"
HorizontalAlignment="Center"
Foreground="{DynamicResource MahApps.Brushes.Gray1}"/>
<TextBlock Text="This usually takes 1020 seconds"
FontSize="11" HorizontalAlignment="Center"
Foreground="{DynamicResource MahApps.Brushes.Gray5}"
<TextBlock Text="This usually takes 10-20 seconds"
Style="{StaticResource HintText}"
HorizontalAlignment="Center"
Margin="0,6,0,0"/>
</StackPanel>
</Border>
@@ -36,34 +87,39 @@
<Border x:Name="DropZoneBorder" DockPanel.Dock="Top"
Margin="60,30,60,0"
AllowDrop="True"
Focusable="True"
MouseLeftButtonUp="DropZone_Click"
DragOver="DropZone_DragOver"
DragEnter="DropZone_DragEnter"
DragLeave="DropZone_DragLeave"
Drop="DropZone_Drop"
Cursor="Hand"
MinHeight="180">
<Grid>
MinHeight="180"
AutomationProperties.Name="Photo drop zone - drop photos here or click to browse">
<Grid Background="Transparent">
<!-- Dashed border via Rectangle -->
<Rectangle x:Name="DropBorderRect"
StrokeThickness="2"
StrokeDashArray="6,4"
RadiusX="10" RadiusY="10"
Stroke="{DynamicResource MahApps.Brushes.Gray6}"/>
Stroke="{DynamicResource MahApps.Brushes.Gray6}"
/>
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center"
Margin="0,40">
Margin="0,40"
IsHitTestVisible="False">
<iconPacks:PackIconMaterial Kind="CameraOutline"
Width="52" Height="52"
HorizontalAlignment="Center"
Foreground="{DynamicResource MahApps.Brushes.Gray5}"
Margin="0,0,0,16"/>
Margin="0,0,0,16"
IsTabStop="False"/>
<TextBlock Text="Drop photos here"
FontSize="18" FontWeight="SemiBold"
HorizontalAlignment="Center"
Foreground="{DynamicResource MahApps.Brushes.Gray2}"/>
<TextBlock Text="or click to browse up to 12 photos"
FontSize="12" HorizontalAlignment="Center"
Foreground="{DynamicResource MahApps.Brushes.Gray5}"
<TextBlock Text="or click to browse - up to 12 photos"
Style="{StaticResource HintText}"
HorizontalAlignment="Center"
Margin="0,6,0,0"/>
</StackPanel>
</Grid>
@@ -73,6 +129,7 @@
<ScrollViewer x:Name="ThumbScroller" DockPanel.Dock="Top"
HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Disabled"
Focusable="False"
Margin="60,12,60,0" Visibility="Collapsed">
<StackPanel x:Name="ThumbStrip" Orientation="Horizontal"/>
</ScrollViewer>
@@ -83,14 +140,16 @@
Click="Analyse_Click"
IsEnabled="False"
Style="{StaticResource MahApps.Styles.Button.Square.Accent}"
Padding="28,12" FontSize="14" FontWeight="SemiBold">
Padding="28,12" FontSize="14" FontWeight="SemiBold"
AutomationProperties.Name="Identify and price item with AI">
<StackPanel Orientation="Horizontal">
<iconPacks:PackIconMaterial x:Name="AnalyseIcon"
Kind="MagnifyScan" Width="18" Height="18"
Margin="0,0,8,0" VerticalAlignment="Center"/>
<mah:ProgressRing x:Name="AnalyseSpinner"
Width="18" Height="18" Margin="0,0,8,0"
Visibility="Collapsed"/>
Visibility="Collapsed"
IsTabStop="False"/>
<TextBlock x:Name="AnalyseBtnText"
Text="Identify &amp; Price with AI"
VerticalAlignment="Center"/>
@@ -98,7 +157,7 @@
</Button>
<TextBlock x:Name="PhotoCountLabel"
HorizontalAlignment="Center" Margin="0,8,0,0"
FontSize="11" Visibility="Collapsed"
FontSize="13" Visibility="Collapsed"
Foreground="{DynamicResource MahApps.Brushes.Gray5}"/>
</StackPanel>
@@ -106,10 +165,374 @@
</DockPanel>
</Grid>
<!-- ══════════════════════════════════════ STATE B: Review & Edit (stub for now) -->
<Grid x:Name="StateB" Visibility="Collapsed"/>
<!-- STATE B: Review & Edit -->
<Grid x:Name="StateB" Visibility="Collapsed">
<DockPanel LastChildFill="True">
<!-- ══════════════════════════════════════ STATE C: Success (stub for now) -->
<Grid x:Name="StateC" Visibility="Collapsed"/>
<!-- Footer bar - pinned to bottom via DockPanel.Dock -->
<Border DockPanel.Dock="Bottom"
Background="{DynamicResource MahApps.Brushes.Gray9}"
BorderThickness="0,1,0,0"
BorderBrush="{DynamicResource MahApps.Brushes.Gray7}"
Padding="16,8">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Button Grid.Column="0" x:Name="StartOverBtn"
Click="StartOver_Click"
Background="Transparent" BorderThickness="0"
Foreground="{DynamicResource MahApps.Brushes.Gray5}"
Cursor="Hand" VerticalAlignment="Center"
AutomationProperties.Name="Start over and discard edits">
<TextBlock FontSize="13">
<Run Text="&#8592; "/>
<Run Text="Start Over" TextDecorations="Underline"/>
</TextBlock>
</Button>
<StackPanel Grid.Column="1" Orientation="Horizontal">
<Button x:Name="SaveDraftBtn"
Click="SaveDraft_Click"
Style="{StaticResource MahApps.Styles.Button.Square}"
Padding="16,8" Margin="0,0,8,0"
AutomationProperties.Name="Save listing as draft">
<StackPanel Orientation="Horizontal">
<iconPacks:PackIconMaterial Kind="ContentSaveOutline"
Width="14" Height="14" Margin="0,0,6,0"
VerticalAlignment="Center"/>
<TextBlock Text="Save as Draft" VerticalAlignment="Center"/>
</StackPanel>
</Button>
<Button x:Name="PostBtn"
Click="Post_Click"
Style="{StaticResource MahApps.Styles.Button.Square.Accent}"
Padding="16,8"
AutomationProperties.Name="Post listing to eBay">
<StackPanel Orientation="Horizontal">
<iconPacks:PackIconMaterial x:Name="PostIcon"
Kind="CartArrowRight" Width="14" Height="14"
Margin="0,0,6,0" VerticalAlignment="Center"/>
<mah:ProgressRing x:Name="PostSpinner"
Width="14" Height="14" Margin="0,0,6,0"
Visibility="Collapsed"
IsTabStop="False"/>
<TextBlock Text="Post to eBay" VerticalAlignment="Center"/>
</StackPanel>
</Button>
</StackPanel>
</Grid>
</Border>
<!-- Two-column content area -->
<Grid Margin="16,12,16,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="220" MinWidth="160"/>
<ColumnDefinition Width="12"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<!-- LEFT: Photos panel -->
<DockPanel Grid.Column="0">
<TextBlock DockPanel.Dock="Top"
Text="PHOTOS" Style="{StaticResource SectionHeader}"
Margin="0,0,0,8"/>
<StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" Margin="0,8,0,0">
<Button x:Name="AddMorePhotosBtn" Click="AddMorePhotos_Click"
Style="{StaticResource MahApps.Styles.Button.Square}"
Padding="8,4" FontSize="13"
AutomationProperties.Name="Add more photos to listing">
<StackPanel Orientation="Horizontal">
<iconPacks:PackIconMaterial Kind="Plus" Width="12" Height="12"
Margin="0,0,4,0" VerticalAlignment="Center"/>
<TextBlock Text="Add more" VerticalAlignment="Center"/>
</StackPanel>
</Button>
<TextBlock x:Name="BPhotoCount"
Margin="8,0,0,0" VerticalAlignment="Center"
FontSize="13"
Foreground="{DynamicResource MahApps.Brushes.Gray5}"/>
</StackPanel>
<ScrollViewer VerticalScrollBarVisibility="Auto"
Focusable="False">
<WrapPanel x:Name="BPhotosPanel"/>
</ScrollViewer>
</DockPanel>
<!-- RIGHT: Listing fields -->
<ScrollViewer Grid.Column="2" VerticalScrollBarVisibility="Auto"
Focusable="False">
<StackPanel Margin="0,0,8,16" MaxWidth="600">
<TextBlock Text="LISTING DETAILS"
Style="{StaticResource SectionHeader}"
Margin="0,0,0,12"/>
<!-- Title -->
<Grid Margin="0,0,0,4">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock x:Name="TitleLabel" Text="Title"
Style="{StaticResource FieldLabel}"
VerticalAlignment="Center"/>
<Button Grid.Column="1" x:Name="AiTitleBtn" Click="AiTitle_Click"
Style="{StaticResource AiActionButton}"
ToolTip="Improve title with AI"
AutomationProperties.Name="Improve title with AI">
<StackPanel Orientation="Horizontal">
<iconPacks:PackIconMaterial x:Name="TitleAiIcon"
Kind="AutoFix" Width="12" Height="12"
Margin="0,0,4,0" VerticalAlignment="Center"/>
<mah:ProgressRing x:Name="TitleSpinner" Width="12" Height="12"
Margin="0,0,4,0" Visibility="Collapsed"
IsTabStop="False"/>
<TextBlock Text="AI" FontSize="12" VerticalAlignment="Center"/>
</StackPanel>
</Button>
</Grid>
<TextBox x:Name="BTitleBox" TextChanged="TitleBox_TextChanged"
MaxLength="80" Margin="0,0,0,2"
AutomationProperties.LabeledBy="{Binding ElementName=TitleLabel}"/>
<Grid Margin="0,0,0,12">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Border Style="{StaticResource ProgressTrack}">
<Border x:Name="BTitleBar" Style="{StaticResource ProgressFill}"
Background="{DynamicResource MahApps.Brushes.Accent}"/>
</Border>
<TextBlock x:Name="BTitleCount" Grid.Column="1"
Text="0 / 80" Style="{StaticResource CharCountLabel}"/>
</Grid>
<!-- Description -->
<Grid Margin="0,0,0,4">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock x:Name="DescLabel" Text="Description"
Style="{StaticResource FieldLabel}"
VerticalAlignment="Center"/>
<Button Grid.Column="1" x:Name="AiDescBtn" Click="AiDesc_Click"
Style="{StaticResource AiActionButton}"
ToolTip="Write description with AI"
AutomationProperties.Name="Write description with AI">
<StackPanel Orientation="Horizontal">
<iconPacks:PackIconMaterial x:Name="DescAiIcon"
Kind="AutoFix" Width="12" Height="12"
Margin="0,0,4,0" VerticalAlignment="Center"/>
<mah:ProgressRing x:Name="DescSpinner" Width="12" Height="12"
Margin="0,0,4,0" Visibility="Collapsed"
IsTabStop="False"/>
<TextBlock Text="AI" FontSize="12" VerticalAlignment="Center"/>
</StackPanel>
</Button>
</Grid>
<TextBox x:Name="BDescBox" TextChanged="DescBox_TextChanged"
AcceptsReturn="True" TextWrapping="Wrap"
Height="110" VerticalScrollBarVisibility="Auto"
Margin="0,0,0,2"
AutomationProperties.LabeledBy="{Binding ElementName=DescLabel}"/>
<Grid Margin="0,0,0,12">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Border Style="{StaticResource ProgressTrack}">
<Border x:Name="BDescBar" Style="{StaticResource ProgressFill}"
Background="{DynamicResource MahApps.Brushes.Accent}"/>
</Border>
<TextBlock x:Name="BDescCount" Grid.Column="1"
Text="0 / 2000" Style="{StaticResource CharCountLabel}"/>
</Grid>
<!-- Category -->
<TextBlock x:Name="CategoryLabel" Text="Category"
Style="{StaticResource FieldLabel}"
Margin="0,0,0,4"/>
<Grid Margin="0,0,0,2">
<TextBox x:Name="BCategoryBox"
TextChanged="CategoryBox_TextChanged"
KeyDown="CategoryBox_KeyDown"
mah:TextBoxHelper.Watermark="Type to search categories."
AutomationProperties.LabeledBy="{Binding ElementName=CategoryLabel}"/>
<ListBox x:Name="BCategoryList"
Visibility="Collapsed"
SelectionChanged="CategoryList_SelectionChanged"
MaxHeight="160"
VerticalAlignment="Top"
Margin="0,32,0,0"
Panel.ZIndex="10"
Background="{DynamicResource MahApps.Brushes.Gray8}"
BorderBrush="{DynamicResource MahApps.Brushes.Gray6}"
VirtualizingPanel.IsVirtualizing="True"
VirtualizingPanel.VirtualizationMode="Recycling"
ScrollViewer.CanContentScroll="True"
AutomationProperties.Name="Category suggestions"/>
</Grid>
<TextBlock x:Name="BCategoryIdLabel"
Text="(no category selected)"
FontSize="12" Margin="0,0,0,12"
Foreground="{DynamicResource MahApps.Brushes.Gray5}"/>
<!-- Condition + Format -->
<Grid Margin="0,0,0,12">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="12"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0">
<TextBlock x:Name="ConditionLabel" Text="Condition"
Style="{StaticResource FieldLabel}"
Margin="0,0,0,4"/>
<ComboBox x:Name="BConditionBox"
SelectionChanged="ConditionBox_SelectionChanged"
AutomationProperties.LabeledBy="{Binding ElementName=ConditionLabel}">
<ComboBoxItem Content="New" Tag="New"/>
<ComboBoxItem Content="Open Box" Tag="OpenBox"/>
<ComboBoxItem Content="Refurbished" Tag="Refurbished"/>
<ComboBoxItem Content="Used" Tag="Used" IsSelected="True"/>
<ComboBoxItem Content="For Parts" Tag="ForParts"/>
</ComboBox>
</StackPanel>
<StackPanel Grid.Column="2">
<TextBlock x:Name="FormatLabel" Text="Format"
Style="{StaticResource FieldLabel}"
Margin="0,0,0,4"/>
<ComboBox x:Name="BFormatBox"
AutomationProperties.LabeledBy="{Binding ElementName=FormatLabel}">
<ComboBoxItem Content="Fixed Price" IsSelected="True"/>
<ComboBoxItem Content="Auction"/>
</ComboBox>
</StackPanel>
</Grid>
<!-- Price -->
<Grid Margin="0,0,0,4">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock x:Name="PriceLabel" Text="Price"
Style="{StaticResource FieldLabel}"
VerticalAlignment="Center"/>
<Button Grid.Column="1" x:Name="AiPriceBtn" Click="AiPrice_Click"
Style="{StaticResource AiActionButton}"
ToolTip="Research live eBay price"
AutomationProperties.Name="Research live eBay price">
<StackPanel Orientation="Horizontal">
<iconPacks:PackIconMaterial x:Name="PriceAiIcon"
Kind="Magnify" Width="12" Height="12"
Margin="0,0,4,0" VerticalAlignment="Center"/>
<mah:ProgressRing x:Name="PriceSpinner" Width="12" Height="12"
Margin="0,0,4,0" Visibility="Collapsed"
IsTabStop="False"/>
<TextBlock Text="Research" FontSize="12" VerticalAlignment="Center"/>
</StackPanel>
</Button>
</Grid>
<mah:NumericUpDown x:Name="BPriceBox" ValueChanged="PriceBox_ValueChanged"
StringFormat="&#x00A3;{0:0.00}"
Minimum="0" Maximum="99999"
Interval="0.50"
Margin="0,0,0,4"
AutomationProperties.LabeledBy="{Binding ElementName=PriceLabel}"/>
<TextBlock x:Name="BPriceHint"
FontSize="12" Margin="0,0,0,4"
Visibility="Collapsed"
Foreground="{DynamicResource MahApps.Brushes.Gray5}"/>
<TextBlock x:Name="BFeeLabel"
FontSize="12" Margin="0,0,0,12"
Visibility="Collapsed"
Foreground="{DynamicResource MahApps.Brushes.Gray5}"
AutomationProperties.Name="Estimated eBay listing fee"/>
<!-- Postage + Postcode -->
<Grid Margin="0,12,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="12"/>
<ColumnDefinition Width="120"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0">
<TextBlock x:Name="PostageLabel" Text="Postage"
Style="{StaticResource FieldLabel}"
Margin="0,0,0,4"/>
<ComboBox x:Name="BPostageBox" SelectionChanged="PostageBox_SelectionChanged"
AutomationProperties.LabeledBy="{Binding ElementName=PostageLabel}">
<ComboBoxItem Content="Royal Mail 1st Class" Tag="RoyalMailFirstClass"/>
<ComboBoxItem Content="Royal Mail 2nd Class" Tag="RoyalMailSecondClass" IsSelected="True"/>
<ComboBoxItem Content="Royal Mail Tracked 24" Tag="RoyalMailTracked24"/>
<ComboBoxItem Content="Royal Mail Tracked 48" Tag="RoyalMailTracked48"/>
<ComboBoxItem Content="Collection Only" Tag="CollectionOnly"/>
<ComboBoxItem Content="Free Postage" Tag="FreePostage"/>
</ComboBox>
</StackPanel>
<StackPanel Grid.Column="2">
<TextBlock x:Name="PostcodeLabel" Text="From postcode"
Style="{StaticResource FieldLabel}"
Margin="0,0,0,4"/>
<TextBox x:Name="BPostcodeBox"
AutomationProperties.LabeledBy="{Binding ElementName=PostcodeLabel}"/>
</StackPanel>
</Grid>
</StackPanel>
</ScrollViewer>
</Grid>
</DockPanel>
</Grid>
<!-- STATE C: Success -->
<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"
IsTabStop="False"/>
<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"
AutomationProperties.Name="Listing URL - click to open"/>
<Button x:Name="CopyUrlBtn" Click="CopyUrl_Click"
Style="{StaticResource MahApps.Styles.Button.Square}"
HorizontalAlignment="Center" Padding="16,8" Margin="0,0,0,36"
AutomationProperties.Name="Copy listing URL to clipboard">
<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"
AutomationProperties.Name="List another item">
<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>
</UserControl>

View File

@@ -1,4 +1,4 @@
using System.Windows;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media.Imaging;
@@ -23,7 +23,7 @@ public partial class NewListingView : UserControl
private readonly List<string> _photoPaths = new();
private const int MaxPhotos = 12;
// State B — draft being edited (stub, populated in Task 4)
// State B — draft being edited
private ListingDraft _draft = new();
private PhotoAnalysisResult? _lastAnalysis;
private bool _suppressCategoryLookup;
@@ -142,19 +142,19 @@ public partial class NewListingView : UserControl
var bmp = new BitmapImage();
bmp.BeginInit();
bmp.UriSource = new Uri(path, UriKind.Absolute);
bmp.DecodePixelWidth = 80;
bmp.DecodePixelWidth = 240;
bmp.CacheOption = BitmapCacheOption.OnLoad;
bmp.EndInit();
bmp.Freeze();
var img = new Image
{
Source = bmp, Width = 60, Height = 60,
Source = bmp, Width = 192, Height = 192,
Stretch = System.Windows.Media.Stretch.UniformToFill,
Margin = new Thickness(3)
Margin = new Thickness(4)
};
img.Clip = new System.Windows.Media.RectangleGeometry(
new Rect(0, 0, 60, 60), 4, 4);
new Rect(0, 0, 192, 192), 6, 6);
ThumbStrip.Children.Add(img);
}
catch { /* skip bad files */ }
@@ -211,10 +211,428 @@ public partial class NewListingView : UserControl
}
}
// Stub for State B — implemented in Task 4
private Task PopulateStateBAsync(PhotoAnalysisResult result) => Task.CompletedTask;
// ---- State B: Populate from analysis ----
private async Task PopulateStateBAsync(PhotoAnalysisResult result)
{
_draft = new ListingDraft { Postcode = _defaultPostcode };
_draft.PhotoPaths = new List<string>(_photoPaths);
RebuildBPhotoThumbnails();
BTitleBox.Text = result.Title;
BDescBox.Text = result.Description;
BPriceBox.Value = (double)Math.Round(result.PriceSuggested, 2);
BPostcodeBox.Text = _defaultPostcode;
BConditionBox.SelectedIndex = 3; // Used
if (!string.IsNullOrWhiteSpace(result.CategoryKeyword))
await AutoFillCategoryAsync(result.CategoryKeyword);
if (result.PriceMin > 0 && result.PriceMax > 0)
{
BPriceHint.Text = $"AI estimate: \u00A3{result.PriceMin:F2} \u00A3{result.PriceMax:F2}";
BPriceHint.Visibility = Visibility.Visible;
}
}
// ---- Title ----
private void TitleBox_TextChanged(object sender, TextChangedEventArgs e)
{
_draft.Title = BTitleBox.Text;
var len = BTitleBox.Text.Length;
BTitleCount.Text = $"{len} / 80";
var over = len > 75;
var trackBorder = BTitleBar.Parent as Border;
double trackWidth = trackBorder?.ActualWidth ?? 0;
if (trackWidth > 0) BTitleBar.Width = trackWidth * (len / 80.0);
BTitleBar.Background = over
? System.Windows.Media.Brushes.OrangeRed
: (System.Windows.Media.Brush)FindResource("MahApps.Brushes.Accent");
BTitleCount.Foreground = over
? System.Windows.Media.Brushes.OrangeRed
: (System.Windows.Media.Brush)FindResource("MahApps.Brushes.Gray5");
}
private async void AiTitle_Click(object sender, RoutedEventArgs e)
{
if (_aiService == null) return;
SetTitleBusy(true);
try
{
var title = await _aiService.GenerateTitleAsync(BTitleBox.Text, GetSelectedCondition().ToString());
BTitleBox.Text = title.Trim().TrimEnd('.').Trim('"');
if (string.IsNullOrWhiteSpace(_draft.CategoryId))
await AutoFillCategoryAsync(BTitleBox.Text);
}
catch (Exception ex) { ShowError("AI Title", ex.Message); }
finally { SetTitleBusy(false); }
}
private void SetTitleBusy(bool busy)
{
AiTitleBtn.IsEnabled = !busy;
TitleSpinner.Visibility = busy ? Visibility.Visible : Visibility.Collapsed;
TitleAiIcon.Visibility = busy ? Visibility.Collapsed : Visibility.Visible;
}
// ---- Description ----
private void DescBox_TextChanged(object sender, TextChangedEventArgs e)
{
_draft.Description = BDescBox.Text;
var len = BDescBox.Text.Length;
const int softCap = 2000;
BDescCount.Text = $"{len} / {softCap}";
var over = len > softCap;
var trackBorder = BDescBar.Parent as Border;
double trackWidth = trackBorder?.ActualWidth ?? 0;
if (trackWidth > 0) BDescBar.Width = Math.Min(trackWidth, trackWidth * (len / (double)softCap));
BDescBar.Background = over
? System.Windows.Media.Brushes.OrangeRed
: new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(0xF5, 0x9E, 0x0B));
BDescCount.Foreground = over
? System.Windows.Media.Brushes.OrangeRed
: (System.Windows.Media.Brush)FindResource("MahApps.Brushes.Gray5");
}
private async void AiDesc_Click(object sender, RoutedEventArgs e)
{
if (_aiService == null) return;
SetDescBusy(true);
try
{
var desc = await _aiService.WriteDescriptionAsync(
BTitleBox.Text, GetSelectedCondition().ToString(), BDescBox.Text);
BDescBox.Text = desc;
}
catch (Exception ex) { ShowError("AI Description", ex.Message); }
finally { SetDescBusy(false); }
}
private void SetDescBusy(bool busy)
{
AiDescBtn.IsEnabled = !busy;
DescSpinner.Visibility = busy ? Visibility.Visible : Visibility.Collapsed;
DescAiIcon.Visibility = busy ? Visibility.Collapsed : Visibility.Visible;
}
// ---- Category ----
private void CategoryBox_TextChanged(object sender, TextChangedEventArgs e)
{
if (_suppressCategoryLookup) return;
_categoryCts?.Cancel();
_categoryCts?.Dispose();
_categoryCts = new System.Threading.CancellationTokenSource();
var cts = _categoryCts;
if (BCategoryBox.Text.Length < 3) { BCategoryList.Visibility = Visibility.Collapsed; return; }
_ = SearchCategoryAsync(BCategoryBox.Text, cts);
}
private async Task SearchCategoryAsync(string text, System.Threading.CancellationTokenSource cts)
{
try
{
await Task.Delay(350, cts.Token);
if (cts.IsCancellationRequested) return;
var suggestions = await _categoryService!.GetCategorySuggestionsAsync(text);
if (cts.IsCancellationRequested) return;
BCategoryList.ItemsSource = suggestions.Select(s => s.CategoryName).ToList();
BCategoryList.Tag = suggestions;
BCategoryList.Visibility = suggestions.Count > 0 ? Visibility.Visible : Visibility.Collapsed;
}
catch (OperationCanceledException) { }
catch { }
}
private void CategoryBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Escape) { BCategoryList.Visibility = Visibility.Collapsed; e.Handled = true; }
}
private void CategoryList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (BCategoryList.SelectedIndex < 0) return;
var suggestions = BCategoryList.Tag as List<CategorySuggestion>;
if (suggestions == null || BCategoryList.SelectedIndex >= suggestions.Count) return;
var cat = suggestions[BCategoryList.SelectedIndex];
_suppressCategoryLookup = true;
_draft.CategoryId = cat.CategoryId;
_draft.CategoryName = cat.CategoryName;
BCategoryBox.Text = cat.CategoryName;
BCategoryIdLabel.Text = $"ID: {cat.CategoryId}";
BCategoryList.Visibility = Visibility.Collapsed;
_suppressCategoryLookup = false;
}
private async Task AutoFillCategoryAsync(string keyword)
{
if (_categoryService == null || string.IsNullOrWhiteSpace(keyword)) return;
try
{
var suggestions = await _categoryService.GetCategorySuggestionsAsync(keyword);
if (suggestions.Count == 0) return;
var top = suggestions[0];
_suppressCategoryLookup = true;
_draft.CategoryId = top.CategoryId;
_draft.CategoryName = top.CategoryName;
BCategoryBox.Text = top.CategoryName;
BCategoryIdLabel.Text = $"ID: {top.CategoryId}";
_suppressCategoryLookup = false;
BCategoryList.ItemsSource = suggestions.Select(s => s.CategoryName).ToList();
BCategoryList.Tag = suggestions;
BCategoryList.Visibility = suggestions.Count > 1 ? Visibility.Visible : Visibility.Collapsed;
}
catch { }
}
// ---- Condition ----
private void ConditionBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
_draft.Condition = GetSelectedCondition();
}
private ItemCondition GetSelectedCondition()
{
var tag = (BConditionBox.SelectedItem as ComboBoxItem)?.Tag?.ToString() ?? "Used";
return tag switch
{
"New" => ItemCondition.New,
"OpenBox" => ItemCondition.OpenBox,
"Refurbished" => ItemCondition.Refurbished,
"ForParts" => ItemCondition.ForPartsOrNotWorking,
_ => ItemCondition.Used
};
}
// ---- Price ----
private async void AiPrice_Click(object sender, RoutedEventArgs e)
{
if (_aiService == null) return;
SetPriceBusy(true);
try
{
var result = await _aiService.SuggestPriceAsync(BTitleBox.Text, GetSelectedCondition().ToString());
var lines = result.Split('\n', StringSplitOptions.RemoveEmptyEntries);
var priceLine = lines.FirstOrDefault(l => l.StartsWith("PRICE:", StringComparison.OrdinalIgnoreCase));
_suggestedPriceValue = priceLine?.Replace("PRICE:", "", StringComparison.OrdinalIgnoreCase).Trim() ?? "";
BPriceHint.Text = lines.FirstOrDefault() ?? result;
BPriceHint.Visibility = Visibility.Visible;
if (decimal.TryParse(_suggestedPriceValue, out var price))
BPriceBox.Value = (double)price;
}
catch (Exception ex) { ShowError("AI Price", ex.Message); }
finally { SetPriceBusy(false); }
}
private void PriceBox_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double?> e)
=> UpdateFeeEstimate();
private void PostageBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
=> UpdateFeeEstimate();
private static readonly Dictionary<string, decimal> PostageEstimates = new()
{
["RoyalMailFirstClass"] = 3.70m,
["RoyalMailSecondClass"] = 2.85m,
["RoyalMailTracked24"] = 4.35m,
["RoyalMailTracked48"] = 3.60m,
["CollectionOnly"] = 0m,
["FreePostage"] = 0m,
};
private void UpdateFeeEstimate()
{
if (BFeeLabel == null) return;
var price = (decimal)(BPriceBox?.Value ?? 0);
if (price <= 0) { BFeeLabel.Visibility = Visibility.Collapsed; return; }
var postageTag = (BPostageBox?.SelectedItem as ComboBoxItem)?.Tag?.ToString() ?? "";
PostageEstimates.TryGetValue(postageTag, out var postageEst);
const decimal fvfRate = 0.128m;
const decimal minFee = 0.30m;
var fee = Math.Max(Math.Round((price + postageEst) * fvfRate, 2), minFee);
var postageNote = postageEst > 0 ? $" + est. \u00A3{postageEst:F2} postage" : "";
BFeeLabel.Text = $"Est. eBay fee: \u00A3{fee:F2} (12.8% of \u00A3{price:F2}{postageNote})";
BFeeLabel.Visibility = Visibility.Visible;
}
private void SetPriceBusy(bool busy)
{
AiPriceBtn.IsEnabled = !busy;
PriceSpinner.Visibility = busy ? Visibility.Visible : Visibility.Collapsed;
PriceAiIcon.Visibility = busy ? Visibility.Collapsed : Visibility.Visible;
}
// ---- Photos (State B) ----
private void RebuildBPhotoThumbnails()
{
BPhotosPanel.Children.Clear();
for (int i = 0; i < _draft.PhotoPaths.Count; i++)
AddBPhotoThumbnail(_draft.PhotoPaths[i], i);
BPhotoCount.Text = $"{_draft.PhotoPaths.Count} / {MaxPhotos}";
BPhotoCount.Foreground = _draft.PhotoPaths.Count >= MaxPhotos
? System.Windows.Media.Brushes.OrangeRed
: (System.Windows.Media.Brush)FindResource("MahApps.Brushes.Gray5");
}
private void AddBPhotoThumbnail(string path, int index)
{
try
{
var bmp = new BitmapImage();
bmp.BeginInit();
bmp.UriSource = new Uri(path, UriKind.Absolute);
bmp.DecodePixelWidth = 320;
bmp.CacheOption = BitmapCacheOption.OnLoad;
bmp.EndInit();
bmp.Freeze();
var img = new Image
{
Width = 200, Height = 200,
Stretch = System.Windows.Media.Stretch.UniformToFill,
Source = bmp, ToolTip = System.IO.Path.GetFileName(path)
};
img.Clip = new System.Windows.Media.RectangleGeometry(new Rect(0, 0, 200, 200), 6, 6);
var removeBtn = new Button
{
Width = 18, Height = 18, Content = "\u2715",
FontSize = 11, FontWeight = FontWeights.Bold,
Cursor = Cursors.Hand, ToolTip = "Remove",
HorizontalAlignment = HorizontalAlignment.Right,
VerticalAlignment = VerticalAlignment.Top,
Margin = new Thickness(0, 2, 2, 0), Padding = new Thickness(0),
Background = new System.Windows.Media.SolidColorBrush(
System.Windows.Media.Color.FromArgb(200, 30, 30, 30)),
Foreground = System.Windows.Media.Brushes.White,
BorderThickness = new Thickness(0), Opacity = 0
};
removeBtn.Click += (s, ev) =>
{
ev.Handled = true;
_draft.PhotoPaths.Remove(path);
RebuildBPhotoThumbnails();
};
Border? coverBadge = null;
if (index == 0)
{
coverBadge = new Border
{
CornerRadius = new CornerRadius(3),
Background = new System.Windows.Media.SolidColorBrush(
System.Windows.Media.Color.FromArgb(210, 60, 90, 200)),
Padding = new Thickness(3, 1, 3, 1),
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Top,
Margin = new Thickness(2, 2, 0, 0),
IsHitTestVisible = false,
Child = new TextBlock
{
Text = "Cover", FontSize = 8, FontWeight = FontWeights.SemiBold,
Foreground = System.Windows.Media.Brushes.White
}
};
}
var container = new Grid
{
Width = 200, Height = 200, Margin = new Thickness(4),
Cursor = Cursors.SizeAll, AllowDrop = true, Tag = path
};
container.Children.Add(img);
if (coverBadge != null) container.Children.Add(coverBadge);
container.Children.Add(removeBtn);
container.MouseEnter += (s, ev) => removeBtn.Opacity = 1;
container.MouseLeave += (s, ev) => removeBtn.Opacity = 0;
Point dragStart = default;
bool isDragging = false;
container.MouseLeftButtonDown += (s, ev) => dragStart = ev.GetPosition(null);
container.MouseMove += (s, ev) =>
{
if (ev.LeftButton != MouseButtonState.Pressed || isDragging) return;
var pos = ev.GetPosition(null);
if (Math.Abs(pos.X - dragStart.X) > SystemParameters.MinimumHorizontalDragDistance ||
Math.Abs(pos.Y - dragStart.Y) > SystemParameters.MinimumVerticalDragDistance)
{
isDragging = true;
DragDrop.DoDragDrop(container, path, DragDropEffects.Move);
isDragging = false;
}
};
container.DragOver += (s, ev) =>
{
if (ev.Data.GetDataPresent(typeof(string)) &&
(string)ev.Data.GetData(typeof(string)) != path)
{ ev.Effects = DragDropEffects.Move; container.Opacity = 0.45; }
else ev.Effects = DragDropEffects.None;
ev.Handled = true;
};
container.DragLeave += (s, ev) => container.Opacity = 1.0;
container.Drop += (s, ev) =>
{
container.Opacity = 1.0;
if (!ev.Data.GetDataPresent(typeof(string))) return;
var src = (string)ev.Data.GetData(typeof(string));
var tgt = (string)container.Tag;
if (src == tgt) return;
var si = _draft.PhotoPaths.IndexOf(src);
var ti = _draft.PhotoPaths.IndexOf(tgt);
if (si < 0 || ti < 0) return;
_draft.PhotoPaths.RemoveAt(si);
_draft.PhotoPaths.Insert(ti, src);
RebuildBPhotoThumbnails();
ev.Handled = true;
};
BPhotosPanel.Children.Add(container);
}
catch { }
}
private void AddMorePhotos_Click(object sender, RoutedEventArgs e)
{
var dlg = new OpenFileDialog
{
Title = "Add more photos",
Filter = "Images|*.jpg;*.jpeg;*.png;*.gif;*.webp;*.bmp|All files|*.*",
Multiselect = true
};
if (dlg.ShowDialog() == true)
{
foreach (var path in dlg.FileNames)
{
if (_draft.PhotoPaths.Count >= MaxPhotos) break;
if (!_draft.PhotoPaths.Contains(path)) _draft.PhotoPaths.Add(path);
}
RebuildBPhotoThumbnails();
}
}
// ---- Footer actions ----
private void StartOver_Click(object sender, RoutedEventArgs e)
{
var isDirty = !string.IsNullOrWhiteSpace(BTitleBox.Text) ||
!string.IsNullOrWhiteSpace(BDescBox.Text);
if (isDirty)
{
var result = MessageBox.Show("Start over? Any edits will be lost.",
"Start Over", MessageBoxButton.OKCancel, MessageBoxImage.Question);
if (result != MessageBoxResult.OK) return;
}
ResetToStateA();
}
// Stub for ResetToStateA — implemented in Task 4
public void ResetToStateA()
{
_photoPaths.Clear();
@@ -222,9 +640,140 @@ public partial class NewListingView : UserControl
_lastAnalysis = null;
UpdateThumbStrip();
UpdateAnalyseButton();
if (BPhotosPanel != null) BPhotosPanel.Children.Clear();
if (BTitleBox != null) BTitleBox.Text = "";
if (BDescBox != null) BDescBox.Text = "";
if (BCategoryBox != null) { BCategoryBox.Text = ""; BCategoryList.Visibility = Visibility.Collapsed; }
if (BCategoryIdLabel != null) BCategoryIdLabel.Text = "(no category selected)";
if (BPriceBox != null) BPriceBox.Value = 0;
if (BPriceHint != null) BPriceHint.Visibility = Visibility.Collapsed;
if (BConditionBox != null) BConditionBox.SelectedIndex = 3;
if (BFormatBox != null) BFormatBox.SelectedIndex = 0;
if (BPostcodeBox != null) BPostcodeBox.Text = _defaultPostcode;
SetState(ListingState.DropZone);
}
private void SaveDraft_Click(object sender, RoutedEventArgs e)
{
if (_savedService == null) return;
if (!ValidateDraft()) return;
CollectDraftFromFields();
try
{
_savedService.Save(
_draft.Title, _draft.Description, _draft.Price,
_draft.CategoryName, "",
_draft.PhotoPaths,
_draft.CategoryId, _draft.Condition, _draft.Format,
BPostcodeBox.Text);
GetWindow()?.RefreshSavedListings();
GetWindow()?.SetStatus($"Draft saved: {_draft.Title}");
ResetToStateA();
}
catch (Exception ex) { ShowError("Save Failed", ex.Message); }
}
private async void Post_Click(object sender, RoutedEventArgs e)
{
if (_listingService == null) return;
if (!ValidateDraft()) return;
CollectDraftFromFields();
SetPostBusy(true);
try
{
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}");
}
catch (Exception ex)
{
// Log full stack trace to help diagnose crashes
try
{
var logPath = System.IO.Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"EbayListingTool", "crash_log.txt");
var msg = $"{DateTime.Now:HH:mm:ss} [Post_Click] {ex.GetType().Name}: {ex.Message}\n{ex.StackTrace}\n";
if (ex.InnerException != null)
msg += $" Inner: {ex.InnerException.GetType().Name}: {ex.InnerException.Message}\n";
System.IO.File.AppendAllText(logPath, msg + "\n");
}
catch { }
ShowError("Post Failed", ex.Message);
}
finally { SetPostBusy(false); }
}
private void CollectDraftFromFields()
{
_draft.Title = BTitleBox.Text.Trim();
_draft.Description = BDescBox.Text.Trim();
_draft.Price = (decimal)(BPriceBox.Value ?? 0);
_draft.Condition = GetSelectedCondition();
_draft.Format = BFormatBox.SelectedIndex == 0 ? ListingFormat.FixedPrice : ListingFormat.Auction;
_draft.Postcode = BPostcodeBox.Text;
_draft.Quantity = 1;
}
private bool ValidateDraft()
{
if (string.IsNullOrWhiteSpace(BTitleBox?.Text))
{ ShowError("Validation", "Please enter a title."); return false; }
if (BTitleBox.Text.Length > 80)
{ ShowError("Validation", "Title must be 80 characters or fewer."); return false; }
if (string.IsNullOrEmpty(_draft.CategoryId))
{ ShowError("Validation", "Please select a category."); return false; }
if ((BPriceBox?.Value ?? 0) <= 0)
{ ShowError("Validation", "Please enter a price greater than zero."); return false; }
return true;
}
private void SetPostBusy(bool busy)
{
PostBtn.IsEnabled = !busy;
PostSpinner.Visibility = busy ? Visibility.Visible : Visibility.Collapsed;
PostIcon.Visibility = busy ? Visibility.Collapsed : Visibility.Visible;
IsEnabled = !busy;
}
private void ShowError(string title, string msg)
=> 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)
{
var ext = System.IO.Path.GetExtension(path).ToLowerInvariant();

View File

@@ -325,6 +325,166 @@
</StackPanel>
</Border>
<!-- ============================================================
Card Preview — dyscalculia-friendly quick-approve flow
============================================================ -->
<StackPanel x:Name="CardPreviewPanel" Visibility="Collapsed">
<!-- Item card -->
<Border CornerRadius="10" Padding="16" Margin="0,0,0,12"
Background="{DynamicResource MahApps.Brushes.Gray10}"
BorderBrush="{DynamicResource MahApps.Brushes.Gray8}"
BorderThickness="1">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="110"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<!-- Cover photo -->
<Border Grid.Column="0" CornerRadius="7" ClipToBounds="True"
Width="110" Height="110">
<Image x:Name="CardPhoto" Stretch="UniformToFill"/>
</Border>
<!-- Details -->
<StackPanel Grid.Column="1" Margin="14,0,0,0"
VerticalAlignment="Center">
<TextBlock x:Name="CardItemName"
FontSize="17" FontWeight="Bold"
TextWrapping="Wrap"
Foreground="{DynamicResource MahApps.Brushes.Gray1}"/>
<TextBlock x:Name="CardCondition"
FontSize="11" Margin="0,3,0,0"
TextWrapping="Wrap"
Foreground="{DynamicResource MahApps.Brushes.Gray5}"/>
<!-- Photo dots (built in code-behind) -->
<StackPanel x:Name="CardPhotoDots"
Orientation="Horizontal" Margin="0,8,0,0"/>
<!-- Verbal price — primary -->
<TextBlock x:Name="CardPriceVerbal"
FontSize="24" FontWeight="Bold" Margin="0,10,0,2"
Foreground="{DynamicResource MahApps.Brushes.Accent}"/>
<!-- Digit price — secondary/small -->
<TextBlock x:Name="CardPriceDigit"
FontSize="11" Opacity="0.40"/>
<!-- Category pill -->
<Border CornerRadius="10" Padding="8,3" Margin="0,10,0,0"
Background="{DynamicResource MahApps.Brushes.Gray9}"
HorizontalAlignment="Left">
<TextBlock x:Name="CardCategory" FontSize="11"
Foreground="{DynamicResource MahApps.Brushes.Gray3}"/>
</Border>
</StackPanel>
</Grid>
</Border>
<!-- Live price note (updated async) -->
<TextBlock x:Name="CardLivePriceNote"
FontSize="10" Margin="0,0,0,10"
Foreground="{DynamicResource MahApps.Brushes.Gray5}"
TextWrapping="Wrap" Visibility="Collapsed"/>
<!-- Primary action buttons -->
<Grid Margin="0,0,0,6">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="8"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Button Grid.Column="0" x:Name="LooksGoodBtn"
Click="LooksGood_Click"
Height="54" FontSize="15" FontWeight="SemiBold"
Style="{DynamicResource MahApps.Styles.Button.Square.Accent}">
<StackPanel Orientation="Horizontal">
<iconPacks:PackIconMaterial Kind="Check" Width="17" Height="17"
Margin="0,0,8,0" VerticalAlignment="Center"/>
<TextBlock Text="Looks good" VerticalAlignment="Center"/>
</StackPanel>
</Button>
<Button Grid.Column="2" x:Name="ChangeSomethingBtn"
Click="ChangeSomething_Click"
Height="54" FontSize="13"
Style="{DynamicResource MahApps.Styles.Button.Square}">
<StackPanel Orientation="Horizontal">
<iconPacks:PackIconMaterial x:Name="ChangeChevron"
Kind="ChevronDown" Width="13" Height="13"
Margin="0,0,6,0" VerticalAlignment="Center"/>
<TextBlock Text="Change something" VerticalAlignment="Center"/>
</StackPanel>
</Button>
</Grid>
<!-- Change panel (collapsed by default) -->
<StackPanel x:Name="CardChangePanel" Visibility="Collapsed" Margin="0,4,0,0">
<!-- Price slider -->
<Border Style="{StaticResource SectionCard}">
<StackPanel>
<TextBlock Text="PRICE" Style="{StaticResource SectionHeading}"
Margin="0,0,0,10"/>
<TextBlock x:Name="SliderVerbalLabel"
FontSize="22" FontWeight="Bold" Margin="0,0,0,2"
Foreground="{DynamicResource MahApps.Brushes.Accent}"/>
<TextBlock x:Name="SliderDigitLabel"
FontSize="11" Opacity="0.40" Margin="0,0,0,12"/>
<Slider x:Name="PriceSliderCard"
Minimum="0.50" Maximum="200"
SmallChange="0.5" LargeChange="5"
TickFrequency="0.5" IsSnapToTickEnabled="True"
ValueChanged="PriceSliderCard_ValueChanged"/>
<Grid Margin="0,3,0,0">
<TextBlock Text="cheaper" FontSize="10" Opacity="0.45"
HorizontalAlignment="Left"/>
<TextBlock Text="pricier" FontSize="10" Opacity="0.45"
HorizontalAlignment="Right"/>
</Grid>
</StackPanel>
</Border>
<!-- Title edit -->
<Border Style="{StaticResource SectionCard}">
<StackPanel>
<TextBlock Text="TITLE" Style="{StaticResource SectionHeading}"
Margin="0,0,0,8"/>
<TextBox x:Name="CardTitleBox"
TextWrapping="Wrap" AcceptsReturn="False"
MaxLength="80" FontSize="13"
TextChanged="CardTitleBox_TextChanged"/>
<!-- Colour bar — no digit counter -->
<Grid Margin="0,6,0,0" Height="4">
<Border CornerRadius="2" Background="{DynamicResource MahApps.Brushes.Gray8}"/>
<Border x:Name="CardTitleBar" CornerRadius="2"
HorizontalAlignment="Left" Width="0"
Background="{DynamicResource MahApps.Brushes.Accent}"/>
</Grid>
</StackPanel>
</Border>
<!-- Save with changes -->
<Button Content="Save with changes"
Click="SaveWithChanges_Click"
Style="{DynamicResource MahApps.Styles.Button.Square.Accent}"
Height="46" FontSize="14" FontWeight="SemiBold"
HorizontalAlignment="Stretch" Margin="0,4,0,8"/>
<Button Content="Analyse another item"
Click="AnalyseAnother_Click"
Style="{DynamicResource MahApps.Styles.Button.Square}"
Height="36" FontSize="12"
HorizontalAlignment="Stretch"/>
</StackPanel>
</StackPanel>
<!-- Results (hidden until analysis complete) -->
<StackPanel x:Name="ResultsPanel" Visibility="Collapsed" Opacity="0">
<StackPanel.RenderTransform>

View File

@@ -4,6 +4,7 @@ using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Threading;
using EbayListingTool.Helpers;
using EbayListingTool.Models;
using EbayListingTool.Services;
using Microsoft.Win32;
@@ -287,7 +288,63 @@ public partial class PhotoAnalysisView : UserControl
{
IdlePanel.Visibility = Visibility.Collapsed;
LoadingPanel.Visibility = Visibility.Collapsed;
ResultsPanel.Visibility = Visibility.Visible;
ResultsPanel.Visibility = Visibility.Collapsed; // hidden behind card preview
CardPreviewPanel.Visibility = Visibility.Visible;
CardChangePanel.Visibility = Visibility.Collapsed;
ChangeChevron.Kind = MahApps.Metro.IconPacks.PackIconMaterialKind.ChevronDown;
// --- Populate card preview ---
CardItemName.Text = r.ItemName;
CardCondition.Text = r.ConditionNotes;
CardCategory.Text = r.CategoryKeyword;
CardPriceVerbal.Text = NumberWords.ToVerbalPrice(r.PriceSuggested);
CardPriceDigit.Text = r.PriceSuggested > 0 ? $"£{r.PriceSuggested:F2}" : "";
CardLivePriceNote.Visibility = Visibility.Collapsed;
// Cover photo
if (_currentImagePaths.Count > 0)
{
try
{
var bmp = new BitmapImage();
bmp.BeginInit();
bmp.UriSource = new Uri(_currentImagePaths[0], UriKind.Absolute);
bmp.CacheOption = BitmapCacheOption.OnLoad;
bmp.DecodePixelWidth = 220;
bmp.EndInit();
bmp.Freeze();
CardPhoto.Source = bmp;
}
catch { CardPhoto.Source = null; }
}
// Photo dots — one dot per photo, filled accent for first
CardPhotoDots.Children.Clear();
for (int i = 0; i < _currentImagePaths.Count; i++)
{
CardPhotoDots.Children.Add(new System.Windows.Shapes.Ellipse
{
Width = 7, Height = 7,
Margin = new Thickness(2, 0, 2, 0),
Fill = i == 0
? (Brush)FindResource("MahApps.Brushes.Accent")
: (Brush)FindResource("MahApps.Brushes.Gray7")
});
}
CardPhotoDots.Visibility = _currentImagePaths.Count > 1
? Visibility.Visible : Visibility.Collapsed;
// Price slider — centre on suggested, range ±60% clamped to sensible bounds
var suggested = (double)(r.PriceSuggested > 0 ? r.PriceSuggested : 10m);
PriceSliderCard.Minimum = Math.Max(0.50, Math.Round(suggested * 0.4 * 2) / 2);
PriceSliderCard.Maximum = Math.Round(suggested * 1.8 * 2) / 2;
PriceSliderCard.Value = Math.Round(suggested * 2) / 2; // snap to 50p
SliderVerbalLabel.Text = NumberWords.ToVerbalPrice(r.PriceSuggested);
SliderDigitLabel.Text = $"£{r.PriceSuggested:F2}";
// Card title box
CardTitleBox.Text = r.Title;
UpdateCardTitleBar(r.Title.Length);
// Item identification
ItemNameText.Text = r.ItemName;
@@ -351,10 +408,6 @@ public partial class PhotoAnalysisView : UserControl
// Reset live price row until lookup completes
LivePriceRow.Visibility = Visibility.Collapsed;
// Animate results in
var sb = (Storyboard)FindResource("ResultsReveal");
sb.Begin(this);
}
private async Task UpdateLivePricesAsync(string query)
@@ -392,9 +445,23 @@ public partial class PhotoAnalysisView : UserControl
// Update suggested price to 40th percentile (competitive but not cheapest)
var suggested = live.Suggested;
PriceSuggestedText.Text = $"£{suggested:F2}";
PriceOverride.Value = (double)Math.Round(suggested, 2); // Issue 6: avoid decimal→double drift
PriceOverride.Value = (double)Math.Round(suggested, 2);
if (_lastResult != null) _lastResult.PriceSuggested = suggested;
// Update card preview price
CardPriceVerbal.Text = NumberWords.ToVerbalPrice(suggested);
CardPriceDigit.Text = $"£{suggested:F2}";
var snapped = Math.Round((double)suggested * 2) / 2;
if (snapped >= PriceSliderCard.Minimum && snapped <= PriceSliderCard.Maximum)
PriceSliderCard.Value = snapped;
SliderVerbalLabel.Text = NumberWords.ToVerbalPrice(suggested);
SliderDigitLabel.Text = $"£{suggested:F2}";
// Show note on card
var noteText = $"eBay: {live.Count} similar listing{(live.Count == 1 ? "" : "s")}, range £{live.Min:F2}–£{live.Max:F2}";
CardLivePriceNote.Text = noteText;
CardLivePriceNote.Visibility = Visibility.Visible;
// Update status label
LivePriceSpinner.Visibility = Visibility.Collapsed;
LivePriceStatus.Text =
@@ -666,6 +733,63 @@ public partial class PhotoAnalysisView : UserControl
Clipboard.SetText(DescriptionBox.Text);
}
// ---- Card preview handlers ----
private void LooksGood_Click(object sender, RoutedEventArgs e)
=> SaveListing_Click(sender, e);
private void ChangeSomething_Click(object sender, RoutedEventArgs e)
{
var expanding = CardChangePanel.Visibility != Visibility.Visible;
CardChangePanel.Visibility = expanding ? Visibility.Visible : Visibility.Collapsed;
ChangeChevron.Kind = expanding
? MahApps.Metro.IconPacks.PackIconMaterialKind.ChevronUp
: MahApps.Metro.IconPacks.PackIconMaterialKind.ChevronDown;
}
private void PriceSliderCard_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
if (!IsLoaded) return;
var price = (decimal)e.NewValue;
SliderVerbalLabel.Text = NumberWords.ToVerbalPrice(price);
SliderDigitLabel.Text = $"£{price:F2}";
// Keep card price display in sync
CardPriceVerbal.Text = NumberWords.ToVerbalPrice(price);
CardPriceDigit.Text = $"£{price:F2}";
// Keep hidden ResultsPanel in sync so SaveListing_Click gets the right value
PriceOverride.Value = e.NewValue;
if (_lastResult != null) _lastResult.PriceSuggested = price;
}
private void CardTitleBox_TextChanged(object sender, TextChangedEventArgs e)
{
var len = CardTitleBox.Text.Length;
UpdateCardTitleBar(len);
// Keep hidden ResultsPanel in sync
TitleBox.Text = CardTitleBox.Text;
}
private void UpdateCardTitleBar(int len)
{
if (!IsLoaded) return;
var trackWidth = CardTitleBar.Parent is Grid g ? g.ActualWidth : 0;
if (trackWidth <= 0) return;
CardTitleBar.Width = trackWidth * (len / 80.0);
CardTitleBar.Background = len > 75
? System.Windows.Media.Brushes.OrangeRed
: (System.Windows.Media.Brush)FindResource("MahApps.Brushes.Accent");
}
private void SaveWithChanges_Click(object sender, RoutedEventArgs e)
{
if (_lastResult != null)
{
_lastResult.Title = CardTitleBox.Text.Trim();
TitleBox.Text = _lastResult.Title;
}
SaveListing_Click(sender, e);
}
// ---- Loading step cycling ----
private void LoadingTimer_Tick(object? sender, EventArgs e)

View File

@@ -2,7 +2,8 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks">
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
KeyboardNavigation.TabNavigation="Cycle">
<UserControl.Resources>
@@ -41,6 +42,22 @@
<Setter Property="Height" Value="30"/>
</Style>
<!-- Shared style for detail action buttons -->
<Style x:Key="DetailActionButton" TargetType="Button"
BasedOn="{StaticResource MahApps.Styles.Button.Square.Accent}">
<Setter Property="Height" Value="34"/>
<Setter Property="Padding" Value="14,0"/>
<Setter Property="Margin" Value="0,0,8,6"/>
</Style>
<!-- Shared style for secondary detail action buttons -->
<Style x:Key="DetailSecondaryButton" TargetType="Button"
BasedOn="{StaticResource MahApps.Styles.Button.Square}">
<Setter Property="Height" Value="34"/>
<Setter Property="Padding" Value="12,0"/>
<Setter Property="Margin" Value="0,0,8,6"/>
</Style>
</UserControl.Resources>
<Grid>
@@ -51,7 +68,7 @@
</Grid.ColumnDefinitions>
<!-- ================================================================
LEFT Listings list
LEFT - Listings list
================================================================ -->
<Grid Grid.Column="0">
<Grid.RowDefinitions>
@@ -72,7 +89,8 @@
<StackPanel Grid.Column="0" Orientation="Horizontal">
<iconPacks:PackIconMaterial Kind="BookmarkMultiple" Width="14" Height="14"
Margin="0,0,7,0" VerticalAlignment="Center"
Foreground="{DynamicResource MahApps.Brushes.Accent}"/>
Foreground="{DynamicResource MahApps.Brushes.Accent}"
IsTabStop="False"/>
<TextBlock x:Name="ListingCountText" Text="0 saved listings"
FontSize="12" FontWeight="SemiBold"
Foreground="{DynamicResource MahApps.Brushes.Gray2}"
@@ -81,7 +99,8 @@
<Button Grid.Column="1" x:Name="OpenExportsDirBtn"
Click="OpenExportsDir_Click"
Style="{StaticResource CardActionBtn}"
ToolTip="Open exports folder in Explorer">
ToolTip="Open exports folder in Explorer"
AutomationProperties.Name="Open exports folder in Explorer">
<StackPanel Orientation="Horizontal">
<iconPacks:PackIconMaterial Kind="FolderOpen" Width="12" Height="12"
Margin="0,0,4,0" VerticalAlignment="Center"/>
@@ -104,18 +123,20 @@
Width="13" Height="13"
Margin="0,0,7,0"
VerticalAlignment="Center"
Foreground="{DynamicResource MahApps.Brushes.Gray5}"/>
Foreground="{DynamicResource MahApps.Brushes.Gray5}"
IsTabStop="False"/>
<TextBox Grid.Column="1" x:Name="SearchBox"
Style="{StaticResource SearchBox}"
mah:TextBoxHelper.Watermark="Filter listings"
mah:TextBoxHelper.Watermark="Filter listings..."
mah:TextBoxHelper.ClearTextButton="True"
TextChanged="SearchBox_TextChanged"/>
TextChanged="SearchBox_TextChanged"
AutomationProperties.Name="Filter saved listings"/>
</Grid>
</Border>
<!-- Card list -->
<ScrollViewer Grid.Row="2" VerticalScrollBarVisibility="Auto"
Padding="10,8">
Padding="10,8" Focusable="False">
<Grid>
<!-- Empty state for no saved listings -->
<StackPanel x:Name="EmptyCardState"
@@ -128,11 +149,13 @@
HorizontalAlignment="Center"
Margin="0,0,0,16"
Background="{DynamicResource MahApps.Brushes.Gray9}">
<iconPacks:PackIconMaterial Kind="BookmarkPlusOutline"
Width="32" Height="32"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Foreground="{DynamicResource MahApps.Brushes.Gray5}"/>
Foreground="{DynamicResource MahApps.Brushes.Gray5}"
IsTabStop="False"/>
</Border>
<TextBlock Text="No saved listings yet"
FontSize="13" FontWeight="SemiBold"
@@ -158,7 +181,8 @@
Width="36" Height="36"
HorizontalAlignment="Center"
Foreground="{DynamicResource MahApps.Brushes.Gray6}"
Margin="0,0,0,12"/>
Margin="0,0,0,12"
IsTabStop="False"/>
<TextBlock Text="No listings match your search"
FontSize="12"
Foreground="{DynamicResource MahApps.Brushes.Gray5}"
@@ -172,10 +196,11 @@
<!-- Splitter -->
<GridSplitter Grid.Column="1" Width="4" HorizontalAlignment="Stretch"
Background="{DynamicResource MahApps.Brushes.Gray8}"/>
Background="{DynamicResource MahApps.Brushes.Gray8}"
AutomationProperties.Name="Resize listings panel"/>
<!-- ================================================================
RIGHT Detail panel
RIGHT - Detail panel
================================================================ -->
<Grid Grid.Column="2">
@@ -185,7 +210,8 @@
<iconPacks:PackIconMaterial Kind="BookmarkOutline" Width="48" Height="48"
HorizontalAlignment="Center"
Foreground="{DynamicResource MahApps.Brushes.Gray7}"
Margin="0,0,0,14"/>
Margin="0,0,0,14"
IsTabStop="False"/>
<TextBlock Text="Select a saved listing" FontSize="14"
Foreground="{DynamicResource MahApps.Brushes.Gray5}"
HorizontalAlignment="Center"/>
@@ -193,7 +219,8 @@
<!-- Detail content -->
<ScrollViewer x:Name="DetailPanel" Visibility="Collapsed" Opacity="0"
VerticalScrollBarVisibility="Auto" Padding="18,14">
VerticalScrollBarVisibility="Auto" Padding="18,14"
Focusable="False">
<StackPanel>
<!-- Title + price row -->
@@ -219,7 +246,8 @@
<Button x:Name="RevalueBtn" Click="RevalueBtn_Click"
Height="28" Padding="8,0" Margin="6,0,0,0"
Style="{DynamicResource MahApps.Styles.Button.Square}"
ToolTip="Quick-change the price">
ToolTip="Quick-change the price"
AutomationProperties.Name="Quick-change the price">
<StackPanel Orientation="Horizontal">
<iconPacks:PackIconMaterial Kind="CurrencyGbp" Width="11" Height="11"
Margin="0,0,4,0" VerticalAlignment="Center"/>
@@ -235,11 +263,13 @@
<mah:NumericUpDown x:Name="RevaluePrice"
Minimum="0" Maximum="99999"
StringFormat="F2" Interval="0.5"
Width="110" Height="30"/>
Width="110" Height="30"
AutomationProperties.Name="New price value"/>
<Button x:Name="CheckEbayBtn" Click="CheckEbayBtn_Click"
Height="30" Padding="8,0" Margin="6,0,4,0"
Style="{DynamicResource MahApps.Styles.Button.Square}"
ToolTip="Check eBay for a suggested price">
ToolTip="Check eBay for a suggested price"
AutomationProperties.Name="Check eBay for suggested price">
<StackPanel Orientation="Horizontal">
<iconPacks:PackIconMaterial x:Name="CheckEbayIcon"
Kind="Magnify" Width="11" Height="11"
@@ -251,13 +281,15 @@
<Button Click="RevalueSave_Click"
Style="{DynamicResource MahApps.Styles.Button.Square.Accent}"
Height="30" Padding="10,0" Margin="0,0,4,0"
ToolTip="Save new price">
ToolTip="Save new price"
AutomationProperties.Name="Save new price">
<iconPacks:PackIconMaterial Kind="Check" Width="13" Height="13"/>
</Button>
<Button Click="RevalueCancel_Click"
Style="{DynamicResource MahApps.Styles.Button.Square}"
Height="30" Padding="8,0"
ToolTip="Cancel">
ToolTip="Cancel"
AutomationProperties.Name="Cancel price change">
<iconPacks:PackIconMaterial Kind="Close" Width="11" Height="11"/>
</Button>
</StackPanel>
@@ -270,20 +302,22 @@
</StackPanel>
</Grid>
<!-- Meta row: category · date -->
<!-- Meta row: category / date -->
<StackPanel Orientation="Horizontal" Margin="0,0,0,14">
<iconPacks:PackIconMaterial Kind="Tag" Width="11" Height="11"
Margin="0,0,4,0" VerticalAlignment="Center"
Foreground="{DynamicResource MahApps.Brushes.Gray5}"/>
Foreground="{DynamicResource MahApps.Brushes.Gray5}"
IsTabStop="False"/>
<TextBlock x:Name="DetailCategory" FontSize="11"
Foreground="{DynamicResource MahApps.Brushes.Gray4}"
VerticalAlignment="Center"/>
<TextBlock Text=" · " FontSize="11"
<TextBlock Text=" | " FontSize="11"
Foreground="{DynamicResource MahApps.Brushes.Gray6}"
VerticalAlignment="Center"/>
<iconPacks:PackIconMaterial Kind="ClockOutline" Width="11" Height="11"
Margin="0,0,4,0" VerticalAlignment="Center"
Foreground="{DynamicResource MahApps.Brushes.Gray5}"/>
Foreground="{DynamicResource MahApps.Brushes.Gray5}"
IsTabStop="False"/>
<TextBlock x:Name="DetailDate" FontSize="11"
Foreground="{DynamicResource MahApps.Brushes.Gray4}"
VerticalAlignment="Center"/>
@@ -293,6 +327,7 @@
<TextBlock Text="PHOTOS" Style="{StaticResource DetailLabel}"/>
<ScrollViewer HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Disabled"
Focusable="False"
Margin="0,0,0,4">
<WrapPanel x:Name="DetailPhotosPanel" Orientation="Horizontal"/>
</ScrollViewer>
@@ -320,22 +355,23 @@
<WrapPanel Orientation="Horizontal">
<Button x:Name="PostDraftBtn"
Click="PostDraft_Click"
Style="{StaticResource MahApps.Styles.Button.Square.Accent}"
Height="34" Padding="14,0" Margin="0,0,8,6"
ToolTip="Post this draft to eBay">
Style="{StaticResource DetailActionButton}"
ToolTip="Post this draft to eBay"
AutomationProperties.Name="Post draft to eBay">
<StackPanel Orientation="Horizontal">
<iconPacks:PackIconMaterial x:Name="PostDraftIcon"
Kind="CartArrowRight" Width="14" Height="14"
Margin="0,0,6,0" VerticalAlignment="Center"/>
<mah:ProgressRing x:Name="PostDraftSpinner"
Width="14" Height="14" Margin="0,0,6,0"
Visibility="Collapsed"/>
Visibility="Collapsed"
IsTabStop="False"/>
<TextBlock Text="Post to eBay" VerticalAlignment="Center"/>
</StackPanel>
</Button>
<Button Click="EditListing_Click"
Style="{DynamicResource MahApps.Styles.Button.Square.Accent}"
Height="34" Padding="14,0" Margin="0,0,8,6">
Style="{StaticResource DetailActionButton}"
AutomationProperties.Name="Edit this listing">
<StackPanel Orientation="Horizontal">
<iconPacks:PackIconMaterial Kind="Pencil" Width="13" Height="13"
Margin="0,0,6,0" VerticalAlignment="Center"/>
@@ -343,8 +379,8 @@
</StackPanel>
</Button>
<Button Click="OpenFolderDetail_Click"
Style="{DynamicResource MahApps.Styles.Button.Square.Accent}"
Height="34" Padding="14,0" Margin="0,0,8,6">
Style="{StaticResource DetailActionButton}"
AutomationProperties.Name="Open export folder for this listing">
<StackPanel Orientation="Horizontal">
<iconPacks:PackIconMaterial Kind="FolderOpen" Width="13" Height="13"
Margin="0,0,6,0" VerticalAlignment="Center"/>
@@ -352,8 +388,8 @@
</StackPanel>
</Button>
<Button Click="CopyTitle_Click"
Style="{DynamicResource MahApps.Styles.Button.Square}"
Height="34" Padding="12,0" Margin="0,0,8,6">
Style="{StaticResource DetailSecondaryButton}"
AutomationProperties.Name="Copy listing title to clipboard">
<Button.Content>
<StackPanel Orientation="Horizontal">
<iconPacks:PackIconMaterial Kind="ContentCopy" Width="12" Height="12"
@@ -363,8 +399,8 @@
</Button.Content>
</Button>
<Button Click="CopyDescription_Click"
Style="{DynamicResource MahApps.Styles.Button.Square}"
Height="34" Padding="12,0" Margin="0,0,8,6">
Style="{StaticResource DetailSecondaryButton}"
AutomationProperties.Name="Copy listing description to clipboard">
<Button.Content>
<StackPanel Orientation="Horizontal">
<iconPacks:PackIconMaterial Kind="ContentCopy" Width="12" Height="12"
@@ -374,8 +410,9 @@
</Button.Content>
</Button>
<Button Click="DeleteListing_Click"
Style="{DynamicResource MahApps.Styles.Button.Square}"
Height="34" Padding="12,0" Margin="0,0,0,6">
Style="{StaticResource MahApps.Styles.Button.Square}"
Height="34" Padding="12,0" Margin="0,0,0,6"
AutomationProperties.Name="Delete this listing">
<Button.Content>
<StackPanel Orientation="Horizontal">
<iconPacks:PackIconMaterial Kind="TrashCanOutline" Width="13" Height="13"
@@ -391,15 +428,17 @@
</StackPanel>
</ScrollViewer>
<!-- Edit panel shown in place of DetailPanel when editing -->
<!-- Edit panel - shown in place of DetailPanel when editing -->
<ScrollViewer x:Name="EditPanel" Visibility="Collapsed"
VerticalScrollBarVisibility="Auto" Padding="18,14">
<StackPanel>
VerticalScrollBarVisibility="Auto" Padding="18,14"
Focusable="False">
<StackPanel KeyboardNavigation.TabNavigation="Local">
<!-- Title -->
<TextBlock Text="TITLE" Style="{StaticResource DetailLabel}" Margin="0,0,0,3"/>
<TextBlock x:Name="EditTitleLabel" Text="TITLE" Style="{StaticResource DetailLabel}" Margin="0,0,0,3"/>
<TextBox x:Name="EditTitle" FontSize="13" Margin="0,0,0,4"
mah:TextBoxHelper.Watermark="Listing title"/>
mah:TextBoxHelper.Watermark="Listing title"
AutomationProperties.LabeledBy="{Binding ElementName=EditTitleLabel}"/>
<!-- Price + Category -->
<Grid Margin="0,0,0,4">
@@ -409,35 +448,40 @@
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0">
<TextBlock Text="PRICE (£)" Style="{StaticResource DetailLabel}" Margin="0,0,0,3"/>
<TextBlock x:Name="EditPriceLabel" Text="PRICE" Style="{StaticResource DetailLabel}" Margin="0,0,0,3"/>
<mah:NumericUpDown x:Name="EditPrice" Minimum="0" Maximum="99999"
StringFormat="F2" Interval="0.5" Value="0"/>
StringFormat="F2" Interval="0.5" Value="0"
AutomationProperties.LabeledBy="{Binding ElementName=EditPriceLabel}"/>
</StackPanel>
<StackPanel Grid.Column="2">
<TextBlock Text="CATEGORY" Style="{StaticResource DetailLabel}" Margin="0,0,0,3"/>
<TextBlock x:Name="EditCategoryLabel" Text="CATEGORY" Style="{StaticResource DetailLabel}" Margin="0,0,0,3"/>
<TextBox x:Name="EditCategory" FontSize="12"
mah:TextBoxHelper.Watermark="e.g. Clothing, Shoes &amp; Accessories"/>
mah:TextBoxHelper.Watermark="e.g. Clothing, Shoes &amp; Accessories"
AutomationProperties.LabeledBy="{Binding ElementName=EditCategoryLabel}"/>
</StackPanel>
</Grid>
<!-- Condition notes -->
<TextBlock Text="CONDITION NOTES" Style="{StaticResource DetailLabel}" Margin="0,0,0,3"/>
<TextBlock x:Name="EditConditionLabel" Text="CONDITION NOTES" Style="{StaticResource DetailLabel}" Margin="0,0,0,3"/>
<TextBox x:Name="EditCondition" FontSize="12" Margin="0,0,0,4"
mah:TextBoxHelper.Watermark="Optional e.g. minor scuff on base"/>
mah:TextBoxHelper.Watermark="Optional - e.g. minor scuff on base"
AutomationProperties.LabeledBy="{Binding ElementName=EditConditionLabel}"/>
<!-- Description -->
<TextBlock Text="DESCRIPTION" Style="{StaticResource DetailLabel}" Margin="0,0,0,3"/>
<TextBlock x:Name="EditDescriptionLabel" Text="DESCRIPTION" Style="{StaticResource DetailLabel}" Margin="0,0,0,3"/>
<TextBox x:Name="EditDescription" FontSize="12" Margin="0,0,0,4"
TextWrapping="Wrap" AcceptsReturn="True"
Height="130" VerticalScrollBarVisibility="Auto"/>
Height="130" VerticalScrollBarVisibility="Auto"
AutomationProperties.LabeledBy="{Binding ElementName=EditDescriptionLabel}"/>
<!-- Photos -->
<TextBlock Text="PHOTOS" Style="{StaticResource DetailLabel}" Margin="0,0,0,3"/>
<TextBlock Text="First photo is the listing cover. Use ◀ ▶ to reorder."
<TextBlock Text="First photo is the listing cover. Use arrows to reorder."
FontSize="10" Foreground="{DynamicResource MahApps.Brushes.Gray5}"
Margin="0,0,0,6"/>
<ScrollViewer HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Disabled"
Focusable="False"
Margin="0,0,0,10">
<StackPanel x:Name="EditPhotosPanel" Orientation="Horizontal"/>
</ScrollViewer>
@@ -447,11 +491,13 @@
<Button x:Name="SaveEditBtn" Click="SaveEdit_Click"
Style="{DynamicResource MahApps.Styles.Button.Square.Accent}"
Height="34" Padding="16,0" Margin="0,0,8,0"
Content="Save Changes"/>
Content="Save Changes"
AutomationProperties.Name="Save listing changes"/>
<Button x:Name="CancelEditBtn" Click="CancelEdit_Click"
Style="{DynamicResource MahApps.Styles.Button.Square}"
Height="34" Padding="14,0"
Content="Cancel"/>
Content="Cancel"
AutomationProperties.Name="Cancel editing"/>
</StackPanel>
</StackPanel>
@@ -470,6 +516,7 @@
BorderThickness="0,0,0,3"
BorderBrush="{DynamicResource MahApps.Brushes.Accent}"
Panel.ZIndex="10">
<Border.RenderTransform>
<TranslateTransform x:Name="ToastTranslate" Y="60"/>
</Border.RenderTransform>
@@ -482,14 +529,16 @@
<iconPacks:PackIconMaterial Kind="CheckCircleOutline"
Width="16" Height="16" Margin="0,0,10,0"
Foreground="{DynamicResource MahApps.Brushes.Accent}"
VerticalAlignment="Center"/>
VerticalAlignment="Center"
IsTabStop="False"/>
<TextBlock x:Name="ToastUrlText" Grid.Column="1"
VerticalAlignment="Center" TextTrimming="CharacterEllipsis"
Foreground="{DynamicResource MahApps.Brushes.Gray1}" FontSize="12"/>
<Button Grid.Column="2" Content="" Width="20" Height="20"
<Button Grid.Column="2" Content="x" Width="20" Height="20"
BorderThickness="0" Background="Transparent"
Foreground="{DynamicResource MahApps.Brushes.Gray5}"
Click="DismissToast_Click" Margin="8,0,0,0"/>
Click="DismissToast_Click" Margin="8,0,0,0"
AutomationProperties.Name="Dismiss notification"/>
</Grid>
</Border>

View File

@@ -778,14 +778,14 @@ public partial class SavedListingsView : UserControl
var draft = _selected.ToListingDraft();
var url = await _ebayListing.PostListingAsync(draft);
ToastUrlText.Text = url;
ShowDraftPostedToast();
var posted = _selected;
_selected = null;
_service?.Delete(posted);
ClearDetail();
RefreshList();
ToastUrlText.Text = url;
ShowDraftPostedToast();
}
catch (Exception ex)
{
@@ -810,7 +810,11 @@ public partial class SavedListingsView : UserControl
private void ShowDraftPostedToast()
{
_toastTimer?.Stop();
if (_toastTimer != null)
{
_toastTimer.Stop();
_toastTimer = null;
}
ToastTranslate.BeginAnimation(System.Windows.Media.TranslateTransform.YProperty, null);
DraftPostedToast.Visibility = Visibility.Visible;
@@ -835,6 +839,7 @@ public partial class SavedListingsView : UserControl
private void DismissToastAnimated()
{
_toastTimer?.Stop();
_toastTimer = null;
var slideOut = new System.Windows.Media.Animation.DoubleAnimation(
0, 60, new Duration(TimeSpan.FromMilliseconds(180)))
{

View File

@@ -204,6 +204,55 @@
</ListBox.ItemTemplate>
</ListBox>
<!-- Item Specifics (Aspects) panel — revealed after category is selected -->
<Border x:Name="AspectsPanel" Visibility="Collapsed"
CornerRadius="4" Margin="0,10,0,0" Padding="12,10"
BorderBrush="{DynamicResource MahApps.Brushes.Gray7}" BorderThickness="1">
<StackPanel>
<Grid Margin="0,0,0,8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<StackPanel Orientation="Horizontal">
<mah:ProgressRing x:Name="AspectsSpinner" Width="14" Height="14"
Margin="0,0,6,0" VerticalAlignment="Center"
Visibility="Collapsed"/>
<TextBlock Text="Item Specifics" FontWeight="SemiBold" FontSize="12"
VerticalAlignment="Center"
Foreground="{DynamicResource MahApps.Brushes.Gray2}"/>
<TextBlock x:Name="AspectsRequiredNote"
Text=" (required fields marked *)"
FontSize="11" VerticalAlignment="Center"
Foreground="{DynamicResource MahApps.Brushes.Gray5}"
Visibility="Collapsed"/>
</StackPanel>
<Button Grid.Column="1" x:Name="AiAspectsBtn"
Style="{StaticResource AiButton}"
Height="26" Padding="10,0" FontSize="11"
Click="AiAspects_Click"
ToolTip="Let AI suggest values from your title and description">
<StackPanel Orientation="Horizontal">
<mah:ProgressRing x:Name="AspectsAiSpinner" Width="11" Height="11"
Margin="0,0,4,0" Foreground="White"
Visibility="Collapsed"/>
<iconPacks:PackIconMaterial x:Name="AspectsAiIcon" Kind="AutoFix"
Width="11" Height="11" Margin="0,0,4,0"
VerticalAlignment="Center"/>
<TextBlock Text="AI Suggest" VerticalAlignment="Center"/>
</StackPanel>
</Button>
</Grid>
<ItemsControl x:Name="AspectsItemsControl">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</StackPanel>
</Border>
<!-- Condition + Format -->
<Grid Margin="0,10,0,0">
<Grid.ColumnDefinitions>
@@ -311,6 +360,8 @@
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="12"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="16"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<!-- Price with inline AI button -->
@@ -352,7 +403,7 @@
<StackPanel Grid.Column="4">
<TextBlock Style="{StaticResource FieldLabel}" Text="Postage"/>
<ComboBox x:Name="PostageBox">
<ComboBox x:Name="PostageBox" SelectionChanged="PostageBox_SelectionChanged">
<ComboBoxItem Content="Royal Mail 1st Class (~£1.55)" IsSelected="True"/>
<ComboBoxItem Content="Royal Mail 2nd Class (~£1.20)"/>
<ComboBoxItem Content="Royal Mail Tracked 24 (~£2.90)"/>
@@ -361,6 +412,14 @@
<ComboBoxItem Content="Collection Only"/>
</ComboBox>
</StackPanel>
<StackPanel Grid.Column="6">
<TextBlock Style="{StaticResource FieldLabel}" Text="Shipping Cost (£)"/>
<mah:NumericUpDown x:Name="ShippingCostBox"
Minimum="0" Maximum="99" StringFormat="F2"
Interval="0.50" Value="0"
Width="110" HorizontalAlignment="Left"/>
</StackPanel>
</Grid>
<!-- Postcode — narrower input, left-aligned -->

View File

@@ -1,694 +0,0 @@
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media.Imaging;
using EbayListingTool.Models;
using EbayListingTool.Services;
using Microsoft.Win32;
namespace EbayListingTool.Views;
public partial class SingleItemView : UserControl
{
private EbayListingService? _listingService;
private EbayCategoryService? _categoryService;
private AiAssistantService? _aiService;
private EbayAuthService? _auth;
private ListingDraft _draft = new();
private System.Threading.CancellationTokenSource? _categoryCts;
private bool _suppressCategoryLookup;
private string _suggestedPriceValue = "";
// Photo drag-reorder
private Point _dragStartPoint;
private bool _isDragging;
public SingleItemView()
{
InitializeComponent();
PostcodeBox.TextChanged += (s, e) => _draft.Postcode = PostcodeBox.Text;
}
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
// Re-run the count bar calculations now that the layout has rendered
// and the track Border has a non-zero ActualWidth.
TitleBox_TextChanged(this, null!);
DescriptionBox_TextChanged(this, null!);
}
public void Initialise(EbayListingService listingService, EbayCategoryService categoryService,
AiAssistantService aiService, EbayAuthService auth)
{
_listingService = listingService;
_categoryService = categoryService;
_aiService = aiService;
_auth = auth;
PostcodeBox.Text = App.Configuration["Ebay:DefaultPostcode"] ?? "";
}
/// <summary>Pre-fills the form from a Photo Analysis result.</summary>
public async void PopulateFromAnalysis(PhotoAnalysisResult result, IReadOnlyList<string> imagePaths, decimal price)
{
// Q6: reset form directly — calling NewListing_Click shows a confirmation dialog which
// is unexpected when arriving here automatically from the Photo Analysis tab.
_draft = new ListingDraft { Postcode = PostcodeBox.Text };
TitleBox.Text = "";
DescriptionBox.Text = "";
CategoryBox.Text = "";
CategoryIdLabel.Text = "(no category)";
PriceBox.Value = 0;
QuantityBox.Value = 1;
ConditionBox.SelectedIndex = 3; // Used
FormatBox.SelectedIndex = 0;
PhotosPanel.Children.Clear();
UpdatePhotoPanel();
SuccessPanel.Visibility = Visibility.Collapsed;
PriceSuggestionPanel.Visibility = Visibility.Collapsed;
TitleBox.Text = result.Title;
DescriptionBox.Text = result.Description;
PriceBox.Value = (double)price;
// Auto-fill the top eBay category from the analysis keyword; user can override
await AutoFillCategoryAsync(result.CategoryKeyword);
// Q1: load all photos from analysis
var validPaths = imagePaths.Where(p => !string.IsNullOrEmpty(p) && File.Exists(p)).ToArray();
if (validPaths.Length > 0)
AddPhotos(validPaths);
}
// ---- Title ----
private void TitleBox_TextChanged(object sender, TextChangedEventArgs e)
{
_draft.Title = TitleBox.Text;
var len = TitleBox.Text.Length;
TitleCount.Text = $"{len} / 80";
var overLimit = len > 75;
TitleCount.Foreground = overLimit
? System.Windows.Media.Brushes.OrangeRed
: (System.Windows.Media.Brush)FindResource("MahApps.Brushes.Gray5");
// Update the progress bar fill width proportionally
var trackBorder = TitleCountBar.Parent as Border;
double trackWidth = trackBorder?.ActualWidth ?? 0;
if (trackWidth > 0)
TitleCountBar.Width = trackWidth * (len / 80.0);
TitleCountBar.Background = overLimit
? System.Windows.Media.Brushes.OrangeRed
: (System.Windows.Media.Brush)FindResource("MahApps.Brushes.Accent");
}
private async void AiTitle_Click(object sender, RoutedEventArgs e)
{
if (_aiService == null) return;
var condition = GetSelectedCondition().ToString();
var current = TitleBox.Text;
SetTitleSpinner(true);
SetBusy(true, "Generating title...");
try
{
var title = await _aiService.GenerateTitleAsync(current, condition);
TitleBox.Text = title.Trim().TrimEnd('.').Trim('"');
// Auto-fill category from the generated title if not already set
if (string.IsNullOrWhiteSpace(_draft.CategoryId))
await AutoFillCategoryAsync(TitleBox.Text);
}
catch (Exception ex)
{
ShowError("AI Title", ex.Message);
}
finally { SetBusy(false); SetTitleSpinner(false); }
}
// ---- Category ----
private async void CategoryBox_TextChanged(object sender, TextChangedEventArgs e)
{
if (_suppressCategoryLookup) return;
_categoryCts?.Cancel();
_categoryCts?.Dispose();
_categoryCts = new System.Threading.CancellationTokenSource();
var cts = _categoryCts;
if (CategoryBox.Text.Length < 3)
{
CategorySuggestionsList.Visibility = Visibility.Collapsed;
return;
}
try
{
await Task.Delay(400, cts.Token);
}
catch (OperationCanceledException)
{
return;
}
if (cts.IsCancellationRequested) return;
try
{
var suggestions = await _categoryService!.GetCategorySuggestionsAsync(CategoryBox.Text);
if (cts.IsCancellationRequested) return;
Dispatcher.Invoke(() =>
{
CategorySuggestionsList.ItemsSource = suggestions;
CategorySuggestionsList.Visibility = suggestions.Count > 0
? Visibility.Visible : Visibility.Collapsed;
});
}
catch (OperationCanceledException) { /* superseded by newer keystroke */ }
catch { /* ignore transient network errors */ }
}
private void DescriptionBox_TextChanged(object sender, TextChangedEventArgs e)
{
_draft.Description = DescriptionBox.Text;
var len = DescriptionBox.Text.Length;
var softCap = 2000;
DescCount.Text = $"{len} / {softCap}";
var overLimit = len > softCap;
DescCount.Foreground = overLimit
? System.Windows.Media.Brushes.OrangeRed
: (System.Windows.Media.Brush)FindResource("MahApps.Brushes.Gray5");
var trackBorder = DescCountBar.Parent as Border;
double trackWidth = trackBorder?.ActualWidth ?? 0;
if (trackWidth > 0)
DescCountBar.Width = Math.Min(trackWidth, trackWidth * (len / (double)softCap));
DescCountBar.Background = overLimit
? System.Windows.Media.Brushes.OrangeRed
: new System.Windows.Media.SolidColorBrush(
System.Windows.Media.Color.FromRgb(0xF5, 0x9E, 0x0B)); // amber
}
private void CategoryBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Escape)
{
CategorySuggestionsList.Visibility = Visibility.Collapsed;
e.Handled = true;
}
}
private void CategorySuggestionsList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (CategorySuggestionsList.SelectedItem is CategorySuggestion cat)
{
_draft.CategoryId = cat.CategoryId;
_draft.CategoryName = cat.CategoryName;
CategoryBox.Text = cat.CategoryName;
CategoryIdLabel.Text = $"ID: {cat.CategoryId}";
CategorySuggestionsList.Visibility = Visibility.Collapsed;
}
}
/// <summary>
/// Fetches the top eBay category suggestion for <paramref name="keyword"/> and auto-fills
/// the category fields. The suggestions list is shown so the user can override.
/// </summary>
private async Task AutoFillCategoryAsync(string keyword)
{
if (_categoryService == null || string.IsNullOrWhiteSpace(keyword)) return;
try
{
var suggestions = await _categoryService.GetCategorySuggestionsAsync(keyword);
if (suggestions.Count == 0) return;
var top = suggestions[0];
_suppressCategoryLookup = true;
try
{
_draft.CategoryId = top.CategoryId;
_draft.CategoryName = top.CategoryName;
CategoryBox.Text = top.CategoryName;
CategoryIdLabel.Text = $"ID: {top.CategoryId}";
}
finally { _suppressCategoryLookup = false; }
// Show the full list so user can see alternatives and override
CategorySuggestionsList.ItemsSource = suggestions;
CategorySuggestionsList.Visibility = suggestions.Count > 1
? Visibility.Visible : Visibility.Collapsed;
}
catch { /* non-critical — leave category blank if lookup fails */ }
}
// ---- Condition ----
private void ConditionBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
_draft.Condition = GetSelectedCondition();
}
private ItemCondition GetSelectedCondition()
{
var tag = (ConditionBox.SelectedItem as ComboBoxItem)?.Tag?.ToString() ?? "Used";
return tag switch
{
"New" => ItemCondition.New,
"OpenBox" => ItemCondition.OpenBox,
"Refurbished" => ItemCondition.Refurbished,
"ForParts" => ItemCondition.ForPartsOrNotWorking,
_ => ItemCondition.Used
};
}
// ---- Description ----
private async void AiDescription_Click(object sender, RoutedEventArgs e)
{
if (_aiService == null) return;
SetDescSpinner(true);
SetBusy(true, "Writing description...");
try
{
var description = await _aiService.WriteDescriptionAsync(
TitleBox.Text, GetSelectedCondition().ToString(), DescriptionBox.Text);
DescriptionBox.Text = description;
}
catch (Exception ex) { ShowError("AI Description", ex.Message); }
finally { SetBusy(false); SetDescSpinner(false); }
}
// ---- Price ----
private async void AiPrice_Click(object sender, RoutedEventArgs e)
{
if (_aiService == null) return;
SetPriceSpinner(true);
SetBusy(true, "Researching price...");
try
{
var result = await _aiService.SuggestPriceAsync(
TitleBox.Text, GetSelectedCondition().ToString());
PriceSuggestionText.Text = result;
// Extract price line for "Use this price"
var lines = result.Split('\n', StringSplitOptions.RemoveEmptyEntries);
var priceLine = lines.FirstOrDefault(l => l.StartsWith("PRICE:", StringComparison.OrdinalIgnoreCase));
_suggestedPriceValue = priceLine?.Replace("PRICE:", "", StringComparison.OrdinalIgnoreCase).Trim() ?? "";
PriceSuggestionPanel.Visibility = Visibility.Visible;
}
catch (Exception ex) { ShowError("AI Price", ex.Message); }
finally { SetBusy(false); SetPriceSpinner(false); }
}
private void UseSuggestedPrice_Click(object sender, RoutedEventArgs e)
{
if (decimal.TryParse(_suggestedPriceValue, out var price))
PriceBox.Value = (double)price;
}
// ---- Photos ----
private void Photos_DragOver(object sender, DragEventArgs e)
{
e.Effects = e.Data.GetDataPresent(DataFormats.FileDrop)
? DragDropEffects.Copy : DragDropEffects.None;
e.Handled = true;
}
private void Photos_Drop(object sender, DragEventArgs e)
{
if (!e.Data.GetDataPresent(DataFormats.FileDrop)) return;
var files = (string[])e.Data.GetData(DataFormats.FileDrop);
// Remove highlight when drop completes
DropZone.BorderBrush = (System.Windows.Media.Brush)FindResource("MahApps.Brushes.Gray7");
DropZone.Background = (System.Windows.Media.Brush)FindResource("MahApps.Brushes.Gray10");
AddPhotos(files);
}
private void DropZone_DragEnter(object sender, DragEventArgs e)
{
if (!e.Data.GetDataPresent(DataFormats.FileDrop)) return;
DropZone.BorderBrush = (System.Windows.Media.Brush)FindResource("MahApps.Brushes.Accent");
DropZone.Background = new System.Windows.Media.SolidColorBrush(
System.Windows.Media.Color.FromArgb(20, 0x5C, 0x6B, 0xC0)); // subtle indigo tint
}
private void DropZone_DragLeave(object sender, DragEventArgs e)
{
DropZone.BorderBrush = (System.Windows.Media.Brush)FindResource("MahApps.Brushes.Gray7");
DropZone.Background = (System.Windows.Media.Brush)FindResource("MahApps.Brushes.Gray10");
}
private void BrowsePhotos_Click(object sender, RoutedEventArgs e)
{
var dlg = new OpenFileDialog
{
Title = "Select photos",
Filter = "Images|*.jpg;*.jpeg;*.png;*.gif;*.bmp|All files|*.*",
Multiselect = true
};
if (dlg.ShowDialog() == true)
AddPhotos(dlg.FileNames);
}
private void AddPhotos(string[] paths)
{
var imageExts = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{ ".jpg", ".jpeg", ".png", ".gif", ".bmp" };
foreach (var path in paths)
{
if (!imageExts.Contains(Path.GetExtension(path))) continue;
if (_draft.PhotoPaths.Count >= 12) break;
if (_draft.PhotoPaths.Contains(path)) continue;
_draft.PhotoPaths.Add(path);
}
RebuildPhotoThumbnails();
}
/// <summary>
/// Clears and recreates all photo thumbnails from <see cref="ListingDraft.PhotoPaths"/>.
/// Called after any add, remove, or reorder operation so the panel always matches the list.
/// </summary>
private void RebuildPhotoThumbnails()
{
PhotosPanel.Children.Clear();
for (int i = 0; i < _draft.PhotoPaths.Count; i++)
AddPhotoThumbnail(_draft.PhotoPaths[i], i);
UpdatePhotoPanel();
}
private void AddPhotoThumbnail(string path, int index)
{
try
{
var bmp = new BitmapImage();
bmp.BeginInit();
bmp.UriSource = new Uri(path, UriKind.Absolute);
bmp.DecodePixelWidth = 128;
bmp.CacheOption = BitmapCacheOption.OnLoad;
bmp.EndInit();
bmp.Freeze();
var img = new System.Windows.Controls.Image
{
Width = 72, Height = 72,
Stretch = System.Windows.Media.Stretch.UniformToFill,
Source = bmp,
ToolTip = Path.GetFileName(path)
};
img.Clip = new System.Windows.Media.RectangleGeometry(new Rect(0, 0, 72, 72), 4, 4);
// Remove button
var removeBtn = new Button
{
Width = 18, Height = 18,
Cursor = Cursors.Hand,
ToolTip = "Remove photo",
HorizontalAlignment = HorizontalAlignment.Right,
VerticalAlignment = VerticalAlignment.Top,
Margin = new Thickness(0, 2, 2, 0),
Padding = new Thickness(0),
Background = new System.Windows.Media.SolidColorBrush(
System.Windows.Media.Color.FromArgb(200, 30, 30, 30)),
Foreground = System.Windows.Media.Brushes.White,
BorderThickness = new Thickness(0),
FontSize = 11, FontWeight = FontWeights.Bold,
Content = "✕",
Opacity = 0
};
removeBtn.Click += (s, e) =>
{
e.Handled = true; // don't bubble and trigger drag
_draft.PhotoPaths.Remove(path);
RebuildPhotoThumbnails();
};
// "Cover" badge on the first photo — it becomes the eBay gallery hero image
Border? coverBadge = null;
if (index == 0)
{
coverBadge = new Border
{
CornerRadius = new CornerRadius(3),
Background = new System.Windows.Media.SolidColorBrush(
System.Windows.Media.Color.FromArgb(210, 60, 90, 200)),
Padding = new Thickness(3, 1, 3, 1),
Margin = new Thickness(2, 2, 0, 0),
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Top,
IsHitTestVisible = false, // don't block drag
Child = new TextBlock
{
Text = "Cover",
FontSize = 8,
FontWeight = FontWeights.SemiBold,
Foreground = System.Windows.Media.Brushes.White
}
};
}
var container = new Grid
{
Width = 72, Height = 72,
Margin = new Thickness(4),
Cursor = Cursors.SizeAll, // signal draggability
AllowDrop = true,
Tag = path // stable identifier used by drop handler
};
container.Children.Add(img);
if (coverBadge != null) container.Children.Add(coverBadge);
container.Children.Add(removeBtn);
// Hover: reveal remove button
container.MouseEnter += (s, e) => removeBtn.Opacity = 1;
container.MouseLeave += (s, e) => removeBtn.Opacity = 0;
// Drag initiation
container.MouseLeftButtonDown += (s, e) =>
{
_dragStartPoint = e.GetPosition(null);
};
container.MouseMove += (s, e) =>
{
if (e.LeftButton != MouseButtonState.Pressed || _isDragging) return;
var pos = e.GetPosition(null);
if (Math.Abs(pos.X - _dragStartPoint.X) > SystemParameters.MinimumHorizontalDragDistance ||
Math.Abs(pos.Y - _dragStartPoint.Y) > SystemParameters.MinimumVerticalDragDistance)
{
_isDragging = true;
DragDrop.DoDragDrop(container, path, DragDropEffects.Move);
_isDragging = false;
}
};
// Drop target
container.DragOver += (s, e) =>
{
if (e.Data.GetDataPresent(typeof(string)) &&
(string)e.Data.GetData(typeof(string)) != path)
{
e.Effects = DragDropEffects.Move;
container.Opacity = 0.45; // dim to signal insertion point
}
else
{
e.Effects = DragDropEffects.None;
}
e.Handled = true;
};
container.DragLeave += (s, e) => container.Opacity = 1.0;
container.Drop += (s, e) =>
{
container.Opacity = 1.0;
if (!e.Data.GetDataPresent(typeof(string))) return;
var sourcePath = (string)e.Data.GetData(typeof(string));
var targetPath = (string)container.Tag;
if (sourcePath == targetPath) return;
var sourceIdx = _draft.PhotoPaths.IndexOf(sourcePath);
var targetIdx = _draft.PhotoPaths.IndexOf(targetPath);
if (sourceIdx < 0 || targetIdx < 0) return;
_draft.PhotoPaths.RemoveAt(sourceIdx);
_draft.PhotoPaths.Insert(targetIdx, sourcePath);
RebuildPhotoThumbnails();
e.Handled = true;
};
PhotosPanel.Children.Add(container);
}
catch { /* skip unreadable files */ }
}
private void UpdatePhotoPanel()
{
var count = _draft.PhotoPaths.Count;
DropHint.Visibility = count == 0 ? Visibility.Visible : Visibility.Collapsed;
PhotoCountBadge.Text = count.ToString();
// Tint the badge red when at the limit
PhotoCountBadge.Foreground = count >= 12
? System.Windows.Media.Brushes.OrangeRed
: (System.Windows.Media.Brush)FindResource("MahApps.Brushes.Gray2");
}
private void ClearPhotos_Click(object sender, RoutedEventArgs e)
{
_draft.PhotoPaths.Clear();
RebuildPhotoThumbnails();
}
// ---- Post / Save ----
private async void PostListing_Click(object sender, RoutedEventArgs e)
{
if (!ValidateDraft()) return;
_draft.Title = TitleBox.Text.Trim();
_draft.Description = DescriptionBox.Text.Trim();
_draft.Price = (decimal)(PriceBox.Value ?? 0);
_draft.Quantity = (int)(QuantityBox.Value ?? 1);
_draft.Condition = GetSelectedCondition();
_draft.Format = FormatBox.SelectedIndex == 0 ? ListingFormat.FixedPrice : ListingFormat.Auction;
_draft.Postcode = PostcodeBox.Text;
SetPostSpinner(true);
SetBusy(true, "Posting to eBay...");
PostBtn.IsEnabled = false;
try
{
var url = await _listingService!.PostListingAsync(_draft);
ListingUrlText.Text = url;
SuccessPanel.Visibility = Visibility.Visible;
GetWindow()?.SetStatus($"Listed: {_draft.Title}");
}
catch (Exception ex)
{
ShowError("Post Failed", ex.Message);
}
finally
{
SetBusy(false);
SetPostSpinner(false);
PostBtn.IsEnabled = true;
}
}
private void ListingUrl_Click(object sender, MouseButtonEventArgs e)
{
if (!string.IsNullOrEmpty(_draft.EbayListingUrl))
Process.Start(new ProcessStartInfo(_draft.EbayListingUrl) { UseShellExecute = true });
}
private void CopyUrl_Click(object sender, RoutedEventArgs e)
{
var url = ListingUrlText.Text;
if (!string.IsNullOrEmpty(url))
System.Windows.Clipboard.SetText(url);
}
private void CopyTitle_Click(object sender, RoutedEventArgs e)
{
if (!string.IsNullOrEmpty(_draft.Title))
System.Windows.Clipboard.SetText(_draft.Title);
}
private void SaveDraft_Click(object sender, RoutedEventArgs e)
{
// Drafts: future feature — for now just confirm save
MessageBox.Show("Draft saved (local save to be implemented in a future update).",
"Save Draft", MessageBoxButton.OK, MessageBoxImage.Information);
}
private void NewListing_Click(object sender, RoutedEventArgs e)
{
if (!string.IsNullOrWhiteSpace(TitleBox.Text))
{
var result = MessageBox.Show(
"Start a new listing? Current details will be lost.",
"New Listing",
MessageBoxButton.OKCancel,
MessageBoxImage.Question);
if (result != MessageBoxResult.OK) return;
}
_draft = new ListingDraft { Postcode = PostcodeBox.Text };
TitleBox.Text = "";
DescriptionBox.Text = "";
CategoryBox.Text = "";
CategoryIdLabel.Text = "(no category)";
PriceBox.Value = 0;
QuantityBox.Value = 1;
ConditionBox.SelectedIndex = 3; // Used
FormatBox.SelectedIndex = 0;
PhotosPanel.Children.Clear();
UpdatePhotoPanel();
SuccessPanel.Visibility = Visibility.Collapsed;
PriceSuggestionPanel.Visibility = Visibility.Collapsed;
}
// ---- Helpers ----
private bool ValidateDraft()
{
if (string.IsNullOrWhiteSpace(TitleBox.Text))
{ ShowError("Validation", "Please enter a title."); return false; }
if (TitleBox.Text.Length > 80)
{ ShowError("Validation", "Title must be 80 characters or fewer."); return false; }
if (string.IsNullOrEmpty(_draft.CategoryId))
{ ShowError("Validation", "Please select a category."); return false; }
if ((PriceBox.Value ?? 0) <= 0)
{ ShowError("Validation", "Please enter a price greater than zero."); return false; }
return true;
}
private void SetBusy(bool busy, string message = "")
{
IsEnabled = !busy;
GetWindow()?.SetStatus(busy ? message : "Ready");
}
private void SetPostSpinner(bool spinning)
{
PostSpinner.Visibility = spinning ? Visibility.Visible : Visibility.Collapsed;
PostIcon.Visibility = spinning ? Visibility.Collapsed : Visibility.Visible;
}
private void SetTitleSpinner(bool spinning)
{
TitleSpinner.Visibility = spinning ? Visibility.Visible : Visibility.Collapsed;
TitleAiIcon.Visibility = spinning ? Visibility.Collapsed : Visibility.Visible;
}
private void SetDescSpinner(bool spinning)
{
DescSpinner.Visibility = spinning ? Visibility.Visible : Visibility.Collapsed;
DescAiIcon.Visibility = spinning ? Visibility.Collapsed : Visibility.Visible;
}
private void SetPriceSpinner(bool spinning)
{
PriceSpinner.Visibility = spinning ? Visibility.Visible : Visibility.Collapsed;
PriceAiIcon.Visibility = spinning ? Visibility.Collapsed : Visibility.Visible;
}
private void ShowError(string title, string message)
=> MessageBox.Show(message, title, MessageBoxButton.OK, MessageBoxImage.Warning);
private MainWindow? GetWindow() => Window.GetWindow(this) as MainWindow;
}