1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-07-19 21:09:37 +02:00

Fix collection link

This commit is contained in:
Sean Morley 2024-08-11 13:34:32 -04:00
parent cd55437f91
commit 5aef1eb8bd
3 changed files with 16 additions and 14 deletions

View file

@ -10,6 +10,8 @@
let adventures: Adventure[] = []; let adventures: Adventure[] = [];
let isLoading: boolean = true;
export let user: User | null; export let user: User | null;
onMount(async () => { onMount(async () => {
@ -17,19 +19,16 @@
if (modal) { if (modal) {
modal.showModal(); modal.showModal();
} }
let formData = new FormData(); let res = await fetch(`/api/adventures/all/?include_collections=false`, {
formData.append('include_collections', 'false'); method: 'GET'
let res = await fetch(`/adventures?/all`, {
method: 'POST',
body: formData
}); });
const result: ActionResult = deserialize(await res.text()); const newAdventures = await res.json();
console.log(result);
if (result.type === 'success' && result.data) { if (res.ok && adventures) {
adventures = result.data.adventures as Adventure[]; adventures = newAdventures;
} }
isLoading = false;
}); });
function close() { function close() {
@ -53,11 +52,16 @@
<!-- svelte-ignore a11y-no-noninteractive-tabindex --> <!-- svelte-ignore a11y-no-noninteractive-tabindex -->
<div class="modal-box w-11/12 max-w-5xl" role="dialog" on:keydown={handleKeydown} tabindex="0"> <div class="modal-box w-11/12 max-w-5xl" role="dialog" on:keydown={handleKeydown} tabindex="0">
<h1 class="text-center font-bold text-4xl mb-6">My Adventures</h1> <h1 class="text-center font-bold text-4xl mb-6">My Adventures</h1>
{#if isLoading}
<div class="flex justify-center items-center w-full mt-16">
<span class="loading loading-spinner w-24 h-24"></span>
</div>
{/if}
<div class="flex flex-wrap gap-4 mr-4 justify-center content-center"> <div class="flex flex-wrap gap-4 mr-4 justify-center content-center">
{#each adventures as adventure} {#each adventures as adventure}
<AdventureCard user={user ?? null} type="link" {adventure} on:link={add} /> <AdventureCard user={user ?? null} type="link" {adventure} on:link={add} />
{/each} {/each}
{#if adventures.length === 0} {#if adventures.length === 0 && !isLoading}
<p class="text-center text-lg"> <p class="text-center text-lg">
No adventures found that can be linked to this collection. No adventures found that can be linked to this collection.
</p> </p>

View file

@ -146,15 +146,13 @@ export const actions: Actions = {
}; };
} }
let trip_id_number: number = parseInt(trip_id as string);
let res = await fetch(`${serverEndpoint}/api/adventures/${event.params.id}/`, { let res = await fetch(`${serverEndpoint}/api/adventures/${event.params.id}/`, {
method: 'PATCH', method: 'PATCH',
headers: { headers: {
Cookie: `${event.cookies.get('auth')}`, Cookie: `${event.cookies.get('auth')}`,
'Content-Type': 'application/json' 'Content-Type': 'application/json'
}, },
body: JSON.stringify({ collection: trip_id_number }) body: JSON.stringify({ collection: trip_id })
}); });
let res2 = await res.json(); let res2 = await res.json();
console.log(res2); console.log(res2);

View file

@ -171,7 +171,7 @@
<span class="text-sm text-muted-foreground">{adventure.location}</span> <span class="text-sm text-muted-foreground">{adventure.location}</span>
</div> </div>
{/if} {/if}
{#if adventure.activity_types} {#if adventure.activity_types && adventure.activity_types?.length > 0}
<div class="flex items-center gap-2"> <div class="flex items-center gap-2">
<svg <svg
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"