fixed image and added priority
This commit is contained in:
@@ -3,6 +3,7 @@ export interface Category {
|
|||||||
name: string;
|
name: string;
|
||||||
parentID: number;
|
parentID: number;
|
||||||
icon?: string;
|
icon?: string;
|
||||||
wideBanner?: string;
|
wideBanner?: string | boolean;
|
||||||
itemCount?: number;
|
itemCount?: number;
|
||||||
|
priority?: number;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -130,7 +130,7 @@
|
|||||||
class="dexar-category-card"
|
class="dexar-category-card"
|
||||||
[class.dexar-category-card--wide]="isWideCategory(category.categoryID)">
|
[class.dexar-category-card--wide]="isWideCategory(category.categoryID)">
|
||||||
<div class="dexar-category-image">
|
<div class="dexar-category-image">
|
||||||
@if (isWideCategory(category.categoryID) && category.wideBanner) {
|
@if (isWideCategory(category.categoryID) && category.wideBanner && category.wideBanner !== true) {
|
||||||
<img [src]="category.wideBanner" [alt]="category.name" loading="lazy" decoding="async" />
|
<img [src]="category.wideBanner" [alt]="category.name" loading="lazy" decoding="async" />
|
||||||
} @else if (category.icon) {
|
} @else if (category.icon) {
|
||||||
<img [src]="category.icon" [alt]="category.name" loading="lazy" decoding="async" />
|
<img [src]="category.icon" [alt]="category.name" loading="lazy" decoding="async" />
|
||||||
|
|||||||
@@ -22,7 +22,9 @@ export class HomeComponent implements OnInit {
|
|||||||
|
|
||||||
// Memoized computed values for performance
|
// Memoized computed values for performance
|
||||||
topLevelCategories = computed(() => {
|
topLevelCategories = computed(() => {
|
||||||
return this.categories().filter(cat => cat.parentID === 0);
|
return this.categories()
|
||||||
|
.filter(cat => cat.parentID === 0)
|
||||||
|
.sort((a, b) => (a.priority ?? Infinity) - (b.priority ?? Infinity));
|
||||||
});
|
});
|
||||||
|
|
||||||
// Memoized item count lookup
|
// Memoized item count lookup
|
||||||
@@ -83,8 +85,14 @@ export class HomeComponent implements OnInit {
|
|||||||
private detectWideImages(categories: Category[]): void {
|
private detectWideImages(categories: Category[]): void {
|
||||||
const topLevel = categories.filter(c => c.parentID === 0);
|
const topLevel = categories.filter(c => c.parentID === 0);
|
||||||
topLevel.forEach(cat => {
|
topLevel.forEach(cat => {
|
||||||
const src = cat.wideBanner || null;
|
if (!cat.wideBanner) return;
|
||||||
if (!src) return;
|
|
||||||
|
// API may send wideBanner as a boolean flag instead of a URL
|
||||||
|
if (cat.wideBanner === true) {
|
||||||
|
this.wideCategories.update(set => { const next = new Set(set); next.add(cat.categoryID); return next; });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const img = new Image();
|
const img = new Image();
|
||||||
img.onload = () => {
|
img.onload = () => {
|
||||||
const ratio = img.naturalWidth / img.naturalHeight;
|
const ratio = img.naturalWidth / img.naturalHeight;
|
||||||
@@ -96,7 +104,7 @@ export class HomeComponent implements OnInit {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
img.src = src;
|
img.src = cat.wideBanner as string;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user