From 3a3781ba7a009cb842fd08669b4c7b0fb67786f1 Mon Sep 17 00:00:00 2001 From: grabowski Date: Thu, 9 Apr 2026 17:04:18 +0700 Subject: [PATCH] Show thumbnails on component list cards Component cards now display the first uploaded image as a thumbnail, matching the device list card design. Falls back to a placeholder icon when no image is uploaded. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/routes/(app)/components/+page.server.ts | 24 +++++++++++++++++++-- src/routes/(app)/components/+page.svelte | 14 +++++++++++- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/routes/(app)/components/+page.server.ts b/src/routes/(app)/components/+page.server.ts index 43ac77e..caf219d 100644 --- a/src/routes/(app)/components/+page.server.ts +++ b/src/routes/(app)/components/+page.server.ts @@ -1,7 +1,7 @@ import type { PageServerLoad } from './$types'; import { db } from '$lib/server/db/index.js'; -import { components, componentInstances, devices } from '$lib/server/db/schema.js'; -import { eq, ilike, or, and, isNull, isNotNull, count, desc, sql } from 'drizzle-orm'; +import { components, componentInstances, componentImages } from '$lib/server/db/schema.js'; +import { eq, ilike, or, and, count, sql } from 'drizzle-orm'; export const load: PageServerLoad = async ({ url }) => { const type = url.searchParams.get('type'); @@ -60,9 +60,29 @@ export const load: PageServerLoad = async ({ url }) => { } } + // Get first image per component + let imageMap: Record = {}; + if (componentIds.length > 0) { + const images = await db + .select({ + componentId: componentImages.componentId, + thumbnailPath: componentImages.thumbnailPath, + filePath: componentImages.filePath + }) + .from(componentImages) + .where(sql`${componentImages.componentId} IN ${componentIds}`); + + for (const img of images) { + if (!imageMap[img.componentId]) { + imageMap[img.componentId] = img.thumbnailPath ?? img.filePath; + } + } + } + return { components: componentList.map((c) => ({ ...c, + thumbnail: imageMap[c.id] ?? null, total: instanceCounts[c.id]?.total ?? 0, installed: instanceCounts[c.id]?.installed ?? 0, available: (instanceCounts[c.id]?.total ?? 0) - (instanceCounts[c.id]?.installed ?? 0) diff --git a/src/routes/(app)/components/+page.svelte b/src/routes/(app)/components/+page.svelte index d78f807..9bcf5b9 100644 --- a/src/routes/(app)/components/+page.svelte +++ b/src/routes/(app)/components/+page.svelte @@ -61,7 +61,18 @@