2024-07-08 11:44:39 -04:00
|
|
|
<script lang="ts">
|
|
|
|
import { createEventDispatcher } from 'svelte';
|
2024-08-17 11:12:15 -04:00
|
|
|
import type { Adventure, OpenStreetMapPlace, Point } from '$lib/types';
|
2024-07-08 11:44:39 -04:00
|
|
|
import { onMount } from 'svelte';
|
2024-08-17 11:12:15 -04:00
|
|
|
import { enhance } from '$app/forms';
|
2024-07-08 11:44:39 -04:00
|
|
|
import { addToast } from '$lib/toasts';
|
2024-08-17 15:18:43 -04:00
|
|
|
import { deserialize } from '$app/forms';
|
2024-08-17 11:12:15 -04:00
|
|
|
|
|
|
|
export let longitude: number | null = null;
|
|
|
|
export let latitude: number | null = null;
|
2024-08-17 22:40:27 -04:00
|
|
|
export let collection_id: string | null = null;
|
2024-08-17 11:12:15 -04:00
|
|
|
|
|
|
|
import { DefaultMarker, MapEvents, MapLibre } from 'svelte-maplibre';
|
|
|
|
let markers: Point[] = [];
|
|
|
|
let query: string = '';
|
|
|
|
let places: OpenStreetMapPlace[] = [];
|
|
|
|
let images: { id: string; image: string }[] = [];
|
|
|
|
|
|
|
|
import Earth from '~icons/mdi/earth';
|
|
|
|
import ActivityComplete from './ActivityComplete.svelte';
|
|
|
|
import { appVersion } from '$lib/config';
|
2024-07-08 11:44:39 -04:00
|
|
|
|
2024-07-31 11:01:41 -04:00
|
|
|
export let startDate: string | null = null;
|
|
|
|
export let endDate: string | null = null;
|
|
|
|
|
2024-08-17 22:48:57 -04:00
|
|
|
let wikiError: string = '';
|
|
|
|
|
2024-08-17 14:21:55 -04:00
|
|
|
let noPlaces: boolean = false;
|
|
|
|
|
2024-08-17 22:40:27 -04:00
|
|
|
export let adventureToEdit: Adventure | null = null;
|
|
|
|
|
|
|
|
let adventure: Adventure = {
|
|
|
|
id: adventureToEdit?.id || '',
|
|
|
|
name: adventureToEdit?.name || '',
|
|
|
|
type: adventureToEdit?.type || 'visited',
|
|
|
|
date: adventureToEdit?.date || null,
|
2024-08-18 12:30:12 -04:00
|
|
|
end_date: adventureToEdit?.end_date || null,
|
2024-08-17 22:40:27 -04:00
|
|
|
link: adventureToEdit?.link || null,
|
|
|
|
description: adventureToEdit?.description || null,
|
|
|
|
activity_types: adventureToEdit?.activity_types || [],
|
|
|
|
rating: adventureToEdit?.rating || NaN,
|
|
|
|
is_public: adventureToEdit?.is_public || false,
|
|
|
|
latitude: adventureToEdit?.latitude || NaN,
|
|
|
|
longitude: adventureToEdit?.longitude || NaN,
|
|
|
|
location: adventureToEdit?.location || null,
|
|
|
|
images: adventureToEdit?.images || [],
|
|
|
|
user_id: adventureToEdit?.user_id || null,
|
|
|
|
collection: adventureToEdit?.collection || collection_id || null
|
|
|
|
};
|
2024-08-17 11:12:15 -04:00
|
|
|
|
2024-08-17 15:18:43 -04:00
|
|
|
let url: string = '';
|
|
|
|
let imageError: string = '';
|
2024-08-17 16:28:56 -04:00
|
|
|
let wikiImageError: string = '';
|
2024-08-17 15:18:43 -04:00
|
|
|
|
2024-08-17 22:40:27 -04:00
|
|
|
images = adventure.images || [];
|
2024-07-08 11:44:39 -04:00
|
|
|
|
2024-08-17 22:40:27 -04:00
|
|
|
if (adventure.longitude && adventure.latitude) {
|
2024-08-17 17:34:52 -04:00
|
|
|
markers = [
|
|
|
|
{
|
2024-08-17 22:40:27 -04:00
|
|
|
lngLat: { lng: adventure.longitude, lat: adventure.latitude },
|
|
|
|
location: adventure.location || '',
|
|
|
|
name: adventure.name,
|
2024-08-18 09:15:59 -04:00
|
|
|
activity_type: ''
|
2024-08-17 17:34:52 -04:00
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2024-08-17 11:12:15 -04:00
|
|
|
if (longitude && latitude) {
|
2024-08-17 22:40:27 -04:00
|
|
|
adventure.latitude = latitude;
|
|
|
|
adventure.longitude = longitude;
|
2024-08-17 11:12:15 -04:00
|
|
|
reverseGeocode();
|
|
|
|
}
|
2024-07-08 11:44:39 -04:00
|
|
|
|
2024-08-17 11:12:15 -04:00
|
|
|
$: {
|
2024-08-17 22:40:27 -04:00
|
|
|
if (!adventure.rating) {
|
|
|
|
adventure.rating = NaN;
|
2024-08-17 11:12:15 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-17 22:40:27 -04:00
|
|
|
let imageSearch: string = adventure.name || '';
|
2024-08-17 15:18:43 -04:00
|
|
|
|
2024-08-17 13:30:00 -04:00
|
|
|
async function removeImage(id: string) {
|
2024-08-17 13:59:49 -04:00
|
|
|
let res = await fetch(`/api/images/${id}/image_delete`, {
|
|
|
|
method: 'POST'
|
2024-08-17 13:30:00 -04:00
|
|
|
});
|
2024-08-17 13:59:49 -04:00
|
|
|
if (res.status === 204) {
|
2024-08-17 13:30:00 -04:00
|
|
|
images = images.filter((image) => image.id !== id);
|
2024-08-17 22:40:27 -04:00
|
|
|
adventure.images = images;
|
2024-08-17 13:59:49 -04:00
|
|
|
console.log(images);
|
2024-08-17 13:30:00 -04:00
|
|
|
addToast('success', 'Image removed');
|
|
|
|
} else {
|
|
|
|
addToast('error', 'Failed to remove image');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-17 11:12:15 -04:00
|
|
|
let isDetails: boolean = true;
|
|
|
|
|
|
|
|
function saveAndClose() {
|
2024-08-17 22:40:27 -04:00
|
|
|
dispatch('save', adventure);
|
2024-08-17 11:12:15 -04:00
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
|
|
|
$: if (markers.length > 0) {
|
2024-08-17 22:40:27 -04:00
|
|
|
adventure.latitude = Math.round(markers[0].lngLat.lat * 1e6) / 1e6;
|
|
|
|
adventure.longitude = Math.round(markers[0].lngLat.lng * 1e6) / 1e6;
|
|
|
|
if (!adventure.location) {
|
|
|
|
adventure.location = markers[0].location;
|
2024-08-17 11:12:15 -04:00
|
|
|
}
|
2024-08-17 22:40:27 -04:00
|
|
|
if (!adventure.name) {
|
|
|
|
adventure.name = markers[0].name;
|
2024-08-17 11:12:15 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-17 15:18:43 -04:00
|
|
|
async function fetchImage() {
|
|
|
|
let res = await fetch(url);
|
|
|
|
let data = await res.blob();
|
|
|
|
if (!data) {
|
|
|
|
imageError = 'No image found at that URL.';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let file = new File([data], 'image.jpg', { type: 'image/jpeg' });
|
|
|
|
let formData = new FormData();
|
|
|
|
formData.append('image', file);
|
2024-08-17 22:40:27 -04:00
|
|
|
formData.append('adventure', adventure.id);
|
2024-08-17 15:18:43 -04:00
|
|
|
let res2 = await fetch(`/adventures?/image`, {
|
|
|
|
method: 'POST',
|
|
|
|
body: formData
|
|
|
|
});
|
|
|
|
let data2 = await res2.json();
|
|
|
|
console.log(data2);
|
|
|
|
if (data2.type === 'success') {
|
|
|
|
images = [...images, data2];
|
2024-08-17 22:40:27 -04:00
|
|
|
adventure.images = images;
|
2024-08-17 15:18:43 -04:00
|
|
|
addToast('success', 'Image uploaded');
|
|
|
|
} else {
|
|
|
|
addToast('error', 'Failed to upload image');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function fetchWikiImage() {
|
|
|
|
let res = await fetch(`/api/generate/img/?name=${imageSearch}`);
|
|
|
|
let data = await res.json();
|
2024-08-17 16:28:56 -04:00
|
|
|
if (!res.ok) {
|
|
|
|
wikiImageError = 'Failed to fetch image';
|
|
|
|
return;
|
|
|
|
}
|
2024-08-17 15:18:43 -04:00
|
|
|
if (data.source) {
|
|
|
|
let imageUrl = data.source;
|
|
|
|
let res = await fetch(imageUrl);
|
|
|
|
let blob = await res.blob();
|
|
|
|
let file = new File([blob], `${imageSearch}.jpg`, { type: 'image/jpeg' });
|
|
|
|
let formData = new FormData();
|
|
|
|
formData.append('image', file);
|
2024-08-17 22:40:27 -04:00
|
|
|
formData.append('adventure', adventure.id);
|
2024-08-17 15:18:43 -04:00
|
|
|
let res2 = await fetch(`/adventures?/image`, {
|
|
|
|
method: 'POST',
|
|
|
|
body: formData
|
|
|
|
});
|
|
|
|
if (res2.ok) {
|
|
|
|
let newData = deserialize(await res2.text()) as { data: { id: string; image: string } };
|
|
|
|
console.log(newData);
|
|
|
|
let newImage = { id: newData.data.id, image: newData.data.image };
|
|
|
|
console.log(newImage);
|
|
|
|
images = [...images, newImage];
|
2024-08-17 22:40:27 -04:00
|
|
|
adventure.images = images;
|
2024-08-17 15:18:43 -04:00
|
|
|
addToast('success', 'Image uploaded');
|
|
|
|
} else {
|
|
|
|
addToast('error', 'Failed to upload image');
|
2024-08-17 16:28:56 -04:00
|
|
|
wikiImageError = 'Failed to upload image';
|
2024-08-17 15:18:43 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-08-17 11:12:15 -04:00
|
|
|
async function geocode(e: Event | null) {
|
|
|
|
if (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
if (!query) {
|
|
|
|
alert('Please enter a location');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let res = await fetch(`https://nominatim.openstreetmap.org/search?q=${query}&format=jsonv2`, {
|
|
|
|
headers: {
|
|
|
|
'User-Agent': `AdventureLog / ${appVersion} `
|
|
|
|
}
|
|
|
|
});
|
|
|
|
console.log(res);
|
|
|
|
let data = (await res.json()) as OpenStreetMapPlace[];
|
|
|
|
places = data;
|
2024-08-17 14:21:55 -04:00
|
|
|
if (data.length === 0) {
|
|
|
|
noPlaces = true;
|
|
|
|
} else {
|
|
|
|
noPlaces = false;
|
|
|
|
}
|
2024-08-17 11:12:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
async function reverseGeocode() {
|
|
|
|
let res = await fetch(
|
2024-08-17 22:40:27 -04:00
|
|
|
`https://nominatim.openstreetmap.org/search?q=${adventure.latitude},${adventure.longitude}&format=jsonv2`,
|
2024-08-17 11:12:15 -04:00
|
|
|
{
|
|
|
|
headers: {
|
|
|
|
'User-Agent': `AdventureLog / ${appVersion} `
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
let data = (await res.json()) as OpenStreetMapPlace[];
|
|
|
|
if (data.length > 0) {
|
2024-08-17 22:40:27 -04:00
|
|
|
adventure.name = data[0]?.name || '';
|
|
|
|
adventure.activity_types?.push(data[0]?.type || '');
|
|
|
|
adventure.location = data[0]?.display_name || '';
|
|
|
|
if (longitude && latitude) {
|
|
|
|
markers = [
|
|
|
|
{
|
|
|
|
lngLat: { lng: longitude, lat: latitude },
|
|
|
|
location: data[0]?.display_name || '',
|
|
|
|
name: data[0]?.name || '',
|
2024-08-18 09:15:59 -04:00
|
|
|
activity_type: data[0]?.type || ''
|
2024-08-17 22:40:27 -04:00
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
2024-08-17 11:12:15 -04:00
|
|
|
}
|
|
|
|
console.log(data);
|
|
|
|
}
|
2024-07-16 15:38:07 -04:00
|
|
|
|
|
|
|
let fileInput: HTMLInputElement;
|
2024-07-08 11:44:39 -04:00
|
|
|
|
2024-08-17 11:12:15 -04:00
|
|
|
const dispatch = createEventDispatcher();
|
|
|
|
let modal: HTMLDialogElement;
|
2024-07-08 11:44:39 -04:00
|
|
|
|
|
|
|
onMount(async () => {
|
|
|
|
modal = document.getElementById('my_modal_1') as HTMLDialogElement;
|
|
|
|
if (modal) {
|
|
|
|
modal.showModal();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
function close() {
|
|
|
|
dispatch('close');
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleKeydown(event: KeyboardEvent) {
|
|
|
|
if (event.key === 'Escape') {
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-17 22:48:57 -04:00
|
|
|
async function generateDesc() {
|
|
|
|
let res = await fetch(`/api/generate/desc/?name=${adventure.name}`);
|
|
|
|
let data = await res.json();
|
|
|
|
if (data.extract?.length > 0) {
|
|
|
|
adventure.description = data.extract;
|
2024-08-18 09:15:59 -04:00
|
|
|
wikiError = '';
|
2024-08-17 22:48:57 -04:00
|
|
|
} else {
|
|
|
|
wikiError = 'No description found';
|
|
|
|
}
|
|
|
|
}
|
2024-07-08 11:44:39 -04:00
|
|
|
|
2024-08-17 11:12:15 -04:00
|
|
|
function addMarker(e: CustomEvent<any>) {
|
|
|
|
markers = [];
|
2024-08-17 22:48:57 -04:00
|
|
|
markers = [
|
|
|
|
...markers,
|
|
|
|
{
|
|
|
|
lngLat: e.detail.lngLat,
|
|
|
|
name: '',
|
|
|
|
location: '',
|
2024-08-18 09:15:59 -04:00
|
|
|
activity_type: ''
|
2024-08-17 22:48:57 -04:00
|
|
|
}
|
|
|
|
];
|
2024-08-17 11:12:15 -04:00
|
|
|
console.log(markers);
|
|
|
|
}
|
2024-07-08 11:44:39 -04:00
|
|
|
|
2024-08-17 11:12:15 -04:00
|
|
|
function imageSubmit() {
|
|
|
|
return async ({ result }: any) => {
|
|
|
|
if (result.type === 'success') {
|
|
|
|
if (result.data.id && result.data.image) {
|
2024-08-17 22:40:27 -04:00
|
|
|
adventure.images = [...adventure.images, result.data];
|
2024-08-17 11:12:15 -04:00
|
|
|
images = [...images, result.data];
|
|
|
|
addToast('success', 'Image uploaded');
|
2024-07-08 11:44:39 -04:00
|
|
|
|
2024-08-17 11:12:15 -04:00
|
|
|
fileInput.value = '';
|
2024-08-17 22:40:27 -04:00
|
|
|
console.log(adventure);
|
2024-08-17 11:12:15 -04:00
|
|
|
} else {
|
|
|
|
addToast('error', result.data.error || 'Failed to upload image');
|
2024-07-08 11:44:39 -04:00
|
|
|
}
|
|
|
|
}
|
2024-08-17 11:12:15 -04:00
|
|
|
};
|
2024-07-08 11:44:39 -04:00
|
|
|
}
|
2024-07-16 15:38:07 -04:00
|
|
|
|
2024-08-17 11:12:15 -04:00
|
|
|
async function handleSubmit(event: Event) {
|
|
|
|
event.preventDefault();
|
2024-08-18 12:30:12 -04:00
|
|
|
|
|
|
|
if (adventure.date && adventure.end_date) {
|
|
|
|
if (new Date(adventure.date) > new Date(adventure.end_date)) {
|
|
|
|
addToast('error', 'Start date must be before end date');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-17 22:40:27 -04:00
|
|
|
console.log(adventure);
|
|
|
|
if (adventure.id === '') {
|
|
|
|
let res = await fetch('/api/adventures', {
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
},
|
|
|
|
body: JSON.stringify(adventure)
|
|
|
|
});
|
|
|
|
let data = await res.json();
|
|
|
|
if (data.id) {
|
|
|
|
adventure = data as Adventure;
|
|
|
|
isDetails = false;
|
|
|
|
addToast('success', 'Adventure created');
|
|
|
|
} else {
|
|
|
|
addToast('error', 'Failed to create adventure');
|
|
|
|
}
|
2024-08-17 11:12:15 -04:00
|
|
|
} else {
|
2024-08-17 22:40:27 -04:00
|
|
|
let res = await fetch(`/api/adventures/${adventure.id}`, {
|
|
|
|
method: 'PATCH',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
},
|
|
|
|
body: JSON.stringify(adventure)
|
|
|
|
});
|
|
|
|
let data = await res.json();
|
|
|
|
if (data.id) {
|
|
|
|
adventure = data as Adventure;
|
|
|
|
isDetails = false;
|
|
|
|
addToast('success', 'Adventure updated');
|
|
|
|
} else {
|
|
|
|
addToast('error', 'Failed to update adventure');
|
|
|
|
}
|
2024-07-16 15:38:07 -04:00
|
|
|
}
|
2024-07-08 11:44:39 -04:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2024-08-17 11:12:15 -04:00
|
|
|
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
|
2024-07-08 11:44:39 -04:00
|
|
|
<dialog id="my_modal_1" class="modal">
|
|
|
|
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
|
2024-08-17 11:12:15 -04:00
|
|
|
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
|
2024-08-17 14:13:23 -04:00
|
|
|
<div class="modal-box w-11/12 max-w-2xl" role="dialog" on:keydown={handleKeydown} tabindex="0">
|
2024-08-17 22:40:27 -04:00
|
|
|
<h3 class="font-bold text-lg">Edit {adventure.type} Adventure</h3>
|
|
|
|
{#if adventure.id === '' || isDetails}
|
2024-08-17 11:12:15 -04:00
|
|
|
<div class="modal-action items-center">
|
|
|
|
<form method="post" style="width: 100%;" on:submit={handleSubmit}>
|
|
|
|
<!-- Grid layout for form fields -->
|
|
|
|
<h2 class="text-2xl font-semibold mb-2">Basic Information</h2>
|
2024-08-17 14:13:23 -04:00
|
|
|
<!-- <div class="grid grid-cols-1 gap-4 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-3"> -->
|
|
|
|
<div>
|
|
|
|
<label for="name">Name</label><br />
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
id="name"
|
|
|
|
name="name"
|
2024-08-17 22:40:27 -04:00
|
|
|
bind:value={adventure.name}
|
2024-08-17 14:13:23 -04:00
|
|
|
class="input input-bordered w-full"
|
|
|
|
required
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<div class="form-control">
|
|
|
|
<label class="label cursor-pointer">
|
|
|
|
<span class="label-text">Visited</span>
|
2024-08-17 13:30:00 -04:00
|
|
|
<input
|
2024-08-17 14:13:23 -04:00
|
|
|
type="radio"
|
|
|
|
name="radio-10"
|
|
|
|
class="radio checked:bg-red-500"
|
2024-08-17 22:40:27 -04:00
|
|
|
on:click={() => (adventure.type = 'visited')}
|
|
|
|
checked={adventure.type == 'visited'}
|
2024-08-17 13:30:00 -04:00
|
|
|
/>
|
2024-08-17 14:13:23 -04:00
|
|
|
</label>
|
2024-08-17 13:30:00 -04:00
|
|
|
</div>
|
2024-08-17 14:13:23 -04:00
|
|
|
<div class="form-control">
|
|
|
|
<label class="label cursor-pointer">
|
|
|
|
<span class="label-text">Planned</span>
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
name="radio-10"
|
|
|
|
class="radio checked:bg-blue-500"
|
2024-08-17 22:40:27 -04:00
|
|
|
on:click={() => (adventure.type = 'planned')}
|
|
|
|
checked={adventure.type == 'planned'}
|
2024-08-17 14:13:23 -04:00
|
|
|
/>
|
|
|
|
</label>
|
2024-08-17 11:12:15 -04:00
|
|
|
</div>
|
2024-08-17 14:13:23 -04:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div>
|
2024-08-19 16:32:08 -04:00
|
|
|
<label for="date">{adventure.date ? 'Start Date' : 'Date'}</label><br />
|
2024-08-17 14:13:23 -04:00
|
|
|
<input
|
|
|
|
type="date"
|
|
|
|
id="date"
|
|
|
|
name="date"
|
|
|
|
min={startDate || ''}
|
|
|
|
max={endDate || ''}
|
2024-08-17 22:40:27 -04:00
|
|
|
bind:value={adventure.date}
|
2024-08-17 14:13:23 -04:00
|
|
|
class="input input-bordered w-full"
|
|
|
|
/>
|
|
|
|
</div>
|
2024-08-19 16:32:08 -04:00
|
|
|
{#if adventure.date}
|
|
|
|
<div>
|
|
|
|
<label for="end_date">End Date</label><br />
|
|
|
|
<input
|
|
|
|
type="date"
|
|
|
|
id="end_date"
|
|
|
|
name="end_date"
|
|
|
|
min={startDate || ''}
|
|
|
|
max={endDate || ''}
|
|
|
|
bind:value={adventure.end_date}
|
|
|
|
class="input input-bordered w-full"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
{/if}
|
2024-08-17 14:13:23 -04:00
|
|
|
<div>
|
|
|
|
<!-- link -->
|
2024-08-17 11:12:15 -04:00
|
|
|
<div>
|
2024-08-17 14:13:23 -04:00
|
|
|
<label for="link">Link</label><br />
|
2024-08-17 11:12:15 -04:00
|
|
|
<input
|
|
|
|
type="text"
|
2024-08-17 14:13:23 -04:00
|
|
|
id="link"
|
|
|
|
name="link"
|
2024-08-17 22:40:27 -04:00
|
|
|
bind:value={adventure.link}
|
2024-08-17 11:12:15 -04:00
|
|
|
class="input input-bordered w-full"
|
|
|
|
/>
|
|
|
|
</div>
|
2024-08-17 14:13:23 -04:00
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<label for="description">Description</label><br />
|
|
|
|
<textarea
|
|
|
|
id="description"
|
|
|
|
name="description"
|
2024-08-17 22:40:27 -04:00
|
|
|
bind:value={adventure.description}
|
2024-08-17 14:13:23 -04:00
|
|
|
class="textarea textarea-bordered w-full h-32"
|
|
|
|
></textarea>
|
2024-08-17 22:48:57 -04:00
|
|
|
<div class="mt-2">
|
|
|
|
<button type="button" class="btn btn-neutral" on:click={generateDesc}
|
|
|
|
>Generate Description</button
|
|
|
|
>
|
|
|
|
<p class="text-red-500">{wikiError}</p>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<label for="activity_types">Activity Types</label><br />
|
2024-08-17 14:13:23 -04:00
|
|
|
<input
|
2024-08-17 22:48:57 -04:00
|
|
|
type="text"
|
|
|
|
id="activity_types"
|
|
|
|
name="activity_types"
|
|
|
|
hidden
|
|
|
|
bind:value={adventure.activity_types}
|
|
|
|
class="input input-bordered w-full"
|
2024-08-17 14:13:23 -04:00
|
|
|
/>
|
2024-08-17 22:48:57 -04:00
|
|
|
<ActivityComplete bind:activities={adventure.activity_types} />
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<label for="rating"
|
|
|
|
>Rating <iconify-icon icon="mdi:star" class="text-xl -mb-1"></iconify-icon></label
|
|
|
|
><br />
|
2024-08-17 14:13:23 -04:00
|
|
|
<input
|
2024-08-17 22:48:57 -04:00
|
|
|
type="number"
|
|
|
|
min="0"
|
|
|
|
max="5"
|
|
|
|
hidden
|
|
|
|
bind:value={adventure.rating}
|
|
|
|
id="rating"
|
|
|
|
name="rating"
|
|
|
|
class="input input-bordered w-full max-w-xs mt-1"
|
2024-08-17 14:13:23 -04:00
|
|
|
/>
|
2024-08-17 22:48:57 -04:00
|
|
|
<div class="rating -ml-3 mt-1">
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
name="rating-2"
|
|
|
|
class="rating-hidden"
|
|
|
|
checked={Number.isNaN(adventure.rating)}
|
|
|
|
/>
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
name="rating-2"
|
|
|
|
class="mask mask-star-2 bg-orange-400"
|
|
|
|
on:click={() => (adventure.rating = 1)}
|
|
|
|
checked={adventure.rating === 1}
|
|
|
|
/>
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
name="rating-2"
|
|
|
|
class="mask mask-star-2 bg-orange-400"
|
|
|
|
on:click={() => (adventure.rating = 2)}
|
|
|
|
checked={adventure.rating === 2}
|
|
|
|
/>
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
name="rating-2"
|
|
|
|
class="mask mask-star-2 bg-orange-400"
|
|
|
|
on:click={() => (adventure.rating = 3)}
|
|
|
|
checked={adventure.rating === 3}
|
|
|
|
/>
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
name="rating-2"
|
|
|
|
class="mask mask-star-2 bg-orange-400"
|
|
|
|
on:click={() => (adventure.rating = 4)}
|
|
|
|
checked={adventure.rating === 4}
|
|
|
|
/>
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
name="rating-2"
|
|
|
|
class="mask mask-star-2 bg-orange-400"
|
|
|
|
on:click={() => (adventure.rating = 5)}
|
|
|
|
checked={adventure.rating === 5}
|
|
|
|
/>
|
|
|
|
{#if adventure.rating}
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
class="btn btn-sm btn-error ml-2"
|
|
|
|
on:click={() => (adventure.rating = NaN)}
|
|
|
|
>
|
|
|
|
Remove
|
|
|
|
</button>
|
|
|
|
{/if}
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<div class="mt-2">
|
|
|
|
<div>
|
|
|
|
<label for="is_public"
|
|
|
|
>Public <Earth class="inline-block -mt-1 mb-1 w-6 h-6" /></label
|
|
|
|
><br />
|
|
|
|
<input
|
|
|
|
type="checkbox"
|
|
|
|
class="toggle toggle-primary"
|
|
|
|
id="is_public"
|
|
|
|
name="is_public"
|
|
|
|
bind:checked={adventure.is_public}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="divider"></div>
|
|
|
|
<h2 class="text-2xl font-semibold mb-2 mt-2">Location Information</h2>
|
|
|
|
<!-- <div class="grid grid-cols-1 gap-4 md:grid-cols-2 lg:grid-cols-3"> -->
|
|
|
|
<div>
|
|
|
|
<label for="latitude">Location</label><br />
|
2024-08-17 14:13:23 -04:00
|
|
|
<input
|
2024-08-17 22:48:57 -04:00
|
|
|
type="text"
|
|
|
|
id="location"
|
|
|
|
name="location"
|
|
|
|
bind:value={adventure.location}
|
|
|
|
class="input input-bordered w-full"
|
2024-08-17 14:13:23 -04:00
|
|
|
/>
|
2024-08-15 21:29:36 -04:00
|
|
|
</div>
|
2024-08-17 14:38:24 -04:00
|
|
|
<div>
|
2024-08-17 22:48:57 -04:00
|
|
|
<form on:submit={geocode} class="mt-2">
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
placeholder="Seach for a location"
|
|
|
|
class="input input-bordered w-full max-w-xs mb-2"
|
|
|
|
id="search"
|
|
|
|
name="search"
|
|
|
|
bind:value={query}
|
|
|
|
/>
|
|
|
|
<button class="btn btn-neutral -mt-1" type="submit">Search</button>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
{#if places.length > 0}
|
|
|
|
<div class="mt-4 max-w-full">
|
|
|
|
<h3 class="font-bold text-lg mb-4">Search Results</h3>
|
|
|
|
|
|
|
|
<div class="flex flex-wrap">
|
|
|
|
{#each places as place}
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
class="btn btn-neutral mb-2 mr-2 max-w-full break-words whitespace-normal text-left"
|
|
|
|
on:click={() => {
|
|
|
|
markers = [
|
|
|
|
{
|
|
|
|
lngLat: { lng: Number(place.lon), lat: Number(place.lat) },
|
|
|
|
location: place.display_name,
|
|
|
|
name: place.name,
|
2024-08-18 09:15:59 -04:00
|
|
|
activity_type: place.type
|
2024-08-17 22:48:57 -04:00
|
|
|
}
|
|
|
|
];
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{place.display_name}
|
|
|
|
</button>
|
|
|
|
{/each}
|
2024-08-17 14:38:24 -04:00
|
|
|
</div>
|
|
|
|
</div>
|
2024-08-17 22:48:57 -04:00
|
|
|
{:else if noPlaces}
|
|
|
|
<p class="text-error text-lg">No results found</p>
|
|
|
|
{/if}
|
|
|
|
<!-- </div> -->
|
|
|
|
<div>
|
|
|
|
<MapLibre
|
|
|
|
style="https://basemaps.cartocdn.com/gl/positron-gl-style/style.json"
|
|
|
|
class="relative aspect-[9/16] max-h-[70vh] w-full sm:aspect-video sm:max-h-full"
|
|
|
|
standardControls
|
|
|
|
>
|
|
|
|
<!-- MapEvents gives you access to map events even from other components inside the map,
|
|
|
|
where you might not have access to the top-level `MapLibre` component. In this case
|
|
|
|
it would also work to just use on:click on the MapLibre component itself. -->
|
|
|
|
<MapEvents on:click={addMarker} />
|
|
|
|
|
|
|
|
{#each markers as marker}
|
|
|
|
<DefaultMarker lngLat={marker.lngLat} />
|
|
|
|
{/each}
|
|
|
|
</MapLibre>
|
2024-08-17 14:38:24 -04:00
|
|
|
</div>
|
2024-08-17 14:13:23 -04:00
|
|
|
|
2024-08-17 22:48:57 -04:00
|
|
|
<div class="mt-4">
|
|
|
|
<button type="submit" class="btn btn-primary">Save & Next</button>
|
|
|
|
<button type="button" class="btn" on:click={close}>Close</button>
|
|
|
|
</div>
|
2024-08-17 11:12:15 -04:00
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
{:else}
|
|
|
|
<p>Upload images here</p>
|
2024-08-17 14:38:24 -04:00
|
|
|
<!-- <p>{adventureToEdit.id}</p> -->
|
2024-08-17 11:12:15 -04:00
|
|
|
<div class="mb-2">
|
|
|
|
<label for="image">Image </label><br />
|
|
|
|
<div class="flex">
|
|
|
|
<form
|
|
|
|
method="POST"
|
2024-08-17 22:40:27 -04:00
|
|
|
action="/adventures?/image"
|
2024-08-17 11:12:15 -04:00
|
|
|
use:enhance={imageSubmit}
|
|
|
|
enctype="multipart/form-data"
|
2024-08-15 21:29:36 -04:00
|
|
|
>
|
2024-08-17 11:12:15 -04:00
|
|
|
<input
|
|
|
|
type="file"
|
|
|
|
name="image"
|
|
|
|
class="file-input file-input-bordered w-full max-w-xs"
|
|
|
|
bind:this={fileInput}
|
|
|
|
accept="image/*"
|
|
|
|
id="image"
|
|
|
|
/>
|
2024-08-17 22:40:27 -04:00
|
|
|
<input type="hidden" name="adventure" value={adventure.id} id="adventure" />
|
2024-08-17 11:12:15 -04:00
|
|
|
<button class="btn btn-neutral mt-2 mb-2" type="submit">Upload Image</button>
|
|
|
|
</form>
|
|
|
|
</div>
|
2024-08-17 15:18:43 -04:00
|
|
|
<div class="mt-2">
|
|
|
|
<label for="url">URL</label><br />
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
id="url"
|
|
|
|
name="url"
|
|
|
|
bind:value={url}
|
|
|
|
class="input input-bordered w-full"
|
|
|
|
/>
|
|
|
|
<button class="btn btn-neutral mt-2" type="button" on:click={fetchImage}
|
|
|
|
>Fetch Image</button
|
|
|
|
>
|
|
|
|
</div>
|
|
|
|
<div class="mt-2">
|
|
|
|
<label for="name">Wikipedia</label><br />
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
id="name"
|
|
|
|
name="name"
|
|
|
|
bind:value={imageSearch}
|
|
|
|
class="input input-bordered w-full"
|
|
|
|
/>
|
|
|
|
<button class="btn btn-neutral mt-2" type="button" on:click={fetchWikiImage}
|
|
|
|
>Fetch Image</button
|
|
|
|
>
|
|
|
|
</div>
|
2024-08-17 16:28:56 -04:00
|
|
|
<div class="divider"></div>
|
|
|
|
{#if images.length > 0}
|
|
|
|
<h1 class="font-semibold text-xl">My Images</h1>
|
|
|
|
{:else}
|
|
|
|
<h1 class="font-semibold text-xl">No Images</h1>
|
|
|
|
{/if}
|
|
|
|
<div class="flex flex-wrap gap-2 mt-2">
|
2024-08-17 11:12:15 -04:00
|
|
|
{#each images as image}
|
2024-08-17 16:28:56 -04:00
|
|
|
<div class="relative h-32 w-32">
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
class="absolute top-0 left-0 btn btn-error btn-sm z-10"
|
|
|
|
on:click={() => removeImage(image.id)}
|
|
|
|
>
|
|
|
|
X
|
|
|
|
</button>
|
|
|
|
<img src={image.image} alt={image.id} class="w-full h-full object-cover" />
|
|
|
|
</div>
|
2024-08-17 11:12:15 -04:00
|
|
|
{/each}
|
2024-08-15 21:29:36 -04:00
|
|
|
</div>
|
2024-08-17 11:12:15 -04:00
|
|
|
</div>
|
|
|
|
<div class="mt-4">
|
|
|
|
<button type="button" class="btn btn-primary" on:click={saveAndClose}>Close</button>
|
|
|
|
</div>
|
|
|
|
{/if}
|
2024-08-18 09:15:59 -04:00
|
|
|
{#if adventure.is_public && adventure.id}
|
|
|
|
<div class="bg-neutral p-4 mt-2 rounded-md shadow-sm">
|
|
|
|
<p class=" font-semibold">Share this Adventure!</p>
|
|
|
|
<div class="flex items-center justify-between">
|
|
|
|
<p class="text-card-foreground font-mono">
|
|
|
|
{window.location.origin}/adventures/{adventure.id}
|
|
|
|
</p>
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
on:click={() => {
|
|
|
|
navigator.clipboard.writeText(`${window.location.origin}/adventures/${adventure.id}`);
|
|
|
|
}}
|
|
|
|
class="inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 h-10 px-4 py-2"
|
|
|
|
>
|
|
|
|
Copy Link
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{/if}
|
2024-07-08 11:44:39 -04:00
|
|
|
</div>
|
|
|
|
</dialog>
|