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 @@
{#each data.components as comp} + class="group rounded-lg border border-gray-200 bg-white transition-shadow hover:shadow-md dark:border-gray-700 dark:bg-gray-800 overflow-hidden"> + +
+ {#if comp.thumbnail} + {comp.title} + {:else} + + + + {/if} +
+

{comp.title}

@@ -83,6 +94,7 @@ {comp.available} available
+
{/each}