activity type overhaul
This commit is contained in:
26
frontend/src/routes/activities/+page.server.ts
Normal file
26
frontend/src/routes/activities/+page.server.ts
Normal 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;
|
||||
33
frontend/src/routes/activities/+page.svelte
Normal file
33
frontend/src/routes/activities/+page.svelte
Normal 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> -->
|
||||
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user