diff --git a/backend/server/adventures/admin.py b/backend/server/adventures/admin.py
index 00294996..7ac68427 100644
--- a/backend/server/adventures/admin.py
+++ b/backend/server/adventures/admin.py
@@ -1,7 +1,7 @@
import os
from django.contrib import admin
from django.utils.html import mark_safe
-from .models import Adventure, Checklist, ChecklistItem, Collection, Transportation, Note
+from .models import Adventure, Checklist, ChecklistItem, Collection, Transportation, Note, AdventureImage
from worldtravel.models import Country, Region, VisitedRegion
@@ -57,6 +57,20 @@ def image_display(self, obj):
else:
return
+class AdventureImageAdmin(admin.ModelAdmin):
+ list_display = ('user_id', 'image_display')
+
+ def image_display(self, obj):
+ if obj.image: # Ensure this field matches your model's image field
+ public_url = os.environ.get('PUBLIC_URL', 'http://127.0.0.1:8000').rstrip('/')
+ public_url = public_url.replace("'", "")
+ return mark_safe(f'
{/if}
-
-
-
-
-
-
- {#if type != 'link'}
-
- {#if !collection.is_archived}
-
- {/if}
- {#if collection.is_archived}
-
- {:else}
-
+ {#if type == 'link'}
+
+ {:else}
+
+
+
+
+
+
+ {#if type != 'link'}
+
+ {#if !collection.is_archived}
+
+ {/if}
+ {#if collection.is_archived}
+
+ {:else}
+
+ {/if}
+
{/if}
-
- {/if}
- {#if type == 'link'}
-
- {/if}
-
-
+
+
+ {/if}
diff --git a/frontend/src/lib/components/EditAdventure.svelte b/frontend/src/lib/components/EditAdventure.svelte
deleted file mode 100644
index 6654fba4..00000000
--- a/frontend/src/lib/components/EditAdventure.svelte
+++ /dev/null
@@ -1,363 +0,0 @@
-
-
-{#if isPointModalOpen}
- (isPointModalOpen = false)}
- on:submit={setLongLat}
- query={adventureToEdit.name}
- />
-{/if}
-
-{#if isImageFetcherOpen}
- (isImageFetcherOpen = false)}
- />
-{/if}
-
-
diff --git a/frontend/src/lib/components/NewAdventure.svelte b/frontend/src/lib/components/NewAdventure.svelte
deleted file mode 100644
index 4f114f73..00000000
--- a/frontend/src/lib/components/NewAdventure.svelte
+++ /dev/null
@@ -1,436 +0,0 @@
-
-
-{#if isPointModalOpen}
- (isPointModalOpen = false)}
- on:submit={setLongLat}
- bind:adventure={newAdventure}
- />
-{/if}
-
-{#if isImageFetcherOpen}
- (isImageFetcherOpen = false)}
- />
-{/if}
-
-
-
diff --git a/frontend/src/lib/types.ts b/frontend/src/lib/types.ts
index b00cf354..2a299dd7 100644
--- a/frontend/src/lib/types.ts
+++ b/frontend/src/lib/types.ts
@@ -11,7 +11,7 @@ export type User = {
export type Adventure = {
id: string;
- user_id: number;
+ user_id: number | null;
type: string;
name: string;
location?: string | null;
@@ -19,7 +19,10 @@ export type Adventure = {
description?: string | null;
rating?: number | null;
link?: string | null;
- image?: string | null;
+ images: {
+ id: string;
+ image: string;
+ }[];
date?: string | null; // Assuming date is a string in 'YYYY-MM-DD' format
collection?: string | null;
latitude: number | null;
@@ -55,6 +58,8 @@ export type Point = {
lng: number;
};
name: string;
+ location: string;
+ activity_type: string;
};
export type Collection = {
diff --git a/frontend/src/routes/adventures/+page.server.ts b/frontend/src/routes/adventures/+page.server.ts
index ed0e38a1..829a890a 100644
--- a/frontend/src/routes/adventures/+page.server.ts
+++ b/frontend/src/routes/adventures/+page.server.ts
@@ -159,7 +159,7 @@ export const actions: Actions = {
}
formDataToSend.append('rating', rating ? rating.toString() : '');
formDataToSend.append('link', link || '');
- formDataToSend.append('image', image);
+ // formDataToSend.append('image', image);
// log each key-value pair in the FormData
for (let pair of formDataToSend.entries()) {
@@ -233,6 +233,21 @@ export const actions: Actions = {
let image_url = new_id.image;
let link_url = new_id.link;
+ if (image && image.size > 0) {
+ let imageForm = new FormData();
+ imageForm.append('image', image);
+ imageForm.append('adventure', id);
+ let imageRes = await fetch(`${serverEndpoint}/api/images/`, {
+ method: 'POST',
+ headers: {
+ Cookie: `${event.cookies.get('auth')}`
+ },
+ body: imageForm
+ });
+ let data = await imageRes.json();
+ console.log(data);
+ }
+
return { id, user_id, image_url, link };
},
edit: async (event) => {
@@ -410,5 +425,17 @@ export const actions: Actions = {
let image_url = adventure.image;
let link_url = adventure.link;
return { image_url, link_url };
+ },
+ image: async (event) => {
+ let formData = await event.request.formData();
+ let res = await fetch(`${serverEndpoint}/api/images/`, {
+ method: 'POST',
+ headers: {
+ Cookie: `${event.cookies.get('auth')}`
+ },
+ body: formData
+ });
+ let data = await res.json();
+ return data;
}
};
diff --git a/frontend/src/routes/adventures/+page.svelte b/frontend/src/routes/adventures/+page.svelte
index 5882cc5f..c4f9cefa 100644
--- a/frontend/src/routes/adventures/+page.svelte
+++ b/frontend/src/routes/adventures/+page.svelte
@@ -3,8 +3,7 @@
import { goto } from '$app/navigation';
import { page } from '$app/stores';
import AdventureCard from '$lib/components/AdventureCard.svelte';
- import EditAdventure from '$lib/components/EditAdventure.svelte';
- import NewAdventure from '$lib/components/NewAdventure.svelte';
+ import AdventureModal from '$lib/components/AdventureModal.svelte';
import NotFound from '$lib/components/NotFound.svelte';
import type { Adventure } from '$lib/types';
@@ -23,9 +22,6 @@
includeCollections: true
};
- let isShowingCreateModal: boolean = false;
- let newType: string = '';
-
let resultsPerPage: number = 25;
let count = data.props.count || 0;
@@ -95,31 +91,31 @@
}
}
- let adventureToEdit: Adventure;
- let isEditModalOpen: boolean = false;
+ let adventureToEdit: Adventure | null = null;
+ let isAdventureModalOpen: boolean = false;
function deleteAdventure(event: CustomEvent) {
adventures = adventures.filter((adventure) => adventure.id !== event.detail);
}
- function createAdventure(event: CustomEvent) {
- adventures = [event.detail, ...adventures];
- isShowingCreateModal = false;
+ // function that save changes to an existing adventure or creates a new one if it doesn't exist
+ function saveOrCreate(event: CustomEvent) {
+ if (adventures.find((adventure) => adventure.id === event.detail.id)) {
+ adventures = adventures.map((adventure) => {
+ if (adventure.id === event.detail.id) {
+ return event.detail;
+ }
+ return adventure;
+ });
+ } else {
+ adventures = [event.detail, ...adventures];
+ }
+ isAdventureModalOpen = false;
}
function editAdventure(event: CustomEvent) {
adventureToEdit = event.detail;
- isEditModalOpen = true;
- }
-
- function saveEdit(event: CustomEvent) {
- adventures = adventures.map((adventure) => {
- if (adventure.id === event.detail.id) {
- return event.detail;
- }
- return adventure;
- });
- isEditModalOpen = false;
+ isAdventureModalOpen = true;
}
let sidebarOpen = false;
@@ -129,19 +125,11 @@
}
-{#if isShowingCreateModal}
- (isShowingCreateModal = false)}
- />
-{/if}
-
-{#if isEditModalOpen}
- (isEditModalOpen = false)}
- on:saveEdit={saveEdit}
+ on:close={() => (isAdventureModalOpen = false)}
+ on:save={saveOrCreate}
/>
{/if}
@@ -160,21 +148,13 @@
-
+