From c3e4e695ebe4ef95908fe7fa02d0745d8a302be2 Mon Sep 17 00:00:00 2001 From: sdarbinyan Date: Fri, 6 Mar 2026 17:45:34 +0400 Subject: [PATCH] changes and optimisations --- src/app/pages/cart/cart.component.ts | 6 +- src/app/pages/home/home.component.ts | 17 ++- .../item-detail/item-detail.component.html | 100 +++++++++--------- .../item-detail/item-detail.component.scss | 10 +- .../item-detail/item-detail.component.ts | 11 +- src/app/pages/search/search.component.ts | 2 +- src/app/pipes/lang-route.pipe.ts | 23 ++-- src/app/services/cart.service.ts | 9 +- src/app/services/seo.service.ts | 20 +++- 9 files changed, 129 insertions(+), 69 deletions(-) diff --git a/src/app/pages/cart/cart.component.ts b/src/app/pages/cart/cart.component.ts index df11865..745a5a5 100644 --- a/src/app/pages/cart/cart.component.ts +++ b/src/app/pages/cart/cart.component.ts @@ -167,7 +167,7 @@ export class CartComponent implements OnDestroy { const paymentData = { amount: this.totalPrice(), - currency: 'RUB', + currency: this.items()[0]?.currency || 'RUB', siteuserID: userId, siteorderID: orderId, redirectUrl: '', @@ -193,6 +193,7 @@ export class CartComponent implements OnDestroy { error: (err) => { console.error('Error creating payment:', err); this.paymentStatus.set('timeout'); + if (this.closeTimeout) clearTimeout(this.closeTimeout); this.closeTimeout = setTimeout(() => { this.closePaymentPopup(); }, 4000); @@ -201,6 +202,7 @@ export class CartComponent implements OnDestroy { } startPolling(): void { + this.stopPolling(); this.pollingSubscription = interval(5000) // every 5 seconds .pipe( take(this.maxChecks), // maximum 36 checks (3 minutes) @@ -225,6 +227,7 @@ export class CartComponent implements OnDestroy { if (this.paymentStatus() === 'waiting') { this.paymentStatus.set('timeout'); // Close popup after showing timeout message + if (this.closeTimeout) clearTimeout(this.closeTimeout); this.closeTimeout = setTimeout(() => { this.closePaymentPopup(); }, 3000); @@ -233,6 +236,7 @@ export class CartComponent implements OnDestroy { error: (err) => { console.error('Error checking payment status:', err); // Continue checking even on error until time runs out + if (this.closeTimeout) clearTimeout(this.closeTimeout); this.closeTimeout = setTimeout(() => { this.closePaymentPopup(); }, 3000); diff --git a/src/app/pages/home/home.component.ts b/src/app/pages/home/home.component.ts index c931d09..8cd5b40 100644 --- a/src/app/pages/home/home.component.ts +++ b/src/app/pages/home/home.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit, signal, computed, ChangeDetectionStrategy } from '@angular/core'; +import { Component, OnInit, OnDestroy, signal, computed, ChangeDetectionStrategy } from '@angular/core'; import { Router, RouterLink } from '@angular/router'; import { ApiService, LanguageService } from '../../services'; import { Category } from '../../models'; @@ -14,7 +14,7 @@ import { TranslatePipe } from '../../i18n/translate.pipe'; styleUrls: ['./home.component.scss'], changeDetection: ChangeDetectionStrategy.OnPush }) -export class HomeComponent implements OnInit { +export class HomeComponent implements OnInit, OnDestroy { brandName = environment.brandFullName; isnovo = environment.theme === 'novo'; categories = signal([]); @@ -56,6 +56,14 @@ export class HomeComponent implements OnInit { this.loadCategories(); } + ngOnDestroy(): void { + this.pendingImages.forEach(img => { + img.onload = null; + img.onerror = null; + }); + this.pendingImages.clear(); + } + loadCategories(): void { this.loading.set(true); this.apiService.getCategories().subscribe({ @@ -84,13 +92,17 @@ export class HomeComponent implements OnInit { return this.wideCategories().has(categoryID); } + private pendingImages = new Set(); + private detectWideImages(categories: Category[]): void { const topLevel = categories.filter(c => c.parentID === 0); topLevel.forEach(cat => { if (!cat.wideBanner) return; const img = new Image(); + this.pendingImages.add(img); img.onload = () => { + this.pendingImages.delete(img); const ratio = img.naturalWidth / img.naturalHeight; if (ratio > 2) { this.wideCategories.update(set => { @@ -100,6 +112,7 @@ export class HomeComponent implements OnInit { }); } }; + img.onerror = () => this.pendingImages.delete(img); img.src = cat.wideBanner; }); } diff --git a/src/app/pages/item-detail/item-detail.component.html b/src/app/pages/item-detail/item-detail.component.html index a66bacc..1a94c01 100644 --- a/src/app/pages/item-detail/item-detail.component.html +++ b/src/app/pages/item-detail/item-detail.component.html @@ -15,21 +15,22 @@ } - @if (item() && !loading()) { + @if (item(); as item) { + @if (!loading()) {