Route marketplace data through product facade
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { Component, OnInit, OnDestroy, signal, HostListener, ChangeDetectionStrategy, inject } from '@angular/core';
|
||||
import { DecimalPipe } from '@angular/common';
|
||||
import { ActivatedRoute, RouterLink } from '@angular/router';
|
||||
import { ApiService, CartService } from '../../services';
|
||||
import { CartService } from '../../services';
|
||||
import { PrefetchService } from '../../services/prefetch.service';
|
||||
import { Item } from '../../models';
|
||||
import { Subscription } from 'rxjs';
|
||||
@@ -10,6 +10,7 @@ import { LanguageService } from '../../services/language.service';
|
||||
import { LangRoutePipe } from '../../pipes/lang-route.pipe';
|
||||
import { TranslatePipe } from '../../i18n/translate.pipe';
|
||||
import { SCROLL_THRESHOLD_PX, SCROLL_DEBOUNCE_MS, ITEMS_PER_PAGE } from '../../config/constants';
|
||||
import { ProductFacade } from '../../facades/platform/product.facade';
|
||||
|
||||
@Component({
|
||||
selector: 'app-category',
|
||||
@@ -33,7 +34,7 @@ export class CategoryComponent implements OnInit, OnDestroy {
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private apiService: ApiService,
|
||||
private productFacade: ProductFacade,
|
||||
private cartService: CartService,
|
||||
private prefetchService: PrefetchService
|
||||
) {}
|
||||
@@ -64,8 +65,9 @@ export class CategoryComponent implements OnInit, OnDestroy {
|
||||
this.loading.set(true);
|
||||
this.isLoadingMore = true;
|
||||
|
||||
this.apiService.getCategoryItems(this.categoryID(), this.count, this.skip).subscribe({
|
||||
next: (newItems) => {
|
||||
this.productFacade.getProductsByCategory(this.categoryID(), { count: this.count, skip: this.skip }).subscribe({
|
||||
next: (result) => {
|
||||
const newItems = result.items;
|
||||
// Handle null or empty response
|
||||
if (!newItems || newItems.length === 0) {
|
||||
this.hasMore.set(false);
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
import { Component, OnInit, OnDestroy, signal, ChangeDetectionStrategy, inject } from '@angular/core';
|
||||
import { DecimalPipe } from '@angular/common';
|
||||
import { ActivatedRoute, Router, RouterLink } from '@angular/router';
|
||||
import { ApiService, CartService, LanguageService } from '../../services';
|
||||
import { CartService, LanguageService } from '../../services';
|
||||
import { Category, Item, Subcategory } from '../../models';
|
||||
import { Subscription } from 'rxjs';
|
||||
import { LangRoutePipe } from '../../pipes/lang-route.pipe';
|
||||
import { TranslatePipe } from '../../i18n/translate.pipe';
|
||||
import { TranslateService } from '../../i18n/translate.service';
|
||||
import { getDiscountedPrice, getMainImage, trackByItemId, getBadgeClass, getTranslatedField, getTranslatedCategoryName } from '../../utils/item.utils';
|
||||
import { ProductFacade } from '../../facades/platform/product.facade';
|
||||
|
||||
@Component({
|
||||
selector: 'app-subcategories',
|
||||
@@ -34,7 +35,7 @@ export class SubcategoriesComponent implements OnInit, OnDestroy {
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private apiService: ApiService,
|
||||
private productFacade: ProductFacade,
|
||||
private langService: LanguageService,
|
||||
private cartService: CartService
|
||||
) {}
|
||||
@@ -55,7 +56,7 @@ export class SubcategoriesComponent implements OnInit, OnDestroy {
|
||||
this.categoryItems.set([]);
|
||||
this.nestedSubcategories.set([]);
|
||||
|
||||
this.apiService.getCategories().subscribe({
|
||||
this.productFacade.getCategories().subscribe({
|
||||
next: (cats) => {
|
||||
this.categories.set(cats);
|
||||
const parent = cats.find(c => c.categoryID === parentID);
|
||||
@@ -100,9 +101,9 @@ export class SubcategoriesComponent implements OnInit, OnDestroy {
|
||||
|
||||
/** Load items that belong directly to this category */
|
||||
private loadCategoryItems(categoryID: number): void {
|
||||
this.apiService.getCategoryItems(categoryID, 50, 0).subscribe({
|
||||
next: (items) => {
|
||||
this.categoryItems.set(items);
|
||||
this.productFacade.getProductsByCategory(categoryID, { count: 50, skip: 0 }).subscribe({
|
||||
next: (result) => {
|
||||
this.categoryItems.set(result.items);
|
||||
},
|
||||
error: () => {
|
||||
// Not critical — subcategories still work
|
||||
|
||||
Reference in New Issue
Block a user