mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-08-05 05:05:17 +02:00
feat: Add image upload functionality to adventure creation and editing
This commit is contained in:
parent
2acfc1defb
commit
0637ab2df6
3 changed files with 49 additions and 25 deletions
|
@ -83,16 +83,6 @@
|
|||
}
|
||||
}
|
||||
|
||||
async function searchImage() {
|
||||
try {
|
||||
const imageUrl = await getImage(newAdventure.name);
|
||||
newAdventure.imageUrl = imageUrl;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
// Handle the error
|
||||
}
|
||||
}
|
||||
|
||||
let activityInput: string = "";
|
||||
|
||||
function activitySetup() {
|
||||
|
@ -108,7 +98,11 @@
|
|||
</script>
|
||||
|
||||
{#if isImageModalOpen}
|
||||
<ImageModal on:submit={upload} on:close={() => (isImageModalOpen = false)} />
|
||||
<ImageModal
|
||||
name={newAdventure.name}
|
||||
on:submit={upload}
|
||||
on:close={() => (isImageModalOpen = false)}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
<dialog id="my_modal_1" class="modal">
|
||||
|
@ -188,7 +182,6 @@
|
|||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label for="rating">Image URL</label>
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-secondary"
|
||||
|
@ -196,6 +189,7 @@
|
|||
isImageModalOpen = true;
|
||||
}}
|
||||
>
|
||||
Upload Image
|
||||
</button>
|
||||
</div>
|
||||
|
||||
|
@ -211,9 +205,6 @@
|
|||
<button class="btn btn-secondary" on:click={generate}
|
||||
>Generate Description</button
|
||||
>
|
||||
<button class="btn btn-secondary" on:click={searchImage}
|
||||
>Search for Image</button
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
import { onMount } from "svelte";
|
||||
import { addActivityType, generateDescription, getImage } from "$lib";
|
||||
import AutoComplete from "./AutoComplete.svelte";
|
||||
import ImageModal from "./ImageModal.svelte";
|
||||
let modal: HTMLDialogElement;
|
||||
|
||||
console.log(adventureToEdit.id);
|
||||
|
@ -87,8 +88,24 @@
|
|||
// Handle the error
|
||||
}
|
||||
}
|
||||
|
||||
let isImageModalOpen: boolean = false;
|
||||
|
||||
function upload(e: CustomEvent<any>) {
|
||||
let key = e.detail;
|
||||
console.log("EE" + key);
|
||||
adventureToEdit.imageUrl = key;
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if isImageModalOpen}
|
||||
<ImageModal
|
||||
name={adventureToEdit.name}
|
||||
on:submit={upload}
|
||||
on:close={() => (isImageModalOpen = false)}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
<dialog id="my_modal_1" class="modal">
|
||||
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
|
||||
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
|
||||
|
@ -163,13 +180,15 @@
|
|||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label for="rating">Image URL</label>
|
||||
<input
|
||||
type="url"
|
||||
id="imageUrl"
|
||||
bind:value={adventureToEdit.imageUrl}
|
||||
class="input input-bordered w-full max-w-xs"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-secondary"
|
||||
on:click={() => {
|
||||
isImageModalOpen = true;
|
||||
}}
|
||||
>
|
||||
Upload Image
|
||||
</button>
|
||||
</div>
|
||||
<button class="btn btn-primary mr-4 mt-4" on:click={submit}>Save</button
|
||||
>
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
<script lang="ts">
|
||||
import { getImage } from "$lib";
|
||||
import { createEventDispatcher } from "svelte";
|
||||
import { onMount } from "svelte";
|
||||
let modal: HTMLDialogElement;
|
||||
export let name: string;
|
||||
|
||||
let viewType: string = "upload";
|
||||
|
||||
|
@ -89,6 +91,15 @@
|
|||
imageFile = target.files[0];
|
||||
}
|
||||
}
|
||||
|
||||
async function searchImage() {
|
||||
try {
|
||||
imageUrl = await getImage(name);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
// Handle the error
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<dialog id="my_modal_1" class="modal">
|
||||
|
@ -96,7 +107,7 @@
|
|||
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
|
||||
<div class="modal-box" role="dialog" on:keydown={handleKeydown} tabindex="0">
|
||||
<h3 class="font-bold text-lg">Image Upload</h3>
|
||||
<div class="join items-center justify-center flex">
|
||||
<div class="join items-center justify-center flex mb-8">
|
||||
<input
|
||||
class="join-item btn btn-neutral"
|
||||
type="radio"
|
||||
|
@ -114,7 +125,10 @@
|
|||
/>
|
||||
</div>
|
||||
{#if viewType == "url"}
|
||||
<form method="dialog" style="width: 100%;">
|
||||
<button class="btn btn-secondary" on:click={searchImage}
|
||||
>Search for Image</button
|
||||
>
|
||||
<form method="dialog" style="width: 100%;" class="mb-4">
|
||||
<div>
|
||||
<label for="rating">Image URL</label>
|
||||
<input
|
||||
|
@ -127,7 +141,7 @@
|
|||
</form>
|
||||
{/if}
|
||||
{#if viewType == "upload"}
|
||||
<form method="dialog" style="width: 100%;">
|
||||
<form method="dialog" style="width: 100%;" class="mb-4">
|
||||
<div>
|
||||
<label for="rating">Image Upload</label>
|
||||
<input
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue