feat: lazy load products in both stores (infinite scroll)
Build and Deploy to Kubernetes / build-and-deploy (push) Has been cancelled

- ProductService: add GetProductsPagedAsync with PaginationState support
- Store/Products: replace load-all with page-by-page lazy loading (12 per page)
- DiscountStore/Products: replace pagination with lazy load (load more button)
- Both stores show 'load more' button + loading indicator + 'all shown' text
This commit is contained in:
masoodafar-web
2026-02-18 01:15:48 +03:30
parent 22203fd8f4
commit bed1ad7c66
5 changed files with 150 additions and 34 deletions
@@ -26,6 +26,13 @@ public record Product(
= [];
}
public record ProductListResult(
List<Product> Products,
int TotalCount,
int TotalPages,
int CurrentPage,
bool HasNext);
public record ProductGalleryImage(
long ProductGalleryId,
long ProductImageId,
@@ -59,11 +66,24 @@ public class ProductService
}
public async Task<List<Product>> GetProductsAsync(string? query = null, long? categoryId = null, string? sortBy = null)
{
var result = await GetProductsPagedAsync(query: query, categoryId: categoryId, sortBy: sortBy, page: 1, pageSize: 500);
return result.Products;
}
public async Task<ProductListResult> GetProductsPagedAsync(
string? query = null, long? categoryId = null, string? sortBy = null,
int page = 1, int pageSize = 12)
{
try
{
var request = new GetAllProductsByFilterRequest
{
PaginationState = new CMSMicroservice.Protobuf.Protos.PaginationState
{
PageNumber = page,
PageSize = pageSize
},
Filter = new GetAllProductsByFilterFilter
{
Title = query ?? string.Empty,
@@ -84,7 +104,12 @@ public class ProductService
}
var resp = await _client.GetAllProductsByFilterAsync(request);
return MapAndCache(resp.Models);
var products = MapAndCache(resp.Models);
var totalCount = (int)(resp.MetaData?.TotalCount ?? 0);
var totalPages = (int)(resp.MetaData?.TotalPage ?? 0);
var hasNext = resp.MetaData?.HasNext ?? false;
return new ProductListResult(products, totalCount, totalPages, page, hasNext);
}
catch
{
@@ -97,7 +122,8 @@ public class ProductService
p.Description.Contains(q, StringComparison.OrdinalIgnoreCase));
}
return list.OrderBy(p => p.Id).ToList();
var all = list.OrderBy(p => p.Id).ToList();
return new ProductListResult(all, all.Count, 1, 1, false);
}
}