Add paths implementation
Some checks failed
ci/woodpecker/push/build Pipeline failed

This commit is contained in:
Alessio Davoli 2023-11-27 06:10:06 +01:00
parent b3fb6e46aa
commit c65a0c1c54
6 changed files with 38 additions and 30 deletions

12
frontend/src/app.d.ts vendored
View file

@ -6,7 +6,17 @@ declare global {
// interface Locals {} // interface Locals {}
// interface PageData {} // interface PageData {}
// interface Platform {} // interface Platform {}
interface Category {
"id": 1,
"name_it": "Natura",
"name_en": "Nature",
"description_it": "Giri nella natura",
"description_en": "Countryside routes",
"icon": "",
"created_at": null,
"updated_at": null,
"deleted_at": null
}
interface Sport { interface Sport {
"id": 1, "id": 1,
"name_it": "Trekking", "name_it": "Trekking",

View file

@ -1,15 +0,0 @@
import { error } from "@sveltejs/kit";
export async function load({ params }) {
return {
title: params.slug,
routes: [
{id: 1, name: 'Pianello 1', image: '/images/test-1.jpg', duration: 1233},
{id: 2, name: 'Pianello 2', image: '/images/test-1.jpg', duration: 1233},
{id: 3, name: 'Pianello 3', image: '/images/test-1.jpg', duration: 2134},
{id: 4, name: 'Pianello 4', image: '/images/test-1.jpg', duration: 2134 * 4},
{id: 5, name: 'Pianello 5', image: '/images/test-1.jpg', duration: 2134 * 4},
]
}
}

View file

@ -1,22 +1,14 @@
<script lang="ts"> <script lang="ts">
import Route from '$lib/components/Route.svelte'; import Route from '$lib/components/Route.svelte';
import HomeHeader from '$lib/components/HomeHeader.svelte'; import HomeHeader from '$lib/components/HomeHeader.svelte';
import { onMount } from 'svelte';
import { getRouteByCategory } from '$lib/repo';
let id = 0; export let data;
let routes = [];
onMount(async () => {
id = Number(window.location.href.split('paths/')[1]);
routes = await getRouteByCategory(id);
})
</script> </script>
<!-- <HomeHeader title={data.category}></HomeHeader>
<HomeHeader title={title}></HomeHeader>-->
<div> <div>
{#each routes as route} {#each data.routes as route}
<Route {route}></Route> <Route {route}></Route>
{/each} {/each}
</div> </div>

View file

@ -0,0 +1,19 @@
import { getRouteByCategory, getRouteCategories } from '$lib/repo.js';
import { error } from '@sveltejs/kit';
/** @type {import('./$types').PageLoad} */
export async function load({ params }) {
const categories: App.Category[] = await getRouteCategories();
const categoryId = Number(params.slug);
const category: App.Category = categories.find(c => c.id === categoryId);
if (!category) {
error(404);
}
return {
category: category.name_it,
routes: await getRouteByCategory(categoryId),
}
}

View file

@ -6,6 +6,8 @@
export let data: App.Route; export let data: App.Route;
let divider; let divider;
const mapClick = () => {};
</script> </script>
<Header></Header> <Header></Header>
@ -14,7 +16,7 @@
<div bind:this={divider} id="divider"> <div bind:this={divider} id="divider">
<div id="banner"> <div id="banner">
<p>Percorso <b>{data.name_it}</b></p> <p>Percorso <b>{data.name_it}</b></p>
<p id="duration">Dislivello {data.elevation_gain}</p> <p id="duration">Dislivello {data.route_sport_details[0].elevation_gain} m</p>
</div> </div>
<Tabs on:map-click={mapClick} route={data}></Tabs> <Tabs on:map-click={mapClick} route={data}></Tabs>
</div> </div>

View file

@ -1,7 +1,7 @@
import { getRoute } from '$lib/repo.js'; import { getRouteByCategory } from '$lib/repo.js';
import { error } from '@sveltejs/kit'; import { error } from '@sveltejs/kit';
/** @type {import('./$types').PageLoad} */ /** @type {import('./$types').PageLoad} */
export async function load({ params }) { export async function load({ params }) {
return await getRoute(params.slug); return await getRouteByCategory(params.slug);
} }