Refactor categories view with tree structure and improve product caching
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using FrontOffice.Main.Utilities;
|
||||
using MudBlazor;
|
||||
|
||||
namespace FrontOffice.Main.Pages.Store;
|
||||
|
||||
@@ -20,8 +21,8 @@ public partial class ProductDetail : ComponentBase, IDisposable
|
||||
private const int MaxQty = 20;
|
||||
private IReadOnlyList<ProductGalleryImage> _galleryItems = Array.Empty<ProductGalleryImage>();
|
||||
private IReadOnlyList<ProductCategoryPathInfo> _categoryPaths = Array.Empty<ProductCategoryPathInfo>();
|
||||
private IReadOnlyList<ProductCategoryNodeInfo> _breadcrumbNodes = Array.Empty<ProductCategoryNodeInfo>();
|
||||
private ProductGalleryImage? _selectedGalleryImage;
|
||||
private readonly List<BreadcrumbItem> _breadcrumbItems = new();
|
||||
private long TotalPrice => (_product?.Price ?? 0) * _qty;
|
||||
private bool HasDiscount => _product is { Discount: > 0 and < 100 };
|
||||
|
||||
@@ -60,7 +61,7 @@ public partial class ProductDetail : ComponentBase, IDisposable
|
||||
{
|
||||
_galleryItems = Array.Empty<ProductGalleryImage>();
|
||||
_categoryPaths = Array.Empty<ProductCategoryPathInfo>();
|
||||
_breadcrumbNodes = Array.Empty<ProductCategoryNodeInfo>();
|
||||
_breadcrumbItems.Clear();
|
||||
}
|
||||
|
||||
StateHasChanged();
|
||||
@@ -177,9 +178,26 @@ public partial class ProductDetail : ComponentBase, IDisposable
|
||||
|
||||
private void UpdateBreadcrumb()
|
||||
{
|
||||
_breadcrumbNodes = _categoryPaths
|
||||
_breadcrumbItems.Clear();
|
||||
|
||||
if (_product is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_breadcrumbItems.Add(new BreadcrumbItem("خانه", href: RouteConstants.Store.Products));
|
||||
|
||||
var nodes = _categoryPaths
|
||||
.OrderByDescending(path => path.Nodes.Count)
|
||||
.FirstOrDefault()?.Nodes ?? Array.Empty<ProductCategoryNodeInfo>();
|
||||
|
||||
foreach (var node in nodes)
|
||||
{
|
||||
var target = $"{RouteConstants.Store.Products}?category={node.Id}";
|
||||
_breadcrumbItems.Add(new BreadcrumbItem(node.Title, href: target));
|
||||
}
|
||||
|
||||
// _breadcrumbItems.Add(new BreadcrumbItem(_product.Title, href: null, disabled: true));
|
||||
}
|
||||
|
||||
private void NavigateToCategory(ProductCategoryPathInfo path)
|
||||
|
||||
Reference in New Issue
Block a user