fix DI errors and stabilize static page navigation
This commit is contained in:
@@ -24,11 +24,11 @@ export class ItemsCarouselComponent implements OnInit {
|
||||
products = signal<Item[]>([]);
|
||||
loading = signal(true);
|
||||
private readonly uiRuntime = inject(UiRuntimeFacade);
|
||||
private readonly productFacade = inject(ProductFacade);
|
||||
|
||||
responsiveOptions: { breakpoint: string; numVisible: number; numScroll: number }[] | undefined;
|
||||
|
||||
constructor(
|
||||
private productFacade: ProductFacade,
|
||||
private cartService: CartService
|
||||
) {}
|
||||
|
||||
|
||||
@@ -1,70 +1,48 @@
|
||||
import { Injectable, signal } from '@angular/core';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { ProductDataService } from '../../core/products/product-data.service';
|
||||
import { Product, ProductCategory, ProductListQuery, ProductListResult, ProductSearchQuery, RelatedProductsQuery } from '../../core/products/models/product-domain.model';
|
||||
import {
|
||||
Product,
|
||||
ProductCategory,
|
||||
ProductListQuery,
|
||||
ProductListResult,
|
||||
ProductSearchQuery,
|
||||
RelatedProductsQuery,
|
||||
} from '../../core/products/models/product-domain.model';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class ProductFacade {
|
||||
readonly categories = signal<ProductCategory[]>([]);
|
||||
readonly products = signal<Product[]>([]);
|
||||
readonly selectedProduct = signal<Product | null>(null);
|
||||
readonly relatedProducts = signal<Product[]>([]);
|
||||
readonly total = signal(0);
|
||||
readonly loading = signal(false);
|
||||
readonly error = signal<string | null>(null);
|
||||
constructor(private readonly productData: ProductDataService) {}
|
||||
|
||||
constructor(private readonly productData: ProductDataService) {}
|
||||
getProducts(query?: ProductListQuery): Observable<ProductListResult> {
|
||||
return this.productData.getProducts(query);
|
||||
}
|
||||
|
||||
loadCategories(): void {
|
||||
this.loading.set(true);
|
||||
this.error.set(null);
|
||||
getProduct(productID: number): Observable<Product> {
|
||||
return this.productData.getProduct(productID);
|
||||
}
|
||||
|
||||
this.productData.getCategories().subscribe({
|
||||
next: (categories) => {
|
||||
this.categories.set(categories);
|
||||
this.loading.set(false);
|
||||
},
|
||||
error: () => {
|
||||
this.categories.set([]);
|
||||
this.error.set('Failed to load categories');
|
||||
this.loading.set(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
getCategories(): Observable<ProductCategory[]> {
|
||||
return this.productData.getCategories();
|
||||
}
|
||||
|
||||
getCategories() {
|
||||
return this.productData.getCategories();
|
||||
}
|
||||
searchProducts(query: ProductSearchQuery): Observable<ProductListResult> {
|
||||
return this.productData.searchProducts(query);
|
||||
}
|
||||
|
||||
getProducts(query?: ProductListQuery) {
|
||||
return this.productData.getProducts(query);
|
||||
}
|
||||
getFeaturedProducts(query?: ProductListQuery): Observable<ProductListResult> {
|
||||
return this.productData.getFeaturedProducts(query);
|
||||
}
|
||||
|
||||
getProduct(productID: number) {
|
||||
return this.productData.getProduct(productID);
|
||||
}
|
||||
getLatestProducts(query?: ProductListQuery): Observable<ProductListResult> {
|
||||
return this.productData.getLatestProducts(query);
|
||||
}
|
||||
|
||||
searchProducts(query: ProductSearchQuery) {
|
||||
return this.productData.searchProducts(query);
|
||||
}
|
||||
getProductsByCategory(categoryID: number, query?: ProductListQuery): Observable<ProductListResult> {
|
||||
return this.productData.getProductsByCategory(categoryID, query);
|
||||
}
|
||||
|
||||
getFeaturedProducts(query?: ProductListQuery) {
|
||||
return this.productData.getFeaturedProducts(query);
|
||||
}
|
||||
|
||||
getLatestProducts(query?: ProductListQuery) {
|
||||
return this.productData.getLatestProducts(query);
|
||||
}
|
||||
|
||||
getProductsByCategory(categoryID: number, query?: ProductListQuery) {
|
||||
return this.productData.getProductsByCategory(categoryID, query);
|
||||
}
|
||||
|
||||
getRelatedProducts(query: RelatedProductsQuery) {
|
||||
return this.productData.getRelatedProducts(query);
|
||||
}
|
||||
|
||||
setListResult(result: ProductListResult): void {
|
||||
this.products.set(result.items);
|
||||
this.total.set(result.total);
|
||||
}
|
||||
getRelatedProducts(query: RelatedProductsQuery): Observable<ProductListResult> {
|
||||
return this.productData.getRelatedProducts(query);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,10 +31,10 @@ export class CategoryComponent implements OnInit, OnDestroy {
|
||||
private isLoadingMore = false;
|
||||
private routeSubscription?: Subscription;
|
||||
private scrollTimeout?: ReturnType<typeof setTimeout>;
|
||||
private readonly productFacade = inject(ProductFacade);
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private productFacade: ProductFacade,
|
||||
private cartService: CartService,
|
||||
private prefetchService: PrefetchService
|
||||
) {}
|
||||
|
||||
@@ -27,6 +27,7 @@ export class SubcategoriesComponent implements OnInit, OnDestroy {
|
||||
error = signal<string | null>(null);
|
||||
|
||||
private i18n = inject(TranslateService);
|
||||
private readonly productFacade = inject(ProductFacade);
|
||||
parentName = signal<string>('');
|
||||
|
||||
private routeSubscription?: Subscription;
|
||||
@@ -35,7 +36,6 @@ export class SubcategoriesComponent implements OnInit, OnDestroy {
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private categoryFacade: CategoryFacade,
|
||||
private productFacade: ProductFacade,
|
||||
private langService: LanguageService,
|
||||
private cartService: CartService
|
||||
) {}
|
||||
|
||||
@@ -107,11 +107,11 @@ export class ItemDetailComponent implements OnInit, OnDestroy {
|
||||
private seoService = inject(SeoService);
|
||||
private i18n = inject(TranslateService);
|
||||
private authService = inject(AuthService);
|
||||
private readonly productFacade = inject(ProductFacade);
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private apiService: ApiService,
|
||||
private productFacade: ProductFacade,
|
||||
private cartService: CartService,
|
||||
private telegramService: TelegramService,
|
||||
private sanitizer: DomSanitizer,
|
||||
|
||||
@@ -35,9 +35,9 @@ export class SearchComponent implements OnDestroy {
|
||||
private searchSubject = new Subject<string>();
|
||||
private searchSubscription: Subscription;
|
||||
private i18n = inject(TranslateService);
|
||||
private readonly productFacade = inject(ProductFacade);
|
||||
|
||||
constructor(
|
||||
private productFacade: ProductFacade,
|
||||
private cartService: CartService,
|
||||
private prefetchService: PrefetchService
|
||||
) {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<section class="static-page__state">
|
||||
<h1>404</h1>
|
||||
<p>Страница не найдена</p>
|
||||
<a [routerLink]="'/' | langRoute">На главную</a>
|
||||
<a [routerLink]="homeRoute()">На главную</a>
|
||||
</section>
|
||||
} @else {
|
||||
<article class="static-page__content">
|
||||
|
||||
@@ -5,12 +5,11 @@ import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
|
||||
import { StaticPageResolverService } from '../../core/config/static-page-resolver.service';
|
||||
import { LanguageService } from '../../services/language.service';
|
||||
import { TranslatePipe } from '../../i18n/translate.pipe';
|
||||
import { LangRoutePipe } from '../../pipes/lang-route.pipe';
|
||||
|
||||
@Component({
|
||||
selector: 'app-static-page',
|
||||
standalone: true,
|
||||
imports: [CommonModule, RouterLink, TranslatePipe, LangRoutePipe],
|
||||
imports: [CommonModule, RouterLink, TranslatePipe],
|
||||
templateUrl: './static-page.component.html',
|
||||
styleUrls: ['./static-page.component.scss'],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush
|
||||
@@ -24,9 +23,12 @@ export class StaticPageComponent {
|
||||
readonly loading = signal(true);
|
||||
readonly notFound = signal(false);
|
||||
readonly title = signal('');
|
||||
readonly homeRoute = signal('');
|
||||
readonly safeHtml = signal<SafeHtml>(this.sanitizer.bypassSecurityTrustHtml(''));
|
||||
|
||||
constructor() {
|
||||
this.homeRoute.set(`/${this.languageService.currentLanguage()}`);
|
||||
|
||||
this.route.paramMap.subscribe(params => {
|
||||
const keyFromParam = params.get('key');
|
||||
const staticPath = params.get('staticPath');
|
||||
|
||||
Reference in New Issue
Block a user