activity type overhaul

This commit is contained in:
Sean Morley
2024-07-17 22:06:55 -04:00
parent f03c338935
commit f38062e250
6 changed files with 76 additions and 7 deletions

View File

@@ -0,0 +1,26 @@
import { redirect } from '@sveltejs/kit';
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) => {
if (!event.locals.user) {
return redirect(302, '/login');
}
let allActivities: string[] = [];
let res = await fetch(`${endpoint}/api/activity-types/types/`, {
headers: {
'Content-Type': 'application/json',
Cookie: `${event.cookies.get('auth')}`
}
});
let data = await res.json();
if (data) {
allActivities = data;
}
return {
props: {
activities: allActivities
}
};
}) satisfies PageServerLoad;

View File

@@ -0,0 +1,33 @@
<script lang="ts">
import type { PageData } from './$types';
export let data: PageData;
let activities: string[] = data.props.activities;
</script>
<!-- make a table with pinned rows -->
<table class="table table-compact">
<thead>
<tr>
<th>Activity</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{#each activities as activity}
<tr>
<td>{activity}</td>
<td>
<!-- <button
class="btn btn-sm btn-error"
on:click={() => {
activities = activities.filter((a) => a !== activity);
}}>Remove</button
> -->
</td>
</tr>
{/each}
</tbody>
</table>
<!-- </ul> -->

View File

@@ -6,6 +6,10 @@
export let data: PageData;
function deleteAdventure(event: CustomEvent<number>) {
adventures = adventures.filter((adventure) => adventure.id !== event.detail);
}
console.log(data);
let adventures: Adventure[] = [];
if (data.props) {
@@ -18,7 +22,7 @@
{:else}
<div class="flex flex-wrap gap-4 mr-4 justify-center content-center">
{#each adventures as adventure}
<AdventureCard type={adventure.type} {adventure} />
<AdventureCard type={adventure.type} {adventure} on:delete={deleteAdventure} />
{/each}
</div>
{/if}