2024-07-17 17:36:05 -04:00
|
|
|
<script lang="ts">
|
|
|
|
import AdventureCard from '$lib/components/AdventureCard.svelte';
|
|
|
|
import NotFound from '$lib/components/NotFound.svelte';
|
2024-07-18 15:48:14 -04:00
|
|
|
import type { Adventure, OpenStreetMapPlace } from '$lib/types';
|
|
|
|
import { onMount } from 'svelte';
|
2024-07-17 17:36:05 -04:00
|
|
|
import type { PageData } from './$types';
|
2024-08-17 22:40:27 -04:00
|
|
|
import EditAdventure from '$lib/components/AdventureModal.svelte';
|
2024-07-22 10:56:18 -04:00
|
|
|
import { appVersion } from '$lib/config';
|
2024-08-04 21:50:15 -04:00
|
|
|
import { goto } from '$app/navigation';
|
2024-08-17 22:40:27 -04:00
|
|
|
import AdventureModal from '$lib/components/AdventureModal.svelte';
|
2024-07-17 17:36:05 -04:00
|
|
|
|
|
|
|
export let data: PageData;
|
|
|
|
|
2024-08-13 12:03:18 -04:00
|
|
|
function deleteAdventure(event: CustomEvent<string>) {
|
2024-08-01 09:38:02 -04:00
|
|
|
myAdventures = myAdventures.filter((adventure) => adventure.id !== event.detail);
|
2024-07-17 22:06:55 -04:00
|
|
|
}
|
|
|
|
|
2024-07-18 15:48:14 -04:00
|
|
|
let osmResults: OpenStreetMapPlace[] = [];
|
2024-08-01 09:38:02 -04:00
|
|
|
let myAdventures: Adventure[] = [];
|
|
|
|
let publicAdventures: Adventure[] = [];
|
2024-07-18 15:48:14 -04:00
|
|
|
|
|
|
|
let query: string | null = '';
|
2024-08-01 10:02:00 -04:00
|
|
|
let property: string = 'all';
|
|
|
|
|
|
|
|
// on chage of property, console log the property
|
|
|
|
|
|
|
|
function filterByProperty() {
|
|
|
|
let url = new URL(window.location.href);
|
|
|
|
url.searchParams.set('property', property);
|
|
|
|
goto(url.toString(), { invalidateAll: true });
|
|
|
|
}
|
2024-07-18 15:48:14 -04:00
|
|
|
|
|
|
|
onMount(() => {
|
|
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
|
|
query = urlParams.get('query');
|
|
|
|
});
|
|
|
|
|
2024-07-17 17:36:05 -04:00
|
|
|
console.log(data);
|
2024-08-01 10:02:00 -04:00
|
|
|
$: {
|
|
|
|
if (data.props) {
|
|
|
|
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 = [];
|
|
|
|
}
|
2024-07-20 08:39:32 -04:00
|
|
|
|
2024-08-01 10:02:00 -04:00
|
|
|
publicAdventures = publicAdventures.filter(
|
|
|
|
(adventure) => adventure.user_id !== data.user?.pk
|
|
|
|
);
|
2024-08-14 22:17:43 -04:00
|
|
|
|
|
|
|
if (data.props.osmData) {
|
|
|
|
osmResults = data.props.osmData;
|
|
|
|
}
|
2024-08-01 09:38:02 -04:00
|
|
|
}
|
2024-07-17 17:36:05 -04:00
|
|
|
}
|
2024-07-22 10:08:42 -04:00
|
|
|
|
|
|
|
let adventureToEdit: Adventure;
|
2024-08-17 22:40:27 -04:00
|
|
|
let isAdventureModalOpen: boolean = false;
|
2024-07-22 10:08:42 -04:00
|
|
|
|
|
|
|
function editAdventure(event: CustomEvent<Adventure>) {
|
|
|
|
adventureToEdit = event.detail;
|
2024-08-17 22:40:27 -04:00
|
|
|
isAdventureModalOpen = true;
|
2024-07-22 10:08:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function saveEdit(event: CustomEvent<Adventure>) {
|
2024-08-17 22:40:27 -04:00
|
|
|
console.log(event.detail);
|
2024-08-01 09:38:02 -04:00
|
|
|
myAdventures = myAdventures.map((adventure) => {
|
2024-07-22 10:08:42 -04:00
|
|
|
if (adventure.id === event.detail.id) {
|
|
|
|
return event.detail;
|
|
|
|
}
|
|
|
|
return adventure;
|
|
|
|
});
|
2024-08-17 22:40:27 -04:00
|
|
|
isAdventureModalOpen = false;
|
|
|
|
console.log(myAdventures);
|
2024-07-22 10:08:42 -04:00
|
|
|
}
|
2024-07-17 17:36:05 -04:00
|
|
|
</script>
|
|
|
|
|
2024-08-17 22:40:27 -04:00
|
|
|
{#if isAdventureModalOpen}
|
|
|
|
<AdventureModal
|
2024-07-22 10:08:42 -04:00
|
|
|
{adventureToEdit}
|
2024-08-17 22:40:27 -04:00
|
|
|
on:close={() => (isAdventureModalOpen = false)}
|
|
|
|
on:save={filterByProperty}
|
2024-07-22 10:08:42 -04:00
|
|
|
/>
|
|
|
|
{/if}
|
|
|
|
|
2024-08-01 09:38:02 -04:00
|
|
|
{#if myAdventures.length === 0 && osmResults.length === 0}
|
2024-07-18 14:55:23 -04:00
|
|
|
<NotFound error={data.error} />
|
2024-07-20 08:39:32 -04:00
|
|
|
{/if}
|
|
|
|
|
2024-08-14 22:17:43 -04:00
|
|
|
{#if myAdventures.length !== 0}
|
2024-07-18 15:48:14 -04:00
|
|
|
<h2 class="text-center font-bold text-2xl mb-4">AdventureLog Results</h2>
|
2024-08-04 21:50:15 -04:00
|
|
|
<div class="flex items-center justify-center mt-2 mb-2">
|
|
|
|
<div class="join">
|
|
|
|
<input
|
|
|
|
class="join-item btn"
|
|
|
|
type="radio"
|
|
|
|
name="filter"
|
|
|
|
aria-label="All"
|
|
|
|
id="all"
|
|
|
|
checked
|
|
|
|
on:change={() => (property = 'all')}
|
|
|
|
/>
|
|
|
|
<input
|
|
|
|
class="join-item btn"
|
|
|
|
type="radio"
|
|
|
|
name="filter"
|
|
|
|
aria-label="Name"
|
|
|
|
id="name"
|
|
|
|
on:change={() => (property = 'name')}
|
|
|
|
/>
|
|
|
|
<input
|
|
|
|
class="join-item btn"
|
|
|
|
type="radio"
|
|
|
|
name="filter"
|
|
|
|
aria-label="Type"
|
|
|
|
id="type"
|
|
|
|
on:change={() => (property = 'type')}
|
|
|
|
/>
|
|
|
|
<input
|
|
|
|
class="join-item btn"
|
|
|
|
type="radio"
|
|
|
|
name="filter"
|
|
|
|
aria-label="Location"
|
|
|
|
id="location"
|
|
|
|
on:change={() => (property = 'location')}
|
|
|
|
/>
|
|
|
|
<input
|
|
|
|
class="join-item btn"
|
|
|
|
type="radio"
|
|
|
|
name="filter"
|
|
|
|
aria-label="Description"
|
|
|
|
id="description"
|
|
|
|
on:change={() => (property = 'description')}
|
|
|
|
/>
|
|
|
|
<input
|
|
|
|
class="join-item btn"
|
|
|
|
type="radio"
|
|
|
|
name="filter"
|
|
|
|
aria-label="Activity Types"
|
|
|
|
id="activity_types"
|
|
|
|
on:change={() => (property = 'activity_types')}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<button class="btn btn-primary ml-2" type="button" on:click={filterByProperty}>Filter</button>
|
2024-08-01 10:25:40 -04:00
|
|
|
</div>
|
2024-08-04 21:50:15 -04:00
|
|
|
{/if}
|
2024-08-01 10:02:00 -04:00
|
|
|
|
2024-08-01 09:38:02 -04:00
|
|
|
{#if myAdventures.length > 0}
|
|
|
|
<h2 class="text-center font-bold text-2xl mb-4">My Adventures</h2>
|
2024-07-17 19:35:02 -04:00
|
|
|
<div class="flex flex-wrap gap-4 mr-4 justify-center content-center">
|
2024-08-01 09:38:02 -04:00
|
|
|
{#each myAdventures as adventure}
|
2024-07-18 18:37:46 -04:00
|
|
|
<AdventureCard
|
|
|
|
user={data.user}
|
|
|
|
type={adventure.type}
|
|
|
|
{adventure}
|
|
|
|
on:delete={deleteAdventure}
|
2024-07-22 10:08:42 -04:00
|
|
|
on:edit={editAdventure}
|
2024-07-18 18:37:46 -04:00
|
|
|
/>
|
2024-07-17 19:35:02 -04:00
|
|
|
{/each}
|
|
|
|
</div>
|
2024-07-20 08:39:32 -04:00
|
|
|
{/if}
|
2024-08-01 09:38:02 -04:00
|
|
|
|
|
|
|
{#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}
|
2024-07-18 15:48:14 -04:00
|
|
|
<div class="divider"></div>
|
2024-07-20 08:39:32 -04:00
|
|
|
{/if}
|
|
|
|
{#if osmResults.length > 0}
|
2024-08-04 21:50:15 -04:00
|
|
|
<h2 class="text-center font-bold mt-2 text-2xl mb-4">Online Results</h2>
|
2024-07-18 15:48:14 -04:00
|
|
|
<div class="flex flex-wrap gap-4 mr-4 justify-center content-center">
|
|
|
|
{#each osmResults as result}
|
2024-07-19 09:05:47 -04:00
|
|
|
<div class="bg-base-300 rounded-lg shadow-md p-4 w-96 mb-2">
|
2024-07-18 15:48:14 -04:00
|
|
|
<h2 class="text-xl font-bold">{result.display_name}</h2>
|
|
|
|
<p>{result.type}</p>
|
|
|
|
<p>{result.lat}, {result.lon}</p>
|
|
|
|
</div>
|
|
|
|
{/each}
|
|
|
|
</div>
|
2024-07-17 17:36:05 -04:00
|
|
|
{/if}
|
2024-08-06 08:50:15 -04:00
|
|
|
|
|
|
|
<svelte:head>
|
|
|
|
<title>Search{query ? `: ${query}` : ''}</title>
|
|
|
|
<meta name="description" content="Search your adventures." />
|
|
|
|
</svelte:head>
|