mirror of
https://github.com/catdevnull/preciazo.git
synced 2024-11-25 19:16:19 +00:00
mejorar diseño
This commit is contained in:
parent
47f4f5fd48
commit
2f6963e5f5
21 changed files with 450 additions and 54 deletions
BIN
sepa/bun.lockb
BIN
sepa/bun.lockb
Binary file not shown.
|
@ -41,6 +41,7 @@
|
|||
"type": "module",
|
||||
"dependencies": {
|
||||
"@types/node": "^22.5.0",
|
||||
"bits-ui": "^0.21.13",
|
||||
"clsx": "^2.1.1",
|
||||
"drizzle-orm": "^0.33.0",
|
||||
"leaflet": "^1.9.4",
|
||||
|
|
17
sepa/sitio2/src/lib/components/SearchBar.svelte
Normal file
17
sepa/sitio2/src/lib/components/SearchBar.svelte
Normal file
|
@ -0,0 +1,17 @@
|
|||
<script lang="ts">
|
||||
import { Input } from '$lib/components/ui/input';
|
||||
import { Button } from '$lib/components/ui/button';
|
||||
import { goto } from '$app/navigation';
|
||||
import { page } from '$app/stores';
|
||||
|
||||
let search = $page.params.query ?? '';
|
||||
|
||||
function handleSubmit() {
|
||||
goto(`/search/${encodeURIComponent(search)}`);
|
||||
}
|
||||
</script>
|
||||
|
||||
<form class="flex gap-2" on:submit|preventDefault={handleSubmit}>
|
||||
<Input placeholder="Buscar productos" bind:value={search} />
|
||||
<Button>Buscar</Button>
|
||||
</form>
|
18
sepa/sitio2/src/lib/components/ui/badge/badge.svelte
Normal file
18
sepa/sitio2/src/lib/components/ui/badge/badge.svelte
Normal file
|
@ -0,0 +1,18 @@
|
|||
<script lang="ts">
|
||||
import { type Variant, badgeVariants } from "./index.js";
|
||||
import { cn } from "$lib/utils.js";
|
||||
|
||||
let className: string | undefined | null = undefined;
|
||||
export let href: string | undefined = undefined;
|
||||
export let variant: Variant = "default";
|
||||
export { className as class };
|
||||
</script>
|
||||
|
||||
<svelte:element
|
||||
this={href ? "a" : "span"}
|
||||
{href}
|
||||
class={cn(badgeVariants({ variant, className }))}
|
||||
{...$$restProps}
|
||||
>
|
||||
<slot />
|
||||
</svelte:element>
|
21
sepa/sitio2/src/lib/components/ui/badge/index.ts
Normal file
21
sepa/sitio2/src/lib/components/ui/badge/index.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
import { type VariantProps, tv } from "tailwind-variants";
|
||||
export { default as Badge } from "./badge.svelte";
|
||||
|
||||
export const badgeVariants = tv({
|
||||
base: "focus:ring-ring inline-flex select-none items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-offset-2",
|
||||
variants: {
|
||||
variant: {
|
||||
default: "bg-primary text-primary-foreground hover:bg-primary/80 border-transparent",
|
||||
secondary:
|
||||
"bg-secondary text-secondary-foreground hover:bg-secondary/80 border-transparent",
|
||||
destructive:
|
||||
"bg-destructive text-destructive-foreground hover:bg-destructive/80 border-transparent",
|
||||
outline: "text-foreground",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
},
|
||||
});
|
||||
|
||||
export type Variant = VariantProps<typeof badgeVariants>["variant"];
|
25
sepa/sitio2/src/lib/components/ui/button/button.svelte
Normal file
25
sepa/sitio2/src/lib/components/ui/button/button.svelte
Normal file
|
@ -0,0 +1,25 @@
|
|||
<script lang="ts">
|
||||
import { Button as ButtonPrimitive } from "bits-ui";
|
||||
import { type Events, type Props, buttonVariants } from "./index.js";
|
||||
import { cn } from "$lib/utils.js";
|
||||
|
||||
type $$Props = Props;
|
||||
type $$Events = Events;
|
||||
|
||||
let className: $$Props["class"] = undefined;
|
||||
export let variant: $$Props["variant"] = "default";
|
||||
export let size: $$Props["size"] = "default";
|
||||
export let builders: $$Props["builders"] = [];
|
||||
export { className as class };
|
||||
</script>
|
||||
|
||||
<ButtonPrimitive.Root
|
||||
{builders}
|
||||
class={cn(buttonVariants({ variant, size, className }))}
|
||||
type="button"
|
||||
{...$$restProps}
|
||||
on:click
|
||||
on:keydown
|
||||
>
|
||||
<slot />
|
||||
</ButtonPrimitive.Root>
|
49
sepa/sitio2/src/lib/components/ui/button/index.ts
Normal file
49
sepa/sitio2/src/lib/components/ui/button/index.ts
Normal file
|
@ -0,0 +1,49 @@
|
|||
import { type VariantProps, tv } from "tailwind-variants";
|
||||
import type { Button as ButtonPrimitive } from "bits-ui";
|
||||
import Root from "./button.svelte";
|
||||
|
||||
const buttonVariants = tv({
|
||||
base: "ring-offset-background focus-visible:ring-ring inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
|
||||
variants: {
|
||||
variant: {
|
||||
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
||||
destructive: "bg-destructive text-destructive-foreground hover:bg-destructive/90",
|
||||
outline:
|
||||
"border-input bg-background hover:bg-accent hover:text-accent-foreground border",
|
||||
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
||||
ghost: "hover:bg-accent hover:text-accent-foreground",
|
||||
link: "text-primary underline-offset-4 hover:underline",
|
||||
},
|
||||
size: {
|
||||
default: "h-10 px-4 py-2",
|
||||
sm: "h-9 rounded-md px-3",
|
||||
lg: "h-11 rounded-md px-8",
|
||||
icon: "h-10 w-10",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
size: "default",
|
||||
},
|
||||
});
|
||||
|
||||
type Variant = VariantProps<typeof buttonVariants>["variant"];
|
||||
type Size = VariantProps<typeof buttonVariants>["size"];
|
||||
|
||||
type Props = ButtonPrimitive.Props & {
|
||||
variant?: Variant;
|
||||
size?: Size;
|
||||
};
|
||||
|
||||
type Events = ButtonPrimitive.Events;
|
||||
|
||||
export {
|
||||
Root,
|
||||
type Props,
|
||||
type Events,
|
||||
//
|
||||
Root as Button,
|
||||
type Props as ButtonProps,
|
||||
type Events as ButtonEvents,
|
||||
buttonVariants,
|
||||
};
|
13
sepa/sitio2/src/lib/components/ui/card/card-content.svelte
Normal file
13
sepa/sitio2/src/lib/components/ui/card/card-content.svelte
Normal file
|
@ -0,0 +1,13 @@
|
|||
<script lang="ts">
|
||||
import type { HTMLAttributes } from "svelte/elements";
|
||||
import { cn } from "$lib/utils.js";
|
||||
|
||||
type $$Props = HTMLAttributes<HTMLDivElement>;
|
||||
|
||||
let className: $$Props["class"] = undefined;
|
||||
export { className as class };
|
||||
</script>
|
||||
|
||||
<div class={cn("p-6 pt-0", className)} {...$$restProps}>
|
||||
<slot />
|
||||
</div>
|
|
@ -0,0 +1,13 @@
|
|||
<script lang="ts">
|
||||
import type { HTMLAttributes } from "svelte/elements";
|
||||
import { cn } from "$lib/utils.js";
|
||||
|
||||
type $$Props = HTMLAttributes<HTMLParagraphElement>;
|
||||
|
||||
let className: $$Props["class"] = undefined;
|
||||
export { className as class };
|
||||
</script>
|
||||
|
||||
<p class={cn("text-muted-foreground text-sm", className)} {...$$restProps}>
|
||||
<slot />
|
||||
</p>
|
13
sepa/sitio2/src/lib/components/ui/card/card-footer.svelte
Normal file
13
sepa/sitio2/src/lib/components/ui/card/card-footer.svelte
Normal file
|
@ -0,0 +1,13 @@
|
|||
<script lang="ts">
|
||||
import type { HTMLAttributes } from "svelte/elements";
|
||||
import { cn } from "$lib/utils.js";
|
||||
|
||||
type $$Props = HTMLAttributes<HTMLDivElement>;
|
||||
|
||||
let className: $$Props["class"] = undefined;
|
||||
export { className as class };
|
||||
</script>
|
||||
|
||||
<div class={cn("flex items-center p-6 pt-0", className)} {...$$restProps}>
|
||||
<slot />
|
||||
</div>
|
13
sepa/sitio2/src/lib/components/ui/card/card-header.svelte
Normal file
13
sepa/sitio2/src/lib/components/ui/card/card-header.svelte
Normal file
|
@ -0,0 +1,13 @@
|
|||
<script lang="ts">
|
||||
import type { HTMLAttributes } from "svelte/elements";
|
||||
import { cn } from "$lib/utils.js";
|
||||
|
||||
type $$Props = HTMLAttributes<HTMLDivElement>;
|
||||
|
||||
let className: $$Props["class"] = undefined;
|
||||
export { className as class };
|
||||
</script>
|
||||
|
||||
<div class={cn("flex flex-col space-y-1.5 p-6", className)} {...$$restProps}>
|
||||
<slot />
|
||||
</div>
|
21
sepa/sitio2/src/lib/components/ui/card/card-title.svelte
Normal file
21
sepa/sitio2/src/lib/components/ui/card/card-title.svelte
Normal file
|
@ -0,0 +1,21 @@
|
|||
<script lang="ts">
|
||||
import type { HTMLAttributes } from "svelte/elements";
|
||||
import type { HeadingLevel } from "./index.js";
|
||||
import { cn } from "$lib/utils.js";
|
||||
|
||||
type $$Props = HTMLAttributes<HTMLHeadingElement> & {
|
||||
tag?: HeadingLevel;
|
||||
};
|
||||
|
||||
let className: $$Props["class"] = undefined;
|
||||
export let tag: $$Props["tag"] = "h3";
|
||||
export { className as class };
|
||||
</script>
|
||||
|
||||
<svelte:element
|
||||
this={tag}
|
||||
class={cn("text-lg font-semibold leading-none tracking-tight", className)}
|
||||
{...$$restProps}
|
||||
>
|
||||
<slot />
|
||||
</svelte:element>
|
16
sepa/sitio2/src/lib/components/ui/card/card.svelte
Normal file
16
sepa/sitio2/src/lib/components/ui/card/card.svelte
Normal file
|
@ -0,0 +1,16 @@
|
|||
<script lang="ts">
|
||||
import type { HTMLAttributes } from "svelte/elements";
|
||||
import { cn } from "$lib/utils.js";
|
||||
|
||||
type $$Props = HTMLAttributes<HTMLDivElement>;
|
||||
|
||||
let className: $$Props["class"] = undefined;
|
||||
export { className as class };
|
||||
</script>
|
||||
|
||||
<div
|
||||
class={cn("bg-card text-card-foreground rounded-lg border shadow-sm", className)}
|
||||
{...$$restProps}
|
||||
>
|
||||
<slot />
|
||||
</div>
|
24
sepa/sitio2/src/lib/components/ui/card/index.ts
Normal file
24
sepa/sitio2/src/lib/components/ui/card/index.ts
Normal file
|
@ -0,0 +1,24 @@
|
|||
import Root from "./card.svelte";
|
||||
import Content from "./card-content.svelte";
|
||||
import Description from "./card-description.svelte";
|
||||
import Footer from "./card-footer.svelte";
|
||||
import Header from "./card-header.svelte";
|
||||
import Title from "./card-title.svelte";
|
||||
|
||||
export {
|
||||
Root,
|
||||
Content,
|
||||
Description,
|
||||
Footer,
|
||||
Header,
|
||||
Title,
|
||||
//
|
||||
Root as Card,
|
||||
Content as CardContent,
|
||||
Description as CardDescription,
|
||||
Footer as CardFooter,
|
||||
Header as CardHeader,
|
||||
Title as CardTitle,
|
||||
};
|
||||
|
||||
export type HeadingLevel = "h1" | "h2" | "h3" | "h4" | "h5" | "h6";
|
29
sepa/sitio2/src/lib/components/ui/input/index.ts
Normal file
29
sepa/sitio2/src/lib/components/ui/input/index.ts
Normal file
|
@ -0,0 +1,29 @@
|
|||
import Root from "./input.svelte";
|
||||
|
||||
export type FormInputEvent<T extends Event = Event> = T & {
|
||||
currentTarget: EventTarget & HTMLInputElement;
|
||||
};
|
||||
export type InputEvents = {
|
||||
blur: FormInputEvent<FocusEvent>;
|
||||
change: FormInputEvent<Event>;
|
||||
click: FormInputEvent<MouseEvent>;
|
||||
focus: FormInputEvent<FocusEvent>;
|
||||
focusin: FormInputEvent<FocusEvent>;
|
||||
focusout: FormInputEvent<FocusEvent>;
|
||||
keydown: FormInputEvent<KeyboardEvent>;
|
||||
keypress: FormInputEvent<KeyboardEvent>;
|
||||
keyup: FormInputEvent<KeyboardEvent>;
|
||||
mouseover: FormInputEvent<MouseEvent>;
|
||||
mouseenter: FormInputEvent<MouseEvent>;
|
||||
mouseleave: FormInputEvent<MouseEvent>;
|
||||
mousemove: FormInputEvent<MouseEvent>;
|
||||
paste: FormInputEvent<ClipboardEvent>;
|
||||
input: FormInputEvent<InputEvent>;
|
||||
wheel: FormInputEvent<WheelEvent>;
|
||||
};
|
||||
|
||||
export {
|
||||
Root,
|
||||
//
|
||||
Root as Input,
|
||||
};
|
42
sepa/sitio2/src/lib/components/ui/input/input.svelte
Normal file
42
sepa/sitio2/src/lib/components/ui/input/input.svelte
Normal file
|
@ -0,0 +1,42 @@
|
|||
<script lang="ts">
|
||||
import type { HTMLInputAttributes } from "svelte/elements";
|
||||
import type { InputEvents } from "./index.js";
|
||||
import { cn } from "$lib/utils.js";
|
||||
|
||||
type $$Props = HTMLInputAttributes;
|
||||
type $$Events = InputEvents;
|
||||
|
||||
let className: $$Props["class"] = undefined;
|
||||
export let value: $$Props["value"] = undefined;
|
||||
export { className as class };
|
||||
|
||||
// Workaround for https://github.com/sveltejs/svelte/issues/9305
|
||||
// Fixed in Svelte 5, but not backported to 4.x.
|
||||
export let readonly: $$Props["readonly"] = undefined;
|
||||
</script>
|
||||
|
||||
<input
|
||||
class={cn(
|
||||
"border-input bg-background ring-offset-background placeholder:text-muted-foreground focus-visible:ring-ring flex h-10 w-full rounded-md border px-3 py-2 text-sm file:border-0 file:bg-transparent file:text-sm file:font-medium focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
|
||||
className
|
||||
)}
|
||||
bind:value
|
||||
{readonly}
|
||||
on:blur
|
||||
on:change
|
||||
on:click
|
||||
on:focus
|
||||
on:focusin
|
||||
on:focusout
|
||||
on:keydown
|
||||
on:keypress
|
||||
on:keyup
|
||||
on:mouseover
|
||||
on:mouseenter
|
||||
on:mouseleave
|
||||
on:mousemove
|
||||
on:paste
|
||||
on:input
|
||||
on:wheel|passive
|
||||
{...$$restProps}
|
||||
/>
|
|
@ -1,5 +1,16 @@
|
|||
<script>
|
||||
// import { cubicIn, cubicOut } from 'svelte/easing';
|
||||
import '../app.css';
|
||||
// import { fly } from 'svelte/transition';
|
||||
|
||||
export let data;
|
||||
</script>
|
||||
|
||||
<slot></slot>
|
||||
<!-- {#key data.pathname}
|
||||
<div
|
||||
in:fly={{ easing: cubicOut, x: 10, duration: 150, delay: 300 }}
|
||||
out:fly={{ easing: cubicIn, x: -10, duration: 150 }}
|
||||
> -->
|
||||
<slot />
|
||||
<!-- </div>
|
||||
{/key} -->
|
||||
|
|
7
sepa/sitio2/src/routes/+layout.ts
Normal file
7
sepa/sitio2/src/routes/+layout.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
export const load = ({ url }) => {
|
||||
const { pathname } = url;
|
||||
|
||||
return {
|
||||
pathname
|
||||
};
|
||||
};
|
|
@ -1,10 +1,18 @@
|
|||
<script lang="ts">
|
||||
import SearchBar from '$lib/components/SearchBar.svelte';
|
||||
import type { PageData } from './$types';
|
||||
|
||||
const numberFormat = new Intl.NumberFormat('es-AR', {
|
||||
style: 'decimal'
|
||||
});
|
||||
|
||||
export let data: PageData;
|
||||
</script>
|
||||
|
||||
<div class="mx-auto max-w-screen-sm p-4">
|
||||
<h1 class="flex text-3xl font-bold">
|
||||
preciazo<small class="text-xs">alpha</small>
|
||||
</h1>
|
||||
<h2>actualmente tengo {data.count} registros de precios</h2>
|
||||
<h2>¡actualmente tengo {numberFormat.format(data.count)} registros de precios!</h2>
|
||||
<SearchBar />
|
||||
</div>
|
||||
|
|
|
@ -3,7 +3,6 @@ import { sql } from 'drizzle-orm';
|
|||
import type { PageServerLoad } from './$types';
|
||||
|
||||
export const load: PageServerLoad = async ({ params }) => {
|
||||
|
||||
// const latestDatasetsSq = db.$with('latest_datasets').as(
|
||||
// db.select({
|
||||
// id: datasets.id,
|
||||
|
@ -18,11 +17,13 @@ export const load: PageServerLoad = async ({ params }) => {
|
|||
// ))
|
||||
|
||||
const query = params.query;
|
||||
const productos = await db.execute(sql`
|
||||
SELECT id_producto, productos_descripcion, productos_marca
|
||||
FROM productos_descripcion_index index
|
||||
WHERE productos_descripcion ILIKE ${`%${query}%`}
|
||||
ORDER BY
|
||||
const productos = await db.execute<{
|
||||
id_producto: string;
|
||||
productos_descripcion: string;
|
||||
productos_marca: string;
|
||||
in_datasets_count: number;
|
||||
}>(sql`
|
||||
SELECT id_producto, productos_descripcion, productos_marca,
|
||||
(WITH latest_datasets AS (
|
||||
SELECT d1.id
|
||||
FROM datasets d1
|
||||
|
@ -34,8 +35,40 @@ export const load: PageServerLoad = async ({ params }) => {
|
|||
)SELECT COUNT(DISTINCT p.id_dataset) as dataset_count
|
||||
FROM precios p
|
||||
JOIN latest_datasets ld ON p.id_dataset = ld.id
|
||||
WHERE p.id_producto = index.id_producto) desc
|
||||
`)
|
||||
WHERE p.id_producto = index.id_producto) as in_datasets_count
|
||||
FROM productos_descripcion_index index
|
||||
WHERE productos_descripcion ILIKE ${`%${query}%`}
|
||||
ORDER BY in_datasets_count desc
|
||||
LIMIT 100
|
||||
`);
|
||||
const collapsedProductos = productos.reduce(
|
||||
(acc, producto) => {
|
||||
const existingProduct = acc.find((p) => p.id_producto === producto.id_producto);
|
||||
if (existingProduct) {
|
||||
existingProduct.descriptions.push(producto.productos_descripcion);
|
||||
existingProduct.marcas.add(producto.productos_marca);
|
||||
existingProduct.in_datasets_count = Math.max(
|
||||
existingProduct.in_datasets_count,
|
||||
producto.in_datasets_count
|
||||
);
|
||||
} else {
|
||||
acc.push({
|
||||
id_producto: producto.id_producto,
|
||||
descriptions: [producto.productos_descripcion],
|
||||
marcas: new Set([producto.productos_marca]),
|
||||
in_datasets_count: producto.in_datasets_count
|
||||
});
|
||||
}
|
||||
return acc;
|
||||
},
|
||||
[] as Array<{
|
||||
id_producto: string;
|
||||
descriptions: string[];
|
||||
marcas: Set<string>;
|
||||
in_datasets_count: number;
|
||||
}>
|
||||
);
|
||||
|
||||
// 'latest_datasets',
|
||||
// sql`
|
||||
// WITH latest_datasets AS (
|
||||
|
@ -68,7 +101,7 @@ WHERE p.id_producto = index.id_producto) desc
|
|||
// FROM precios p
|
||||
// JOIN latest_datasets ld ON p.id_dataset = ld.id
|
||||
// WHERE p.id_producto = ${productos_descripcion_index.id_producto}`);
|
||||
return { productos };
|
||||
return { productos, collapsedProductos, query };
|
||||
// const precios = await sql<
|
||||
// {
|
||||
// id_producto: string;
|
||||
|
|
|
@ -1,15 +1,37 @@
|
|||
<script lang="ts">
|
||||
import SearchBar from '$lib/components/SearchBar.svelte';
|
||||
import Badge from '$lib/components/ui/badge/badge.svelte';
|
||||
import * as Card from '$lib/components/ui/card/index.js';
|
||||
import type { PageData } from './$types';
|
||||
|
||||
export let data: PageData;
|
||||
</script>
|
||||
|
||||
<ul>
|
||||
{#each data.productos as producto}
|
||||
<li>
|
||||
<a href={`/id_producto/${producto.id_producto}`}
|
||||
>{producto.productos_marca} - {producto.productos_descripcion}</a
|
||||
<div class="mx-auto max-w-screen-sm p-4">
|
||||
<SearchBar />
|
||||
<h1 class="my-2 text-2xl font-bold">Resultados para "{data.query}"</h1>
|
||||
{#each data.collapsedProductos as producto}
|
||||
<a href={`/id_producto/${producto.id_producto}`} class="my-2 block">
|
||||
<Card.Root class="transition-colors duration-200 hover:bg-gray-100">
|
||||
<Card.Header class="block px-3 py-2 pb-0">
|
||||
<Badge
|
||||
>{Array.from(producto.marcas)
|
||||
.filter((m) => !['sin marca', 'VARIOS'].includes(m))
|
||||
.filter((m) => m?.trim().length > 0)
|
||||
.join('/')}</Badge
|
||||
>
|
||||
</li>
|
||||
<Badge variant="outline">en {producto.in_datasets_count} cadenas</Badge>
|
||||
<Badge variant="outline">EAN {producto.id_producto}</Badge>
|
||||
</Card.Header>
|
||||
<Card.Content class="px-3 py-2">
|
||||
{#each producto.descriptions as description}
|
||||
<span>{description}</span>
|
||||
{#if description !== producto.descriptions[producto.descriptions.length - 1]}
|
||||
<span class="text-gray-500">⋅</span>{' '}
|
||||
{/if}
|
||||
{/each}
|
||||
</ul>
|
||||
</Card.Content>
|
||||
</Card.Root>
|
||||
</a>
|
||||
{/each}
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue