mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-08-05 05:05:17 +02:00
feat: enhance CategoryModal with loading state and remove unused activities route
This commit is contained in:
parent
64d2bdebce
commit
f9cf92041d
4 changed files with 25 additions and 109 deletions
|
@ -1,51 +0,0 @@
|
|||
import { redirect, type Actions } from '@sveltejs/kit';
|
||||
import type { PageServerLoad } from './$types';
|
||||
import { fetchCSRFToken } from '$lib/index.server';
|
||||
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 csrfToken = await fetchCSRFToken();
|
||||
let allActivities: string[] = [];
|
||||
let res = await event.fetch(`${endpoint}/api/activity-types/types/`, {
|
||||
headers: {
|
||||
'X-CSRFToken': csrfToken,
|
||||
Cookie: `csrftoken=${csrfToken}`
|
||||
},
|
||||
credentials: 'include'
|
||||
});
|
||||
console.log(res);
|
||||
let data = await res.json();
|
||||
if (data) {
|
||||
allActivities = data;
|
||||
}
|
||||
return {
|
||||
props: {
|
||||
activities: allActivities
|
||||
}
|
||||
};
|
||||
}) satisfies PageServerLoad;
|
||||
|
||||
export const actions: Actions = {
|
||||
getActivities: async (event) => {
|
||||
let csrfToken = await fetchCSRFToken();
|
||||
let allActivities: string[] = [];
|
||||
let res = await fetch(`${endpoint}/api/activity-types/types/`, {
|
||||
headers: {
|
||||
'X-CSRFToken': csrfToken,
|
||||
'Content-Type': 'application/json',
|
||||
Cookie: `csrftoken=${csrfToken}`,
|
||||
Referer: event.url.origin // Include Referer header
|
||||
}
|
||||
});
|
||||
console.log(res);
|
||||
let data = await res.json();
|
||||
if (data) {
|
||||
allActivities = data;
|
||||
}
|
||||
return { activities: allActivities };
|
||||
}
|
||||
};
|
|
@ -1,38 +0,0 @@
|
|||
<script lang="ts">
|
||||
import { goto } from '$app/navigation';
|
||||
import type { PageData } from './$types';
|
||||
import { t } from 'svelte-i18n';
|
||||
|
||||
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>{$t('navbar.tag')}</th>
|
||||
<th>{$t('adventures.actions')}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each activities as activity}
|
||||
<tr>
|
||||
<td>{activity}</td>
|
||||
<td>
|
||||
<button
|
||||
class="btn btn-sm btn-primary"
|
||||
on:click={() => goto(`/search?query=${activity}&property=activity_types`)}
|
||||
>{$t('adventures.see_adventures')}</button
|
||||
>
|
||||
</td>
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<svelte:head>
|
||||
<title>My Tags</title>
|
||||
<meta name="description" content="View my tags." />
|
||||
</svelte:head>
|
|
@ -58,8 +58,6 @@
|
|||
console.error(`Error processing GPX file ${gpxfile}:`, error);
|
||||
}
|
||||
}
|
||||
|
||||
// Log the final GeoJSON for debugging
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue