fixed image and added priority

This commit is contained in:
sdarbinyan
2026-02-20 00:44:44 +04:00
parent 18df968b7a
commit 2baa72a022
3 changed files with 15 additions and 6 deletions

View File

@@ -3,6 +3,7 @@ export interface Category {
name: string;
parentID: number;
icon?: string;
wideBanner?: string;
wideBanner?: string | boolean;
itemCount?: number;
priority?: number;
}

View File

@@ -130,7 +130,7 @@
class="dexar-category-card"
[class.dexar-category-card--wide]="isWideCategory(category.categoryID)">
<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" />
} @else if (category.icon) {
<img [src]="category.icon" [alt]="category.name" loading="lazy" decoding="async" />

View File

@@ -22,7 +22,9 @@ export class HomeComponent implements OnInit {
// Memoized computed values for performance
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
@@ -83,8 +85,14 @@ export class HomeComponent implements OnInit {
private detectWideImages(categories: Category[]): void {
const topLevel = categories.filter(c => c.parentID === 0);
topLevel.forEach(cat => {
const src = cat.wideBanner || null;
if (!src) return;
if (!cat.wideBanner) 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();
img.onload = () => {
const ratio = img.naturalWidth / img.naturalHeight;
@@ -96,7 +104,7 @@ export class HomeComponent implements OnInit {
});
}
};
img.src = src;
img.src = cat.wideBanner as string;
});
}