starting trips

This commit is contained in:
Sean Morley
2024-07-10 13:36:51 -04:00
parent 2d596fb550
commit be9c3c6747
7 changed files with 151 additions and 3 deletions

View File

@@ -80,7 +80,7 @@
</div>
</div>
<h1 class="text-center font-bold text-4xl mb-4">Visited Adventures</h1>
<h1 class="text-center font-bold text-4xl mb-4">Planned Adventures</h1>
<div class="flex flex-wrap gap-4 mr-4 ml-4 justify-center content-center">
{#each adventures as adventure}
<AdventureCard type="planned" {adventure} on:delete={deleteAdventure} on:edit={editAdventure} />

View File

@@ -0,0 +1,30 @@
import { redirect } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
import { PUBLIC_SERVER_URL } from '$env/static/public';
export const load = (async (event) => {
const endpoint = PUBLIC_SERVER_URL || 'http://localhost:8000';
if (!event.locals.user || !event.cookies.get('auth')) {
return redirect(302, '/login');
} else {
let res = await event.fetch(`${endpoint}/api/trips/`, {
headers: {
Cookies: event.cookies.get('auth') || ''
}
});
if (res.ok) {
let data = await res.json();
return {
props: {
trips: data
}
};
} else {
return {
status: res.status,
error: new Error('Failed to fetch data')
};
}
}
return {};
}) satisfies PageServerLoad;

View File

@@ -0,0 +1,53 @@
<script lang="ts">
import type { Trip } from '$lib/types';
import { onMount } from 'svelte';
import type { PageData } from './$types';
import Lost from '$lib/assets/undraw_lost.svg';
import { goto } from '$app/navigation';
import TripCard from '$lib/components/TripCard.svelte';
export let data: PageData;
let trips: Trip[];
let notFound: boolean = false;
onMount(() => {
if (data.props && data.props.trips) {
trips = data.props.trips;
} else {
notFound = true;
}
});
console.log(data);
</script>
{#if notFound}
<div
class="flex min-h-[100dvh] flex-col items-center justify-center bg-background px-4 py-12 sm:px-6 lg:px-8 -mt-20"
>
<div class="mx-auto max-w-md text-center">
<div class="flex items-center justify-center">
<img src={Lost} alt="Lost" class="w-1/2" />
</div>
<h1 class="mt-4 text-3xl font-bold tracking-tight text-foreground sm:text-4xl">
Adventure not Found
</h1>
<p class="mt-4 text-muted-foreground">
The adventure you were looking for could not be found. Please try a different adventure or
check back later.
</p>
<div class="mt-6">
<button class="btn btn-primary" on:click={() => goto('/')}>Homepage</button>
</div>
</div>
</div>
{/if}
{#if trips && !notFound}
<div class="flex flex-wrap gap-4 mr-4 ml-4 justify-center content-center">
{#each trips as trip (trip.id)}
<TripCard {trip} />
{/each}
</div>
{/if}