mirror of
https://github.com/catdevnull/preciazo.git
synced 2024-11-23 06:36:19 +00:00
productpreview en search
This commit is contained in:
parent
df5b6f3bf8
commit
f20203cac8
3 changed files with 16 additions and 7 deletions
8
sitio/src/lib/ProductPreview.svelte
Normal file
8
sitio/src/lib/ProductPreview.svelte
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<script lang="ts">
|
||||||
|
export let product: { ean: string; name: string; imageUrl: string };
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<a href={`/ean/${product.ean}`} class="flex">
|
||||||
|
<img src={product.imageUrl} alt={product.name} class="max-h-48" />
|
||||||
|
<p class="text-xl">{product.name}</p>
|
||||||
|
</a>
|
|
@ -6,10 +6,12 @@ const { precios } = schema;
|
||||||
|
|
||||||
export const load: PageServerLoad = async ({ url }) => {
|
export const load: PageServerLoad = async ({ url }) => {
|
||||||
const query = url.searchParams.get("q");
|
const query = url.searchParams.get("q");
|
||||||
let results: null | { ean: string; name: string }[] = null;
|
let results: null | { ean: string; name: string; imageUrl: string }[] = null;
|
||||||
if (query) {
|
if (query) {
|
||||||
results = db.all(
|
results = db.all(
|
||||||
sql`select ean, name from precios_fts where name match ${query};`,
|
sql`select p.ean, p.name, p.image_url as imageUrl from precios_fts f
|
||||||
|
join precios p on p.ean = f.ean
|
||||||
|
where f.name match ${query};`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import ProductPreview from "$lib/ProductPreview.svelte";
|
||||||
import type { PageData } from "./$types";
|
import type { PageData } from "./$types";
|
||||||
|
|
||||||
export let data: PageData;
|
export let data: PageData;
|
||||||
|
@ -8,12 +9,10 @@
|
||||||
<header class="my-2">
|
<header class="my-2">
|
||||||
<h1 class="text-2xl font-bold">Resultados para "{data.query}"</h1>
|
<h1 class="text-2xl font-bold">Resultados para "{data.query}"</h1>
|
||||||
</header>
|
</header>
|
||||||
<ul>
|
<ul class="grid grid-cols-1 gap-4 md:grid-cols-2 lg:grid-cols-3">
|
||||||
{#each data.results as result}
|
{#each data.results as product}
|
||||||
<li>
|
<li>
|
||||||
<a href={`/ean/${result.ean}`}>
|
<ProductPreview {product} />
|
||||||
{result.name}
|
|
||||||
</a>
|
|
||||||
</li>
|
</li>
|
||||||
{/each}
|
{/each}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
Loading…
Reference in a new issue