feat(product-selection): add loading state during product fetch
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
import { Injectable, signal, WritableSignal } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Observable, shareReplay } from 'rxjs';
|
||||
import { delay, Observable, shareReplay } from 'rxjs';
|
||||
import { Product } from '../product-selection/product-selection.component';
|
||||
|
||||
@Injectable({
|
||||
@ -12,7 +12,6 @@ export class ProductService {
|
||||
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
// Local state management
|
||||
setProduct(product: Product | null): void {
|
||||
this.productSignal.set(product);
|
||||
if (product) {
|
||||
@ -32,12 +31,15 @@ export class ProductService {
|
||||
return this.quantitySignal();
|
||||
}
|
||||
|
||||
// API calls
|
||||
getProducts(): Observable<any[]> {
|
||||
return this.http.get<any[]>('https://fakestoreapi.com/products');
|
||||
return this.http.get<any[]>('https://fakestoreapi.com/products').pipe(
|
||||
delay(1000)
|
||||
);
|
||||
}
|
||||
|
||||
getProductById(id: number): Observable<any> {
|
||||
return this.http.get<any>(`https://fakestoreapi.com/products/${id}`);
|
||||
return this.http.get<any>(`https://fakestoreapi.com/products/${id}`).pipe(
|
||||
delay(1000)
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user