Use load fetch instead of window one
All checks were successful
ci/woodpecker/push/build Pipeline was successful
All checks were successful
ci/woodpecker/push/build Pipeline was successful
This commit is contained in:
parent
57736e1d86
commit
edc883d4a8
4 changed files with 22 additions and 14 deletions
|
@ -1,15 +1,10 @@
|
|||
<script lang="ts">
|
||||
import Path from '$lib/components/Path.svelte';
|
||||
// import Splash from '$lib/components/Splash.svelte';
|
||||
|
||||
export let data;
|
||||
let categories: App.Category[] = data.categories;
|
||||
</script>
|
||||
|
||||
|
||||
<!--
|
||||
<Splash />
|
||||
-->
|
||||
<main>
|
||||
<div id="welcome-message">Benvenuti a <span class="bold">Pianello Val Tidone</span></div>
|
||||
<div id="route-cards">
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
|
||||
import { getRouteCategories } from '$lib/repo.js';
|
||||
import { error } from '@sveltejs/kit';
|
||||
import {PUBLIC_BACKEND_URL} from '$env/static/public';
|
||||
|
||||
export async function load() {
|
||||
const API_URL = `${PUBLIC_BACKEND_URL}/api`;
|
||||
|
||||
export async function load({ fetch }) {
|
||||
let categories = [];
|
||||
try {
|
||||
categories = await getRouteCategories();
|
||||
const response = await fetch(`${API_URL}/route-categories`);
|
||||
categories = await response.json();
|
||||
} catch (ex) {
|
||||
error(500);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
import { getRouteByCategory, getRouteCategories } from '$lib/repo.js';
|
||||
import { error } from '@sveltejs/kit';
|
||||
import {PUBLIC_BACKEND_URL} from '$env/static/public';
|
||||
|
||||
export async function load({ params }) {
|
||||
const categories: App.Category[] = await getRouteCategories();
|
||||
const API_URL = `${PUBLIC_BACKEND_URL}/api`;
|
||||
|
||||
export async function load({ params, fetch }) {
|
||||
const response = await fetch(`${API_URL}/route-categories`);
|
||||
const categories: App.Category[] = await response.json();
|
||||
const categoryId = Number(params.slug);
|
||||
|
||||
const category: App.Category = categories.find(c => c.id === categoryId) as App.Category;
|
||||
|
@ -11,9 +15,12 @@ export async function load({ params }) {
|
|||
error(404);
|
||||
}
|
||||
|
||||
const response2 = await fetch(`${API_URL}/route-by-category/${categoryId}`);
|
||||
const routes = await response2.json();
|
||||
|
||||
const toReturn = {
|
||||
category: category.name_it,
|
||||
routes: await getRouteByCategory(categoryId),
|
||||
routes,
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
import { getRoute } from '$lib/repo.js';
|
||||
import { error } from '@sveltejs/kit';
|
||||
import {PUBLIC_BACKEND_URL} from '$env/static/public'
|
||||
|
||||
export async function load({ params }) {
|
||||
const API_URL = `${PUBLIC_BACKEND_URL}/api`
|
||||
|
||||
export async function load({ params, fetch }) {
|
||||
const routeId = Number(params.slug);
|
||||
const route = await getRoute(routeId);
|
||||
const response = await fetch(`${API_URL}/route/${routeId}`);
|
||||
const route = await response.json();
|
||||
|
||||
if (!route) {
|
||||
error(404);
|
||||
|
|
Loading…
Reference in a new issue