improvments are done
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Component, OnInit, signal } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { Component, OnInit, signal, ChangeDetectionStrategy } from '@angular/core';
|
||||
import { DecimalPipe } from '@angular/common';
|
||||
import { RouterLink } from '@angular/router';
|
||||
import { CarouselModule } from 'primeng/carousel';
|
||||
import { ButtonModule } from 'primeng/button';
|
||||
@@ -7,13 +7,14 @@ import { TagModule } from 'primeng/tag';
|
||||
import { ApiService, CartService } from '../../services';
|
||||
import { Item } from '../../models';
|
||||
import { environment } from '../../../environments/environment';
|
||||
import { getDiscountedPrice, getMainImage } from '../../utils/item.utils';
|
||||
|
||||
@Component({
|
||||
selector: 'app-items-carousel',
|
||||
templateUrl: './items-carousel.component.html',
|
||||
standalone: true,
|
||||
imports: [CommonModule, RouterLink, CarouselModule, ButtonModule, TagModule],
|
||||
styleUrls: ['./items-carousel.component.scss']
|
||||
imports: [DecimalPipe, RouterLink, CarouselModule, ButtonModule, TagModule],
|
||||
styleUrls: ['./items-carousel.component.scss'],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush
|
||||
})
|
||||
export class ItemsCarouselComponent implements OnInit {
|
||||
products = signal<Item[]>([]);
|
||||
@@ -93,19 +94,8 @@ export class ItemsCarouselComponent implements OnInit {
|
||||
}
|
||||
}
|
||||
|
||||
getItemImage(item: Item): string {
|
||||
if (item.photos && item.photos.length > 0 && item.photos[0]?.url) {
|
||||
return item.photos[0].url;
|
||||
}
|
||||
return '/assets/images/placeholder.jpg';
|
||||
}
|
||||
|
||||
getDiscountedPrice(item: Item): number {
|
||||
if (item.discount > 0) {
|
||||
return item.price * (1 - item.discount / 100);
|
||||
}
|
||||
return item.price;
|
||||
}
|
||||
readonly getItemImage = getMainImage;
|
||||
readonly getDiscountedPrice = getDiscountedPrice;
|
||||
|
||||
addToCart(event: Event, item: Item): void {
|
||||
event.preventDefault();
|
||||
|
||||
Reference in New Issue
Block a user