mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-08-05 21:25:19 +02:00
chore: Refactor AddFromFeatured component and add trip selection
This commit is contained in:
parent
cb2470070b
commit
fa5399e861
4 changed files with 69 additions and 29 deletions
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "adventurelog",
|
"name": "adventurelog",
|
||||||
"version": "0.1.6",
|
"version": "0.2.0",
|
||||||
"description": "Embark, Explore, Remember. 🌍",
|
"description": "Embark, Explore, Remember. 🌍",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
|
@ -3,26 +3,28 @@
|
||||||
import { createEventDispatcher } from "svelte";
|
import { createEventDispatcher } from "svelte";
|
||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher();
|
||||||
import { onMount } from "svelte";
|
import { onMount } from "svelte";
|
||||||
|
import TripListModal from "./TripListModal.svelte";
|
||||||
let modal: HTMLDialogElement;
|
let modal: HTMLDialogElement;
|
||||||
|
|
||||||
let trips: Trip[] = [];
|
|
||||||
|
|
||||||
export let adventure: Adventure;
|
export let adventure: Adventure;
|
||||||
|
|
||||||
|
let tripModal: boolean = false;
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
modal = document.getElementById("my_modal_1") as HTMLDialogElement;
|
modal = document.getElementById("my_modal_1") as HTMLDialogElement;
|
||||||
if (modal) {
|
if (modal) {
|
||||||
modal.showModal();
|
modal.showModal();
|
||||||
}
|
}
|
||||||
let res = await fetch("/api/trips");
|
|
||||||
trips = await res.json();
|
|
||||||
console.log(trips);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function close() {
|
function close() {
|
||||||
dispatch("close");
|
dispatch("close");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function openTripModal() {
|
||||||
|
tripModal = true;
|
||||||
|
}
|
||||||
|
|
||||||
function visited() {
|
function visited() {
|
||||||
dispatch("visited");
|
dispatch("visited");
|
||||||
close();
|
close();
|
||||||
|
@ -32,8 +34,8 @@
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
function trip(trip: Trip) {
|
function trip(event: CustomEvent<any>) {
|
||||||
dispatch("trip", trip);
|
dispatch("trip", event.detail);
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,6 +46,10 @@
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
{#if tripModal}
|
||||||
|
<TripListModal on:close={close} on:trip={trip} />
|
||||||
|
{/if}
|
||||||
|
|
||||||
<dialog id="my_modal_1" class="modal">
|
<dialog id="my_modal_1" class="modal">
|
||||||
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
|
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
|
||||||
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
|
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
|
||||||
|
@ -58,26 +64,9 @@
|
||||||
<button class="btn btn-primary mr-2" on:click={idea}
|
<button class="btn btn-primary mr-2" on:click={idea}
|
||||||
>Adventure Idea</button
|
>Adventure Idea</button
|
||||||
>
|
>
|
||||||
<details class="dropdown">
|
<button class="btn btn-primary mr-2" on:click={openTripModal}
|
||||||
<summary class="m-1 btn">Add to Trip</summary>
|
>Add to Trip</button
|
||||||
<ul
|
>
|
||||||
class="p-2 shadow menu dropdown-content z-[1] bg-base-100 rounded-box w-52"
|
|
||||||
>
|
|
||||||
{#each trips as trip}
|
|
||||||
<li>
|
|
||||||
<button
|
|
||||||
class="btn btn-primary"
|
|
||||||
on:click={() => {
|
|
||||||
dispatch("trip", trip);
|
|
||||||
close();
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{trip.name}
|
|
||||||
</button>
|
|
||||||
</li>
|
|
||||||
{/each}
|
|
||||||
</ul>
|
|
||||||
</details>
|
|
||||||
<div class="h-32"></div>
|
<div class="h-32"></div>
|
||||||
<button class="btn btn-neutral" on:click={close}>Close</button>
|
<button class="btn btn-neutral" on:click={close}>Close</button>
|
||||||
</div>
|
</div>
|
51
src/lib/components/TripListModal.svelte
Normal file
51
src/lib/components/TripListModal.svelte
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
<script lang="ts">
|
||||||
|
import { onMount } from "svelte";
|
||||||
|
import type { Trip } from "$lib/utils/types";
|
||||||
|
import { createEventDispatcher } from "svelte";
|
||||||
|
const dispatch = createEventDispatcher();
|
||||||
|
let modal: HTMLDialogElement;
|
||||||
|
let trips: Trip[] = [];
|
||||||
|
|
||||||
|
onMount(async () => {
|
||||||
|
modal = document.getElementById("my_modal_1") as HTMLDialogElement;
|
||||||
|
if (modal) {
|
||||||
|
modal.showModal();
|
||||||
|
}
|
||||||
|
let res = await fetch("/api/trips");
|
||||||
|
trips = await res.json();
|
||||||
|
console.log(trips);
|
||||||
|
});
|
||||||
|
|
||||||
|
function handleKeydown(event: KeyboardEvent) {
|
||||||
|
if (event.key === "Escape") {
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function close() {
|
||||||
|
dispatch("close");
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<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">Choose a trip</h3>
|
||||||
|
{#each trips as trip}
|
||||||
|
<li>
|
||||||
|
<button
|
||||||
|
class="btn btn-primary"
|
||||||
|
on:click={() => {
|
||||||
|
dispatch("trip", trip);
|
||||||
|
close();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{trip.name}
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
<!-- close button -->
|
||||||
|
<button class="btn btn-neutral" on:click={close}>Close</button>
|
||||||
|
</dialog>
|
|
@ -3,7 +3,7 @@
|
||||||
import { goto } from "$app/navigation";
|
import { goto } from "$app/navigation";
|
||||||
import AdventureCard from "$lib/components/AdventureCard.svelte";
|
import AdventureCard from "$lib/components/AdventureCard.svelte";
|
||||||
import type { Adventure, Trip } from "$lib/utils/types.js";
|
import type { Adventure, Trip } from "$lib/utils/types.js";
|
||||||
import AddFromFeatured from "$lib/components/AddFromFeatured.svelte";
|
import AddFromFeatured from "$lib/components/AddLocationChooser.svelte";
|
||||||
import { addAdventure } from "../../services/adventureService.js";
|
import { addAdventure } from "../../services/adventureService.js";
|
||||||
import SucessToast from "$lib/components/SucessToast.svelte";
|
import SucessToast from "$lib/components/SucessToast.svelte";
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue