improve navigation

This commit is contained in:
Cat /dev/Nulo 2024-09-22 19:01:16 -03:00
parent 8ed967209f
commit 1cc14d0a0b
4 changed files with 27 additions and 5 deletions

View file

@ -3,10 +3,13 @@
import { ArrowLeft } from 'lucide-svelte';
import Map from '$lib/components/Map.svelte';
import Badge from '$lib/components/ui/badge/badge.svelte';
import {} from '$app/navigation';
import { goto } from '$app/navigation';
import { generateGoogleMapsLink, pesosFormatter, processBanderaNombre } from '$lib/sepa-utils';
import { page } from '$app/stores';
export let data: PageData;
const query = $page.url.searchParams.get('query');
</script>
<svelte:head>
@ -15,7 +18,12 @@
<div class="flex min-h-screen flex-col">
<div class="max-w-screen flex items-stretch gap-3 overflow-hidden px-2">
<button on:click={() => window.history.back()}>
<button
on:click={() =>
goto(
`/search/${encodeURIComponent(query ?? data.precios[0].productos_descripcion ?? $page.params.id)}`
)}
>
<ArrowLeft class="size-8 flex-shrink-0" />
</button>
<div class="flex flex-wrap items-center gap-x-2 overflow-hidden p-1">

View file

@ -8,6 +8,8 @@
import { MapPin } from 'lucide-svelte';
import Button from '$lib/components/ui/button/button.svelte';
import { es } from 'date-fns/locale';
import { goto } from '$app/navigation';
import { page } from '$app/stores';
export let data: PageData;
@ -23,7 +25,15 @@
<div>
<div class="max-w-screen flex items-stretch gap-3 overflow-hidden px-2">
<button on:click={() => window.history.back()}>
<button
on:click={() => {
if (history.length > 1) {
history.back();
} else {
goto(`/id_producto/${$page.params.id}`);
}
}}
>
<ArrowLeft class="size-8 flex-shrink-0" />
</button>
<div class="flex flex-wrap items-center gap-x-2 overflow-hidden p-1">

View file

@ -27,7 +27,7 @@
</p>
{:else}
{#each data.collapsedProductos as producto}
<ProductCard {producto} />
<ProductCard {producto} query={data.query} />
{/each}
{/if}
</div>

View file

@ -11,6 +11,7 @@
in_datasets_count: number;
descriptions: string[];
};
export let query: string | undefined;
let loading = false;
beforeNavigate((x) => {
@ -20,7 +21,10 @@
});
</script>
<a href={`/id_producto/${producto.id_producto}`} class="my-2 block">
<a
href={`/id_producto/${producto.id_producto}?query=${encodeURIComponent(query ?? producto.descriptions[0])}`}
class="my-2 block"
>
<Card.Root class="relative transition-colors duration-200 hover:bg-gray-100">
<Loading {loading}>
<Card.Header class="block px-3 py-2 pb-0">