From 0be2ff8911dd31aae612c878844fe477ebdb0f8c Mon Sep 17 00:00:00 2001 From: Nulo Date: Sun, 22 Sep 2024 18:54:22 -0300 Subject: [PATCH] loading state fixes #60 --- sepa/sitio2/src/lib/components/Loading.svelte | 17 +++++++ .../src/lib/components/SearchBar.svelte | 14 ++++-- .../lib/components/ui/button/button.svelte | 8 +++- .../src/lib/components/ui/button/index.ts | 1 + sepa/sitio2/src/lib/sepa-utils.ts | 11 +++++ .../src/routes/search/[query]/+page.svelte | 33 +------------- .../routes/search/[query]/ProductCard.svelte | 44 +++++++++++++++++++ 7 files changed, 92 insertions(+), 36 deletions(-) create mode 100644 sepa/sitio2/src/lib/components/Loading.svelte create mode 100644 sepa/sitio2/src/routes/search/[query]/ProductCard.svelte diff --git a/sepa/sitio2/src/lib/components/Loading.svelte b/sepa/sitio2/src/lib/components/Loading.svelte new file mode 100644 index 0000000..dfffb4b --- /dev/null +++ b/sepa/sitio2/src/lib/components/Loading.svelte @@ -0,0 +1,17 @@ + + +{#if loading} +
+ +
+ +{:else} + +{/if} diff --git a/sepa/sitio2/src/lib/components/SearchBar.svelte b/sepa/sitio2/src/lib/components/SearchBar.svelte index a58ca8b..b16aec4 100644 --- a/sepa/sitio2/src/lib/components/SearchBar.svelte +++ b/sepa/sitio2/src/lib/components/SearchBar.svelte @@ -1,17 +1,25 @@
- - + +
diff --git a/sepa/sitio2/src/lib/components/ui/button/button.svelte b/sepa/sitio2/src/lib/components/ui/button/button.svelte index f578a57..60cee5d 100644 --- a/sepa/sitio2/src/lib/components/ui/button/button.svelte +++ b/sepa/sitio2/src/lib/components/ui/button/button.svelte @@ -2,6 +2,7 @@ import { Button as ButtonPrimitive } from 'bits-ui'; import { type Events, type Props, buttonVariants } from './index.js'; import { cn } from '$lib/utils.js'; + import Loading from '$lib/components/Loading.svelte'; type $$Props = Props; type $$Events = Events; @@ -10,16 +11,19 @@ export let variant: $$Props['variant'] = 'default'; export let size: $$Props['size'] = 'default'; export let builders: $$Props['builders'] = []; + export let loading = false; export { className as class }; - + + + diff --git a/sepa/sitio2/src/lib/components/ui/button/index.ts b/sepa/sitio2/src/lib/components/ui/button/index.ts index d376139..d6431f3 100644 --- a/sepa/sitio2/src/lib/components/ui/button/index.ts +++ b/sepa/sitio2/src/lib/components/ui/button/index.ts @@ -32,6 +32,7 @@ type Size = VariantProps['size']; type Props = ButtonPrimitive.Props & { variant?: Variant; size?: Size; + loading?: boolean; }; type Events = ButtonPrimitive.Events; diff --git a/sepa/sitio2/src/lib/sepa-utils.ts b/sepa/sitio2/src/lib/sepa-utils.ts index f6a7ba9..40f1a79 100644 --- a/sepa/sitio2/src/lib/sepa-utils.ts +++ b/sepa/sitio2/src/lib/sepa-utils.ts @@ -28,3 +28,14 @@ export const pesosFormatter = new Intl.NumberFormat('es-AR', { style: 'currency', currency: 'ARS' }); + +export function parseMarcas(marcas: readonly string[]) { + const x = marcas + .map((m) => m.trim().replaceAll(/['`´]/g, '')) + .filter((m) => !['sin marca', 'VARIOS'].includes(m)) + .filter((m) => m.length > 0); + if (x.length === 0) { + return ['n/a']; + } + return Array.from(new Set(x)); +} diff --git a/sepa/sitio2/src/routes/search/[query]/+page.svelte b/sepa/sitio2/src/routes/search/[query]/+page.svelte index 786345b..1ee7ae4 100644 --- a/sepa/sitio2/src/routes/search/[query]/+page.svelte +++ b/sepa/sitio2/src/routes/search/[query]/+page.svelte @@ -6,19 +6,9 @@ import { ArrowLeft } from 'lucide-svelte'; import type { PageData } from './$types'; import { goto } from '$app/navigation'; + import ProductCard from './ProductCard.svelte'; export let data: PageData; - - function parseMarcas(marcas: readonly string[]) { - const x = marcas - .map((m) => m.trim().replaceAll(/['`´]/g, '')) - .filter((m) => !['sin marca', 'VARIOS'].includes(m)) - .filter((m) => m.length > 0); - if (x.length === 0) { - return ['n/a']; - } - return Array.from(new Set(x)); - } @@ -39,26 +29,7 @@

{:else} {#each data.collapsedProductos as producto} - - - - {parseMarcas(Array.from(producto.marcas)).join('/')} - en - {producto.in_datasets_count} cadena{#if producto.in_datasets_count > 1}s{/if} - - EAN {producto.id_producto} - - - {#each producto.descriptions as description} - {description} - {#if description !== producto.descriptions[producto.descriptions.length - 1]} - {' '} - {/if} - {/each} - - - + {/each} {/if} diff --git a/sepa/sitio2/src/routes/search/[query]/ProductCard.svelte b/sepa/sitio2/src/routes/search/[query]/ProductCard.svelte new file mode 100644 index 0000000..b57883a --- /dev/null +++ b/sepa/sitio2/src/routes/search/[query]/ProductCard.svelte @@ -0,0 +1,44 @@ + + + + + + + {parseMarcas(Array.from(producto.marcas)).join('/')} + en + {producto.in_datasets_count} cadena{#if producto.in_datasets_count > 1}s{/if} + + EAN {producto.id_producto} + + + {#each producto.descriptions as description} + {description} + {#if description !== producto.descriptions[producto.descriptions.length - 1]} + {' '} + {/if} + {/each} + + + +