Wired up CartDrawel and ProductView to cart service and local storage
continuous-integration/drone/pr Build is passing

This commit is contained in:
Khwezi Mngoma
2026-06-10 23:01:21 +02:00
parent 3bce80c963
commit 64e0fcba27
5 changed files with 85 additions and 61 deletions
@@ -19,13 +19,6 @@ public partial class MainLayout(CartService cartService) : IDisposable
private bool IsSearchActive { get; set; } = false;
private bool IsCartOpen { get; set; } = false;
private List<CartItem> CartItems = new()
{
new CartItem { Id = 1, Title = "Letters from M/M (Paris)", Author = "M/M Paris", Price = 720, Quantity = 1 },
new CartItem { Id = 2, Title = "Daan Paans: Floating Signifiers", Author = "Daan Paans", Price = 540, Quantity = 1 },
new CartItem { Id = 3, Title = "Album Architectures, Maputo", Author = "Guedes Archive", Price = 350, Quantity = 1 }
};
protected override async Task OnInitializedAsync()
{
AuthState = await AuthStateProvider.GetAuthenticationStateAsync();
@@ -111,16 +104,23 @@ public partial class MainLayout(CartService cartService) : IDisposable
private void ToggleCart() => IsCartOpen = !IsCartOpen;
private void ChangeQuantity(CartItem item, int delta)
private async void ChangeQuantity(CartItem item, int delta)
{
item.Quantity += delta;
if (item.Quantity <= 0)
{
CartItems.Remove(item);
}
var peekQuantity = item.Quantity + delta;
if (peekQuantity < 1) return;
cartService.UpdateQuantity(item.Price!.Id, delta);
await cartService.SaveCartToStorageAsync();
}
private void RemoveFromCart(CartItem item) => CartItems.Remove(item);
private async void RemoveFromCart(CartItem item)
{
cartService.RemoveOneItem(item.Price!.Id);
await cartService.SaveCartToStorageAsync();
}
private decimal GetCartTotal() => ShoppingCart?.TotalPrice ?? 0.00m;
@@ -143,13 +143,4 @@ public partial class MainLayout(CartService cartService) : IDisposable
GC.SuppressFinalize(this);
}
public class CartItem
{
public int Id { get; set; }
public string Title { get; set; } = string.Empty;
public string Author { get; set; } = string.Empty;
public int Price { get; set; }
public int Quantity { get; set; }
}
}