Add calendar route and integrate calendar component in Navbar

This commit is contained in:
Sean Morley
2024-12-04 18:11:57 -05:00
parent d44cb06e31
commit 64105808b5
5 changed files with 70 additions and 24 deletions

View File

@@ -0,0 +1,20 @@
import type { Adventure } from '$lib/types';
import type { PageServerLoad } from './$types';
const PUBLIC_SERVER_URL = process.env['PUBLIC_SERVER_URL'];
const endpoint = PUBLIC_SERVER_URL || 'http://localhost:8000';
export const load = (async (event) => {
let sessionId = event.cookies.get('sessionid');
let visitedFetch = await fetch(`${endpoint}/api/adventures/all/?include_collections=true`, {
headers: {
Cookie: `sessionid=${sessionId}`
}
});
let adventures = (await visitedFetch.json()) as Adventure[];
return {
props: {
adventures
}
};
}) satisfies PageServerLoad;

View File

@@ -0,0 +1,42 @@
<script lang="ts">
import type { PageData } from './$types';
// @ts-ignore
import Calendar from '@event-calendar/core';
// @ts-ignore
import TimeGrid from '@event-calendar/time-grid';
// @ts-ignore
import DayGrid from '@event-calendar/day-grid';
export let data: PageData;
let adventures = data.props.adventures;
let dates: Array<{
id: string;
start: string;
end: string;
title: string;
backgroundColor?: string;
}> = [];
adventures.forEach((adventure) => {
adventure.visits.forEach((visit) => {
dates.push({
id: adventure.id,
start: visit.start_date,
end: visit.end_date,
title: adventure.name + ' ' + adventure.category?.icon
});
});
});
let plugins = [TimeGrid, DayGrid];
let options = {
view: 'dayGridMonth',
events: [...dates]
};
</script>
<h1 class="text-center text-2xl font-bold">Adventure Calendar</h1>
<Calendar {plugins} {options} />