arreglar types productpreview

This commit is contained in:
Cat /dev/Nulo 2024-01-04 19:45:56 -03:00
parent 16a51e41b1
commit f089ff5047
2 changed files with 9 additions and 3 deletions

View file

@ -1,8 +1,10 @@
<script lang="ts"> <script lang="ts">
export let product: { ean: string; name: string; imageUrl: string }; export let product: { ean: string; name: string; imageUrl?: string | null };
</script> </script>
<a href={`/ean/${product.ean}`} class="flex"> <a href={`/ean/${product.ean}`} class="flex">
{#if product.imageUrl}
<img src={product.imageUrl} alt={product.name} class="max-h-48" /> <img src={product.imageUrl} alt={product.name} class="max-h-48" />
{/if}
<p class="text-xl">{product.name}</p> <p class="text-xl">{product.name}</p>
</a> </a>

View file

@ -3,6 +3,10 @@
import type { PageData } from "./$types"; import type { PageData } from "./$types";
export let data: PageData; export let data: PageData;
$: precios = data.precios.filter(
(d): d is { ean: string; name: string; imageUrl: string | null } =>
!!d.name,
);
</script> </script>
<h1 class="text-xl">WIP</h1> <h1 class="text-xl">WIP</h1>
@ -32,7 +36,7 @@
<section> <section>
<h2 class="text-lg font-bold">Random</h2> <h2 class="text-lg font-bold">Random</h2>
<ul class="grid grid-cols-1 gap-4 md:grid-cols-2 lg:grid-cols-3"> <ul class="grid grid-cols-1 gap-4 md:grid-cols-2 lg:grid-cols-3">
{#each data.precios as product} {#each precios as product}
<li> <li>
<ProductPreview {product} /> <ProductPreview {product} />
</li> </li>