1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-07-24 23:39:37 +02:00

refactor: Add additional attributions to AboutModal and filter adventures based on user ID in +page.svelte

This commit is contained in:
Sean Morley 2024-08-01 09:38:02 -04:00
parent 06df5d370d
commit 0685065bf6
2 changed files with 38 additions and 8 deletions

View file

@ -64,6 +64,7 @@
class="text-primary-500 underline"
href="https://operations.osmfoundation.org/policies/nominatim/">OpenStreepMap</a
>. Their data is liscensed under the ODbL liscense.
<br /> Additional attributions can be found in the README file.
</p>
<button class="btn btn-primary" on:click={close}>Close</button>

View file

@ -10,11 +10,12 @@
export let data: PageData;
function deleteAdventure(event: CustomEvent<number>) {
adventures = adventures.filter((adventure) => adventure.id !== event.detail);
myAdventures = myAdventures.filter((adventure) => adventure.id !== event.detail);
}
let osmResults: OpenStreetMapPlace[] = [];
let adventures: Adventure[] = [];
let myAdventures: Adventure[] = [];
let publicAdventures: Adventure[] = [];
let query: string | null = '';
@ -48,7 +49,16 @@
console.log(data);
if (data.props) {
adventures = data.props.adventures;
myAdventures = data.props.adventures;
publicAdventures = data.props.adventures;
if (data.user?.pk != null) {
myAdventures = myAdventures.filter((adventure) => adventure.user_id === data.user?.pk ?? -1);
} else {
myAdventures = [];
}
publicAdventures = publicAdventures.filter((adventure) => adventure.user_id !== data.user?.pk);
}
let adventureToEdit: Adventure;
@ -61,7 +71,7 @@
}
function saveEdit(event: CustomEvent<Adventure>) {
adventures = adventures.map((adventure) => {
myAdventures = myAdventures.map((adventure) => {
if (adventure.id === event.detail.id) {
return event.detail;
}
@ -79,14 +89,18 @@
/>
{/if}
{#if adventures.length === 0 && osmResults.length === 0}
{#if myAdventures.length === 0 && osmResults.length === 0}
<NotFound error={data.error} />
{/if}
{#if adventures.length > 0}
{#if myAdventures.length !== 0 && publicAdventures.length !== 0}
<h2 class="text-center font-bold text-2xl mb-4">AdventureLog Results</h2>
{/if}
{#if myAdventures.length > 0}
<h2 class="text-center font-bold text-2xl mb-4">My Adventures</h2>
<div class="flex flex-wrap gap-4 mr-4 justify-center content-center">
{#each adventures as adventure}
{#each myAdventures as adventure}
<AdventureCard
user={data.user}
type={adventure.type}
@ -97,7 +111,22 @@
{/each}
</div>
{/if}
{#if adventures.length > 0 && osmResults.length > 0}
{#if publicAdventures.length > 0}
<h2 class="text-center font-bold text-2xl mb-4">Public Adventures</h2>
<div class="flex flex-wrap gap-4 mr-4 justify-center content-center">
{#each publicAdventures as adventure}
<AdventureCard
user={null}
type={adventure.type}
{adventure}
on:delete={deleteAdventure}
on:edit={editAdventure}
/>
{/each}
</div>
{/if}
{#if myAdventures.length > 0 && osmResults.length > 0 && publicAdventures.length > 0}
<div class="divider"></div>
{/if}
{#if osmResults.length > 0}