Skip to content

Commit

Permalink
Merge pull request #190 from seanmorley15/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
seanmorley15 authored Aug 15, 2024
2 parents a3f1dc7 + a1094f8 commit 54ff856
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 72 deletions.
16 changes: 15 additions & 1 deletion frontend/src/lib/components/AdventureCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
import Plus from '~icons/mdi/plus';
import CollectionLink from './CollectionLink.svelte';
import DotsHorizontal from '~icons/mdi/dots-horizontal';
import DeleteWarning from './DeleteWarning.svelte';
export let type: string;
export let user: User | null;
let isCollectionModalOpen: boolean = false;
let isWarningModalOpen: boolean = false;
let keyword: string = '';
Expand Down Expand Up @@ -136,6 +138,17 @@
<CollectionLink on:link={linkCollection} on:close={() => (isCollectionModalOpen = false)} />
{/if}

{#if isWarningModalOpen}
<DeleteWarning
title="Delete Adventure"
button_text="Delete"
description="Are you sure you want to delete this adventure? This action cannot be undone."
is_warning={false}
on:close={() => (isWarningModalOpen = false)}
on:confirm={deleteAdventure}
/>
{/if}

<div
class="card w-full max-w-xs sm:max-w-sm md:max-w-md lg:max-w-md xl:max-w-md bg-primary-content shadow-xl text-base-content"
>
Expand Down Expand Up @@ -249,7 +262,8 @@
id="delete_adventure"
data-umami-event="Delete Adventure"
class="btn btn-warning"
on:click={deleteAdventure}><TrashCan class="w-6 h-6" />Delete</button
on:click={() => (isWarningModalOpen = true)}
><TrashCan class="w-6 h-6" />Delete</button
>
</ul>
</div>
Expand Down
76 changes: 47 additions & 29 deletions frontend/src/lib/components/CollectionCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
import { addToast } from '$lib/toasts';
import Plus from '~icons/mdi/plus';
import { json } from '@sveltejs/kit';
import DotsHorizontal from '~icons/mdi/dots-horizontal';
import TrashCan from '~icons/mdi/trashcan';
import DeleteWarning from './DeleteWarning.svelte';
const dispatch = createEventDispatcher();
Expand Down Expand Up @@ -69,15 +70,15 @@
<DeleteWarning
title="Delete Collection"
button_text="Delete"
description="Are you sure you want to delete this collection? This action cannot be undone."
description="Are you sure you want to delete this collection? This will also delete all of the linked adventures. This action cannot be undone."
is_warning={true}
on:close={() => (isWarningModalOpen = false)}
on:confirm={deleteCollection}
/>
{/if}

<div
class="card min-w-max lg:w-96 md:w-80 sm:w-60 xs:w-40 bg-primary-content shadow-xl overflow-hidden text-base-content"
class="card min-w-max lg:w-96 md:w-80 sm:w-60 xs:w-40 bg-primary-content shadow-xl text-base-content"
>
<div class="card-body">
<div class="flex justify-between">
Expand Down Expand Up @@ -111,33 +112,50 @@
</p>{/if}

<div class="card-actions justify-end">
{#if type != 'link'}
<button on:click={() => (isWarningModalOpen = true)} class="btn btn-secondary"
><TrashCanOutline class="w-5 h-5 mr-1" /></button
<div class="dropdown dropdown-end">
<div tabindex="0" role="button" class="btn btn-neutral">
<DotsHorizontal class="w-6 h-6" />
</div>
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
<ul
tabindex="0"
class="dropdown-content menu bg-base-100 rounded-box z-[1] w-52 p-2 shadow"
>
{#if !collection.is_archived}
<button class="btn btn-primary" on:click={editAdventure}>
<FileDocumentEdit class="w-6 h-6" />
</button>
{/if}
<button class="btn btn-primary" on:click={() => goto(`/collections/${collection.id}`)}
><Launch class="w-5 h-5 mr-1" /></button
>
{/if}
{#if type == 'link'}
<button class="btn btn-primary" on:click={() => dispatch('link', collection.id)}>
<Plus class="w-5 h-5 mr-1" />
</button>
{/if}
{#if collection.is_archived}
<button class="btn btn-primary" on:click={() => archiveCollection(false)}>
<ArchiveArrowUp class="w-5 h-5 mr-1" />
</button>
{:else}
<button class="btn btn-primary" on:click={() => archiveCollection(true)}>
<ArchiveArrowDown class="w-5 h-5 mr" />
</button>
{/if}
{#if type != 'link'}
<button
class="btn btn-neutral mb-2"
on:click={() => goto(`/collections/${collection.id}`)}
><Launch class="w-5 h-5 mr-1" />Open Details</button
>
{#if !collection.is_archived}
<button class="btn btn-neutral mb-2" on:click={editAdventure}>
<FileDocumentEdit class="w-6 h-6" />Edit Collection
</button>
{/if}
{#if collection.is_archived}
<button class="btn btn-neutral mb-2" on:click={() => archiveCollection(false)}>
<ArchiveArrowUp class="w-6 h-6 mr-1" />Unarchive
</button>
{:else}
<button class="btn btn-neutral mb-2" on:click={() => archiveCollection(true)}>
<ArchiveArrowDown class="w-6 h-6 mr" />Archive
</button>
{/if}
<button
id="delete_adventure"
data-umami-event="Delete Adventure"
class="btn btn-warning"
on:click={() => (isWarningModalOpen = true)}
><TrashCan class="w-6 h-6" />Delete</button
>
{/if}
{#if type == 'link'}
<button class="btn btn-primary" on:click={() => dispatch('link', collection.id)}>
<Plus class="w-5 h-5 mr-1" />
</button>
{/if}
</ul>
</div>
</div>
</div>
</div>
23 changes: 20 additions & 3 deletions frontend/src/lib/components/Toast.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,25 @@

<div class="toast toast-top toast-end z-50 min-w-20">
{#each toastList as { type, message, id, duration }}
<div class="alert alert-{type}">
<span>{message}</span>
</div>
{#if type == 'success'}
<div class="alert alert-success">
<span>{message}</span>
</div>
{/if}
{#if type == 'error'}
<div class="alert alert-error">
<span>{message}</span>
</div>
{/if}
{#if type == 'info'}
<div class="alert alert-info">
<span>{message}</span>
</div>
{/if}
{#if type == 'warning'}
<div class="alert alert-warning">
<span>{message}</span>
</div>
{/if}
{/each}
</div>
4 changes: 2 additions & 2 deletions frontend/src/lib/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export let appVersion = 'Web v0.5.0';
export let versionChangelog = 'https://github.com/seanmorley15/AdventureLog/releases/tag/v0.5.0';
export let appVersion = 'Web v0.5.1';
export let versionChangelog = 'https://github.com/seanmorley15/AdventureLog/releases/tag/v0.5.1';
export let appTitle = 'AdventureLog';
export let copyrightYear = '2024';
22 changes: 22 additions & 0 deletions frontend/src/routes/adventures/[id]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
let adventure: Adventure;
let notFound: boolean = false;
let isEditModalOpen: boolean = false;
import ClipboardList from '~icons/mdi/clipboard-list';
import EditAdventure from '$lib/components/EditAdventure.svelte';
onMount(() => {
if (data.props.adventure) {
Expand All @@ -35,6 +39,11 @@
notFound = true;
}
});
function saveEdit(event: CustomEvent<Adventure>) {
adventure = event.detail;
isEditModalOpen = false;
}
</script>

{#if notFound}
Expand All @@ -59,13 +68,26 @@
</div>
{/if}

{#if isEditModalOpen}
<EditAdventure
adventureToEdit={adventure}
on:close={() => (isEditModalOpen = false)}
on:saveEdit={saveEdit}
/>
{/if}

{#if !adventure && !notFound}
<div class="flex justify-center items-center w-full mt-16">
<span class="loading loading-spinner w-24 h-24"></span>
</div>
{/if}

{#if adventure}
<div class="fixed bottom-4 right-4 z-[999]">
<button class="btn m-1 size-16 btn-primary" on:click={() => (isEditModalOpen = true)}
><ClipboardList class="w-8 h-8" /></button
>
</div>
<div class="flex flex-col min-h-dvh">
<main class="flex-1">
<div class="max-w-5xl mx-auto p-4 md:p-6 lg:p-8">
Expand Down
41 changes: 28 additions & 13 deletions frontend/src/routes/search/+page.server.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import type { Adventure } from '$lib/types';
import type { Adventure, OpenStreetMapPlace } from '$lib/types';
import { fail } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
import { appVersion } from '$lib/config';

const PUBLIC_SERVER_URL = process.env['PUBLIC_SERVER_URL'];
const serverEndpoint = PUBLIC_SERVER_URL || 'http://localhost:8000';

export const load = (async (event) => {
// get url param query
const query = event.url.searchParams.get('query');
const property = event.url.searchParams.get('property') || 'all';

Expand All @@ -23,19 +24,33 @@ export const load = (async (event) => {
}
);

if (res.ok) {
let data = await res.json();
console.log('Search data:', data);

return {
props: {
adventures: data,
query
}
};
} else {
if (!res.ok) {
console.error('Failed to fetch search data');
let error = await res.json();
return { error: error.error };
}

let adventures: Adventure[] = await res.json();

let osmRes = await fetch(`https://nominatim.openstreetmap.org/search?q=${query}&format=jsonv2`, {
headers: {
'User-Agent': `AdventureLog / ${appVersion} `
}
});

if (!osmRes.ok) {
console.error('Failed to fetch OSM data');
let error = await res.json();
return { error: error.error };
}

let osmData = (await osmRes.json()) as OpenStreetMapPlace[];

return {
props: {
adventures,
query,
osmData
}
};
}) satisfies PageServerLoad;
29 changes: 5 additions & 24 deletions frontend/src/routes/search/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,6 @@
onMount(() => {
const urlParams = new URLSearchParams(window.location.search);
query = urlParams.get('query');
fetchData();
});
async function fetchData() {
let res = await fetch(`https://nominatim.openstreetmap.org/search?q=${query}&format=jsonv2`, {
headers: {
'User-Agent': `AdventureLog / ${appVersion} `
}
});
const data = await res.json();
osmResults = data;
}
onMount(async () => {
let res = await fetch(`https://nominatim.openstreetmap.org/search?q=${query}&format=jsonv2`, {
headers: {
'User-Agent': `AdventureLog / ${appVersion} `
}
});
const data = await res.json();
osmResults = data;
});
console.log(data);
Expand All @@ -73,12 +51,15 @@
publicAdventures = publicAdventures.filter(
(adventure) => adventure.user_id !== data.user?.pk
);
if (data.props.osmData) {
osmResults = data.props.osmData;
}
}
}
let adventureToEdit: Adventure;
let isEditModalOpen: boolean = false;
let isShowingCreateModal: boolean = false;
function editAdventure(event: CustomEvent<Adventure>) {
adventureToEdit = event.detail;
Expand Down Expand Up @@ -108,7 +89,7 @@
<NotFound error={data.error} />
{/if}

{#if myAdventures.length !== 0 && publicAdventures.length !== 0}
{#if myAdventures.length !== 0}
<h2 class="text-center font-bold text-2xl mb-4">AdventureLog Results</h2>
<div class="flex items-center justify-center mt-2 mb-2">
<div class="join">
Expand Down

0 comments on commit 54ff856

Please sign in to comment.