migration to new backend

This commit is contained in:
Sean Morley
2024-07-08 11:44:39 -04:00
parent 28a5d423c2
commit 9abe9fb315
309 changed files with 21476 additions and 24132 deletions

View File

@@ -0,0 +1,38 @@
import { redirect } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
const PUBLIC_SERVER_URL = process.env['PUBLIC_SERVER_URL'];
import type { Adventure } from '$lib/types';
const endpoint = PUBLIC_SERVER_URL || 'http://localhost:8000';
export const load = (async (event) => {
if (!event.locals.user) {
return redirect(302, '/login');
} else {
let visitedFetch = await fetch(`${endpoint}/api/adventures/`, {
headers: {
Cookie: `${event.cookies.get('auth')}`
}
});
if (!visitedFetch.ok) {
console.error('Failed to fetch visited adventures');
return redirect(302, '/login');
} else {
let visited = (await visitedFetch.json()) as Adventure[];
console.log('VISITEDL ' + visited);
// make a long lat array like this { lngLat: [-20, 0], name: 'Adventure 1' },
let markers = visited
.filter((adventure) => adventure.latitude !== null && adventure.longitude !== null)
.map((adventure) => {
return {
lngLat: [adventure.longitude, adventure.latitude] as [number, number],
name: adventure.name
};
});
return {
props: {
markers
}
};
}
}
}) satisfies PageServerLoad;

View File

@@ -0,0 +1,31 @@
<script>
// @ts-nocheck
import { DefaultMarker, MapEvents, MapLibre, Popup } from 'svelte-maplibre';
export let data;
let markers = data.props.markers;
console.log(markers);
</script>
<MapLibre
style="https://basemaps.cartocdn.com/gl/voyager-gl-style/style.json"
class="relative aspect-[9/16] max-h-[70vh] w-full sm:aspect-video sm:max-h-full"
standardControls
>
{#each data.props.markers as { lngLat, name }}
<!-- Unlike the custom marker example, default markers do not have mouse events,
and popups only support the default openOn="click" behavior -->
<DefaultMarker {lngLat}>
<Popup offset={[0, -10]}>
<div class="text-lg font-bold">{name}</div>
</Popup>
</DefaultMarker>
{/each}
</MapLibre>
<style>
:global(.map) {
height: 500px;
}
</style>