2024-03-31 00:49:42 +00:00
|
|
|
<script lang="ts">
|
|
|
|
export let editId:number = NaN;
|
|
|
|
export let editName:string = '';
|
|
|
|
export let editLocation:string = '';
|
|
|
|
export let editCreated: string = '';
|
|
|
|
import { createEventDispatcher } from 'svelte';
|
|
|
|
import type { Adventure } from '$lib/utils/types';
|
|
|
|
const dispatch = createEventDispatcher();
|
|
|
|
import { onMount } from 'svelte';
|
|
|
|
let modal: HTMLDialogElement;
|
|
|
|
|
2024-04-01 21:27:02 +00:00
|
|
|
let originalName = editName;
|
|
|
|
|
2024-03-31 00:49:42 +00:00
|
|
|
onMount(() => {
|
|
|
|
modal = document.getElementById("my_modal_1") as HTMLDialogElement;
|
|
|
|
if (modal) {
|
|
|
|
modal.showModal();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function submit() {
|
|
|
|
const adventureEdited: Adventure = { id: editId, name: editName, location: editLocation, created: editCreated };
|
|
|
|
dispatch('submit', adventureEdited);
|
|
|
|
console.log(adventureEdited)
|
|
|
|
}
|
|
|
|
|
|
|
|
function close() {
|
|
|
|
dispatch('close');
|
|
|
|
}
|
2024-04-01 21:27:02 +00:00
|
|
|
|
|
|
|
function handleKeydown(event: KeyboardEvent) {
|
|
|
|
if (event.key === 'Escape') {
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
}
|
2024-03-31 00:49:42 +00:00
|
|
|
</script>
|
|
|
|
|
2024-04-01 21:27:02 +00:00
|
|
|
<dialog id="my_modal_1" class="modal" >
|
|
|
|
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
|
|
|
|
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
|
|
|
|
<div class="modal-box" role="dialog" on:keydown={handleKeydown} tabindex="0">
|
|
|
|
<h3 class="font-bold text-lg">Edit Adventure {originalName}</h3>
|
2024-03-31 00:49:42 +00:00
|
|
|
<p class="py-4">Press ESC key or click the button below to close</p>
|
2024-04-02 21:46:37 +00:00
|
|
|
<div class="modal-action items-center" style="display: flex; flex-direction: column; align-items: center; width: 100%;">
|
|
|
|
<form method="dialog" style="width: 100%;">
|
|
|
|
<div>
|
|
|
|
<label for="name">Name</label>
|
|
|
|
<input type="text" id="name" bind:value={editName} class="input input-bordered w-full max-w-xs" />
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<label for="location">Location</label>
|
|
|
|
<input type="text" id="location" bind:value={editLocation} class="input input-bordered w-full max-w-xs" />
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<label for="created">Created</label>
|
|
|
|
<input type="date" id="created" bind:value={editCreated} class="input input-bordered w-full max-w-xs" />
|
|
|
|
</div>
|
|
|
|
<button class="btn btn-primary mr-4 mt-4" on:click={submit}>Save</button>
|
2024-03-31 00:49:42 +00:00
|
|
|
<!-- if there is a button in form, it will close the modal -->
|
2024-04-02 21:46:37 +00:00
|
|
|
<button class="btn mt-4" on:click={close}>Close</button>
|
2024-03-31 00:49:42 +00:00
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</dialog>
|