optimisation
This commit is contained in:
@@ -12,14 +12,14 @@ export class MockDataService {
|
||||
name: 'dexar',
|
||||
displayName: 'Dexar Marketplace',
|
||||
active: true,
|
||||
logoUrl: 'https://via.placeholder.com/150?text=Dexar'
|
||||
logoUrl: 'https://placehold.co/150?text=Dexar'
|
||||
},
|
||||
{
|
||||
id: 'novo',
|
||||
name: 'novo',
|
||||
displayName: 'Novo Shop',
|
||||
active: true,
|
||||
logoUrl: 'https://via.placeholder.com/150?text=Novo'
|
||||
logoUrl: 'https://placehold.co/150?text=Novo'
|
||||
}
|
||||
];
|
||||
|
||||
@@ -29,7 +29,7 @@ export class MockDataService {
|
||||
name: 'Electronics',
|
||||
visible: true,
|
||||
priority: 1,
|
||||
img: 'https://via.placeholder.com/400x300?text=Electronics',
|
||||
img: 'https://placehold.co/400x300?text=Electronics',
|
||||
projectId: 'dexar',
|
||||
subcategories: [
|
||||
{
|
||||
@@ -37,7 +37,7 @@ export class MockDataService {
|
||||
name: 'Smartphones',
|
||||
visible: true,
|
||||
priority: 1,
|
||||
img: 'https://via.placeholder.com/400x300?text=Smartphones',
|
||||
img: 'https://placehold.co/400x300?text=Smartphones',
|
||||
categoryId: 'cat1',
|
||||
itemCount: 15
|
||||
},
|
||||
@@ -46,7 +46,7 @@ export class MockDataService {
|
||||
name: 'Laptops',
|
||||
visible: true,
|
||||
priority: 2,
|
||||
img: 'https://via.placeholder.com/400x300?text=Laptops',
|
||||
img: 'https://placehold.co/400x300?text=Laptops',
|
||||
categoryId: 'cat1',
|
||||
itemCount: 12
|
||||
}
|
||||
@@ -57,7 +57,7 @@ export class MockDataService {
|
||||
name: 'Clothing',
|
||||
visible: true,
|
||||
priority: 2,
|
||||
img: 'https://via.placeholder.com/400x300?text=Clothing',
|
||||
img: 'https://placehold.co/400x300?text=Clothing',
|
||||
projectId: 'dexar',
|
||||
subcategories: [
|
||||
{
|
||||
@@ -65,7 +65,7 @@ export class MockDataService {
|
||||
name: 'Men',
|
||||
visible: true,
|
||||
priority: 1,
|
||||
img: 'https://via.placeholder.com/400x300?text=Men',
|
||||
img: 'https://placehold.co/400x300?text=Men',
|
||||
categoryId: 'cat2',
|
||||
itemCount: 25
|
||||
}
|
||||
@@ -76,7 +76,7 @@ export class MockDataService {
|
||||
name: 'Home & Garden',
|
||||
visible: false,
|
||||
priority: 3,
|
||||
img: 'https://via.placeholder.com/400x300?text=Home',
|
||||
img: 'https://placehold.co/400x300?text=Home',
|
||||
projectId: 'novo',
|
||||
subcategories: []
|
||||
}
|
||||
@@ -93,8 +93,8 @@ export class MockDataService {
|
||||
discount: 0,
|
||||
currency: 'USD',
|
||||
imgs: [
|
||||
'https://via.placeholder.com/600x400?text=iPhone+Front',
|
||||
'https://via.placeholder.com/600x400?text=iPhone+Back'
|
||||
'https://placehold.co/600x400?text=iPhone+Front',
|
||||
'https://placehold.co/600x400?text=iPhone+Back'
|
||||
],
|
||||
tags: ['new', 'featured', 'bestseller'],
|
||||
badges: ['new', 'featured'],
|
||||
@@ -124,7 +124,7 @@ export class MockDataService {
|
||||
price: 1199,
|
||||
discount: 10,
|
||||
currency: 'USD',
|
||||
imgs: ['https://via.placeholder.com/600x400?text=Samsung+S24'],
|
||||
imgs: ['https://placehold.co/600x400?text=Samsung+S24'],
|
||||
tags: ['new', 'android'],
|
||||
badges: ['new'],
|
||||
simpleDescription: 'Premium Samsung flagship with S Pen',
|
||||
@@ -144,7 +144,7 @@ export class MockDataService {
|
||||
price: 999,
|
||||
discount: 15,
|
||||
currency: 'USD',
|
||||
imgs: ['https://via.placeholder.com/600x400?text=Pixel+8'],
|
||||
imgs: ['https://placehold.co/600x400?text=Pixel+8'],
|
||||
tags: ['sale', 'android', 'ai'],
|
||||
badges: ['sale', 'hot'],
|
||||
simpleDescription: 'Best AI photography phone',
|
||||
@@ -163,7 +163,7 @@ export class MockDataService {
|
||||
price: 2499,
|
||||
discount: 0,
|
||||
currency: 'USD',
|
||||
imgs: ['https://via.placeholder.com/600x400?text=MacBook'],
|
||||
imgs: ['https://placehold.co/600x400?text=MacBook'],
|
||||
tags: ['featured', 'professional'],
|
||||
badges: ['exclusive'],
|
||||
simpleDescription: 'Powerful laptop for professionals',
|
||||
@@ -183,7 +183,7 @@ export class MockDataService {
|
||||
price: 1799,
|
||||
discount: 5,
|
||||
currency: 'USD',
|
||||
imgs: ['https://via.placeholder.com/600x400?text=Dell+XPS'],
|
||||
imgs: ['https://placehold.co/600x400?text=Dell+XPS'],
|
||||
tags: ['out-of-stock'],
|
||||
simpleDescription: 'Premium Windows laptop',
|
||||
description: [
|
||||
@@ -213,7 +213,7 @@ export class MockDataService {
|
||||
price: ((i * 13) % 1000) + 100,
|
||||
discount: i % 3 === 0 ? (i * 5) % 30 + 5 : 0,
|
||||
currency: 'USD',
|
||||
imgs: [`https://via.placeholder.com/600x400?text=Product+${i}`],
|
||||
imgs: [`https://placehold.co/600x400?text=Product+${i}`],
|
||||
tags: ['test'],
|
||||
simpleDescription: `This is test product number ${i}`,
|
||||
description: [{ key: 'Size', value: 'Medium' }],
|
||||
@@ -399,14 +399,26 @@ export class MockDataService {
|
||||
}
|
||||
|
||||
getItem(itemId: string): Observable<Item> {
|
||||
const item = this.items.find(i => i.id === itemId)!;
|
||||
return of(item).pipe(delay(200));
|
||||
let item = this.items.find(i => i.id === itemId);
|
||||
if (!item) {
|
||||
for (const generated of this.generatedItems.values()) {
|
||||
item = generated.find(i => i.id === itemId);
|
||||
if (item) break;
|
||||
}
|
||||
}
|
||||
return of(item!).pipe(delay(200));
|
||||
}
|
||||
|
||||
updateItem(itemId: string, data: Partial<Item>): Observable<Item> {
|
||||
const item = this.items.find(i => i.id === itemId)!;
|
||||
Object.assign(item, data);
|
||||
return of(item).pipe(delay(300));
|
||||
let item = this.items.find(i => i.id === itemId);
|
||||
if (!item) {
|
||||
for (const generated of this.generatedItems.values()) {
|
||||
item = generated.find(i => i.id === itemId);
|
||||
if (item) break;
|
||||
}
|
||||
}
|
||||
if (item) Object.assign(item, data);
|
||||
return of(item!).pipe(delay(300));
|
||||
}
|
||||
|
||||
createItem(subcategoryId: string, data: Partial<Item>): Observable<Item> {
|
||||
@@ -438,7 +450,6 @@ export class MockDataService {
|
||||
}
|
||||
|
||||
deleteItem(itemId: string): Observable<void> {
|
||||
const item = this.items.find(i => i.id === itemId);
|
||||
const index = this.items.findIndex(i => i.id === itemId);
|
||||
if (index > -1) {
|
||||
const subcategoryId = this.items[index].subcategoryId;
|
||||
@@ -452,13 +463,28 @@ export class MockDataService {
|
||||
subcategory.hasItems = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Also remove from generated items cache
|
||||
for (const [key, generated] of this.generatedItems.entries()) {
|
||||
const gi = generated.findIndex(i => i.id === itemId);
|
||||
if (gi > -1) {
|
||||
generated.splice(gi, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return of(void 0).pipe(delay(300));
|
||||
}
|
||||
|
||||
bulkUpdateItems(itemIds: string[], data: Partial<Item>): Observable<void> {
|
||||
itemIds.forEach(id => {
|
||||
const item = this.items.find(i => i.id === id);
|
||||
let item = this.items.find(i => i.id === id);
|
||||
if (!item) {
|
||||
for (const generated of this.generatedItems.values()) {
|
||||
item = generated.find(i => i.id === id);
|
||||
if (item) break;
|
||||
}
|
||||
}
|
||||
if (item) Object.assign(item, data);
|
||||
});
|
||||
return of(void 0).pipe(delay(400));
|
||||
@@ -466,7 +492,7 @@ export class MockDataService {
|
||||
|
||||
uploadImage(file: File): Observable<{ url: string }> {
|
||||
// Simulate upload
|
||||
const url = `https://via.placeholder.com/600x400?text=${encodeURIComponent(file.name)}`;
|
||||
const url = `https://placehold.co/600x400?text=${encodeURIComponent(file.name)}`;
|
||||
return of({ url }).pipe(delay(1000));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user