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