mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-23 14:59:36 +02:00
Fix adding to collection to change value of is_public first try
This commit is contained in:
parent
f7c440c364
commit
4c858ab8b5
4 changed files with 23 additions and 76 deletions
|
@ -194,6 +194,10 @@
|
||||||
on:click={() => (window.location.href = 'https://docs.adventurelog.app/')}
|
on:click={() => (window.location.href = 'https://docs.adventurelog.app/')}
|
||||||
>Documentation</button
|
>Documentation</button
|
||||||
>
|
>
|
||||||
|
<button
|
||||||
|
class="btn btn-sm mt-2"
|
||||||
|
on:click={() => (window.location.href = 'https://discord.gg/wRbQ9Egr8C')}>Discord</button
|
||||||
|
>
|
||||||
<p class="font-bold m-4 text-lg">Theme Selection</p>
|
<p class="font-bold m-4 text-lg">Theme Selection</p>
|
||||||
<form method="POST" use:enhance={submitUpdateTheme}>
|
<form method="POST" use:enhance={submitUpdateTheme}>
|
||||||
<li>
|
<li>
|
||||||
|
|
|
@ -99,72 +99,5 @@ export const actions: Actions = {
|
||||||
status: 204
|
status: 204
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
|
||||||
addToCollection: async (event) => {
|
|
||||||
const id = event.params as { id: string };
|
|
||||||
const adventureId = id.id;
|
|
||||||
|
|
||||||
const formData = await event.request.formData();
|
|
||||||
const trip_id = formData.get('collection_id');
|
|
||||||
|
|
||||||
if (!trip_id) {
|
|
||||||
return {
|
|
||||||
status: 400,
|
|
||||||
error: { message: 'Missing collection id' }
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!event.locals.user) {
|
|
||||||
const refresh = event.cookies.get('refresh');
|
|
||||||
let auth = event.cookies.get('auth');
|
|
||||||
if (!refresh) {
|
|
||||||
return {
|
|
||||||
status: 401,
|
|
||||||
body: { message: 'Unauthorized' }
|
|
||||||
};
|
|
||||||
}
|
|
||||||
let res = await tryRefreshToken(refresh);
|
|
||||||
if (res) {
|
|
||||||
auth = res;
|
|
||||||
event.cookies.set('auth', auth, {
|
|
||||||
httpOnly: true,
|
|
||||||
sameSite: 'lax',
|
|
||||||
expires: new Date(Date.now() + 60 * 60 * 1000), // 60 minutes
|
|
||||||
path: '/'
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
return {
|
|
||||||
status: 401,
|
|
||||||
body: { message: 'Unauthorized' }
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!adventureId) {
|
|
||||||
return {
|
|
||||||
status: 400,
|
|
||||||
error: new Error('Bad request')
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
let res = await fetch(`${serverEndpoint}/api/adventures/${event.params.id}/`, {
|
|
||||||
method: 'PATCH',
|
|
||||||
headers: {
|
|
||||||
Cookie: `${event.cookies.get('auth')}`,
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
},
|
|
||||||
body: JSON.stringify({ collection: trip_id })
|
|
||||||
});
|
|
||||||
let res2 = await res.json();
|
|
||||||
console.log(res2);
|
|
||||||
if (!res.ok) {
|
|
||||||
return {
|
|
||||||
status: res.status,
|
|
||||||
error: new Error('Failed to delete adventure')
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
return {
|
|
||||||
status: 204
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -88,16 +88,18 @@
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
let adventure = event.detail;
|
let adventure = event.detail;
|
||||||
let formData = new FormData();
|
|
||||||
formData.append('collection_id', collection.id.toString());
|
|
||||||
|
|
||||||
let res = await fetch(`/adventures/${adventure.id}?/addToCollection`, {
|
let res = await fetch(`/api/adventures/${adventure.id}/`, {
|
||||||
method: 'POST',
|
method: 'PATCH',
|
||||||
body: formData // Remove the Content-Type header
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ collection: collection.id.toString() })
|
||||||
});
|
});
|
||||||
|
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
console.log('Adventure added to collection');
|
console.log('Adventure added to collection');
|
||||||
|
adventure = await res.json();
|
||||||
adventures = [...adventures, adventure];
|
adventures = [...adventures, adventure];
|
||||||
} else {
|
} else {
|
||||||
console.log('Error adding adventure to collection');
|
console.log('Error adding adventure to collection');
|
||||||
|
|
|
@ -6,11 +6,13 @@
|
||||||
console.log(user);
|
console.log(user);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="avatar flex items-center justify-center mt-4">
|
{#if user.profile_pic}
|
||||||
<div class="w-48 rounded-md">
|
<div class="avatar flex items-center justify-center mt-4">
|
||||||
<img src={user.profile_pic} alt={user.username} />
|
<div class="w-48 rounded-md">
|
||||||
|
<img src={user.profile_pic} alt={user.username} />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
{/if}
|
||||||
|
|
||||||
<h1 class="text-center font-semibold text-4xl mt-4">{user.first_name} {user.last_name}</h1>
|
<h1 class="text-center font-semibold text-4xl mt-4">{user.first_name} {user.last_name}</h1>
|
||||||
<h2 class="text-center font-semibold text-2xl">{user.username}</h2>
|
<h2 class="text-center font-semibold text-2xl">{user.username}</h2>
|
||||||
|
@ -21,6 +23,12 @@
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="flex justify-center mt-4">
|
||||||
|
<p class="text-sm text-neutral-content">
|
||||||
|
{user.date_joined ? 'Joined ' + new Date(user.date_joined).toLocaleDateString() : ''}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
<title>{user.username} | AdventureLog</title>
|
<title>{user.username} | AdventureLog</title>
|
||||||
<meta name="description" content="View your adventure collections." />
|
<meta name="description" content="View your adventure collections." />
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue