feat: add Post to eBay button and toast to SavedListingsView
This commit is contained in:
@@ -318,6 +318,21 @@
|
|||||||
|
|
||||||
<!-- Action buttons -->
|
<!-- Action buttons -->
|
||||||
<WrapPanel Orientation="Horizontal">
|
<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">
|
||||||
|
<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"/>
|
||||||
|
<TextBlock Text="Post to eBay" VerticalAlignment="Center"/>
|
||||||
|
</StackPanel>
|
||||||
|
</Button>
|
||||||
<Button Click="EditListing_Click"
|
<Button Click="EditListing_Click"
|
||||||
Style="{DynamicResource MahApps.Styles.Button.Square.Accent}"
|
Style="{DynamicResource MahApps.Styles.Button.Square.Accent}"
|
||||||
Height="34" Padding="14,0" Margin="0,0,8,6">
|
Height="34" Padding="14,0" Margin="0,0,8,6">
|
||||||
@@ -443,5 +458,40 @@
|
|||||||
</ScrollViewer>
|
</ScrollViewer>
|
||||||
|
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
|
<!-- Draft posted toast -->
|
||||||
|
<Border x:Name="DraftPostedToast"
|
||||||
|
Grid.Column="2"
|
||||||
|
Visibility="Collapsed"
|
||||||
|
VerticalAlignment="Bottom"
|
||||||
|
Margin="12" Padding="14,10"
|
||||||
|
CornerRadius="6"
|
||||||
|
Background="{DynamicResource MahApps.Brushes.Gray8}"
|
||||||
|
BorderThickness="0,0,0,3"
|
||||||
|
BorderBrush="{DynamicResource MahApps.Brushes.Accent}"
|
||||||
|
Panel.ZIndex="10">
|
||||||
|
<Border.RenderTransform>
|
||||||
|
<TranslateTransform x:Name="ToastTranslate" Y="60"/>
|
||||||
|
</Border.RenderTransform>
|
||||||
|
<Grid>
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="Auto"/>
|
||||||
|
<ColumnDefinition Width="*"/>
|
||||||
|
<ColumnDefinition Width="Auto"/>
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<iconPacks:PackIconMaterial Kind="CheckCircleOutline"
|
||||||
|
Width="16" Height="16" Margin="0,0,10,0"
|
||||||
|
Foreground="{DynamicResource MahApps.Brushes.Accent}"
|
||||||
|
VerticalAlignment="Center"/>
|
||||||
|
<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"
|
||||||
|
BorderThickness="0" Background="Transparent"
|
||||||
|
Foreground="{DynamicResource MahApps.Brushes.Gray5}"
|
||||||
|
Click="DismissToast_Click" Margin="8,0,0,0"/>
|
||||||
|
</Grid>
|
||||||
|
</Border>
|
||||||
|
|
||||||
</Grid>
|
</Grid>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using System.Windows.Input;
|
|||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using System.Windows.Media.Animation;
|
using System.Windows.Media.Animation;
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
|
using System.Windows.Threading;
|
||||||
using EbayListingTool.Models;
|
using EbayListingTool.Models;
|
||||||
using EbayListingTool.Services;
|
using EbayListingTool.Services;
|
||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
@@ -14,6 +15,8 @@ public partial class SavedListingsView : UserControl
|
|||||||
{
|
{
|
||||||
private SavedListingsService? _service;
|
private SavedListingsService? _service;
|
||||||
private PriceLookupService? _priceLookup;
|
private PriceLookupService? _priceLookup;
|
||||||
|
private EbayListingService? _ebayListing;
|
||||||
|
private EbayAuthService? _ebayAuth;
|
||||||
private SavedListing? _selected;
|
private SavedListing? _selected;
|
||||||
|
|
||||||
// Edit mode working state
|
// Edit mode working state
|
||||||
@@ -34,10 +37,15 @@ public partial class SavedListingsView : UserControl
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Initialise(SavedListingsService service, PriceLookupService? priceLookup = null)
|
public void Initialise(SavedListingsService service,
|
||||||
|
PriceLookupService? priceLookup = null,
|
||||||
|
EbayListingService? ebayListing = null,
|
||||||
|
EbayAuthService? ebayAuth = null)
|
||||||
{
|
{
|
||||||
_service = service;
|
_service = service;
|
||||||
_priceLookup = priceLookup;
|
_priceLookup = priceLookup;
|
||||||
|
_ebayListing = ebayListing;
|
||||||
|
_ebayAuth = ebayAuth;
|
||||||
RefreshList();
|
RefreshList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -753,4 +761,87 @@ public partial class SavedListingsView : UserControl
|
|||||||
ClearDetail();
|
ClearDetail();
|
||||||
RefreshList();
|
RefreshList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async void PostDraft_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if (_selected == null || _ebayListing == null || _ebayAuth == null) return;
|
||||||
|
if (!_ebayAuth.IsConnected)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Please connect to eBay first.", "Not Connected",
|
||||||
|
MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SetPostDraftBusy(true);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var draft = _selected.ToListingDraft();
|
||||||
|
var url = await _ebayListing.PostListingAsync(draft);
|
||||||
|
|
||||||
|
ToastUrlText.Text = url;
|
||||||
|
ShowDraftPostedToast();
|
||||||
|
|
||||||
|
var posted = _selected;
|
||||||
|
_selected = null;
|
||||||
|
_service?.Delete(posted);
|
||||||
|
ClearDetail();
|
||||||
|
RefreshList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show($"Failed to post listing:\n\n{ex.Message}", "Post Failed",
|
||||||
|
MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
SetPostDraftBusy(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetPostDraftBusy(bool busy)
|
||||||
|
{
|
||||||
|
PostDraftBtn.IsEnabled = !busy;
|
||||||
|
PostDraftIcon.Visibility = busy ? Visibility.Collapsed : Visibility.Visible;
|
||||||
|
PostDraftSpinner.Visibility = busy ? Visibility.Visible : Visibility.Collapsed;
|
||||||
|
IsEnabled = !busy;
|
||||||
|
}
|
||||||
|
|
||||||
|
private DispatcherTimer? _toastTimer;
|
||||||
|
|
||||||
|
private void ShowDraftPostedToast()
|
||||||
|
{
|
||||||
|
_toastTimer?.Stop();
|
||||||
|
ToastTranslate.BeginAnimation(System.Windows.Media.TranslateTransform.YProperty, null);
|
||||||
|
DraftPostedToast.Visibility = Visibility.Visible;
|
||||||
|
|
||||||
|
var slideIn = new System.Windows.Media.Animation.DoubleAnimation(
|
||||||
|
60, 0, new Duration(TimeSpan.FromMilliseconds(220)))
|
||||||
|
{
|
||||||
|
EasingFunction = new System.Windows.Media.Animation.CubicEase
|
||||||
|
{ EasingMode = System.Windows.Media.Animation.EasingMode.EaseOut }
|
||||||
|
};
|
||||||
|
slideIn.Completed += (_, _) =>
|
||||||
|
{
|
||||||
|
_toastTimer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(8) };
|
||||||
|
_toastTimer.Tick += (_, _) => DismissToastAnimated();
|
||||||
|
_toastTimer.Start();
|
||||||
|
};
|
||||||
|
ToastTranslate.BeginAnimation(System.Windows.Media.TranslateTransform.YProperty, slideIn);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DismissToast_Click(object sender, RoutedEventArgs e)
|
||||||
|
=> DismissToastAnimated();
|
||||||
|
|
||||||
|
private void DismissToastAnimated()
|
||||||
|
{
|
||||||
|
_toastTimer?.Stop();
|
||||||
|
var slideOut = new System.Windows.Media.Animation.DoubleAnimation(
|
||||||
|
0, 60, new Duration(TimeSpan.FromMilliseconds(180)))
|
||||||
|
{
|
||||||
|
EasingFunction = new System.Windows.Media.Animation.CubicEase
|
||||||
|
{ EasingMode = System.Windows.Media.Animation.EasingMode.EaseIn }
|
||||||
|
};
|
||||||
|
slideOut.Completed += (_, _) => DraftPostedToast.Visibility = Visibility.Collapsed;
|
||||||
|
ToastTranslate.BeginAnimation(System.Windows.Media.TranslateTransform.YProperty, slideOut);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user