From 17498121a35e50d9be98b6625d7919e86b6c9566 Mon Sep 17 00:00:00 2001 From: Sean Morley Date: Wed, 31 Jul 2024 11:01:41 -0400 Subject: [PATCH] refactor: Update date input fields with min and max values --- frontend/src/lib/components/EditAdventure.svelte | 5 +++++ .../src/lib/components/EditTransportation.svelte | 13 +++++++++++++ frontend/src/lib/components/NewAdventure.svelte | 6 +++++- .../src/lib/components/NewTransportation.svelte | 13 +++++++++++++ .../src/lib/components/TransportationCard.svelte | 2 +- frontend/src/routes/collections/[id]/+page.svelte | 8 ++++++++ 6 files changed, 45 insertions(+), 2 deletions(-) diff --git a/frontend/src/lib/components/EditAdventure.svelte b/frontend/src/lib/components/EditAdventure.svelte index 49f7d8f..9774a78 100644 --- a/frontend/src/lib/components/EditAdventure.svelte +++ b/frontend/src/lib/components/EditAdventure.svelte @@ -7,6 +7,9 @@ import { addToast } from '$lib/toasts'; let modal: HTMLDialogElement; + export let startDate: string | null = null; + export let endDate: string | null = null; + console.log(adventureToEdit.id); let originalName = adventureToEdit.name; @@ -202,6 +205,8 @@ type="date" id="date" name="date" + min={startDate || ''} + max={endDate || ''} bind:value={adventureToEdit.date} class="input input-bordered w-full max-w-xs mt-1" /> diff --git a/frontend/src/lib/components/EditTransportation.svelte b/frontend/src/lib/components/EditTransportation.svelte index ea90cd6..d304d4b 100644 --- a/frontend/src/lib/components/EditTransportation.svelte +++ b/frontend/src/lib/components/EditTransportation.svelte @@ -11,6 +11,17 @@ let originalName = transportationToEdit.name; + export let startDate: string | null = null; + export let endDate: string | null = null; + + let fullStartDate: string = ''; + let fullEndDate: string = ''; + + if (startDate && endDate) { + fullStartDate = `${startDate}T00:00`; + fullEndDate = `${endDate}T23:59`; + } + import MapMarker from '~icons/mdi/map-marker'; import Calendar from '~icons/mdi/calendar'; import Notebook from '~icons/mdi/notebook'; @@ -142,6 +153,8 @@ type="datetime-local" id="date" name="date" + min={fullStartDate || ''} + max={fullEndDate || ''} bind:value={transportationToEdit.date} class="input input-bordered w-full max-w-xs mt-1" /> diff --git a/frontend/src/lib/components/NewAdventure.svelte b/frontend/src/lib/components/NewAdventure.svelte index c0db3e1..851a0c3 100644 --- a/frontend/src/lib/components/NewAdventure.svelte +++ b/frontend/src/lib/components/NewAdventure.svelte @@ -24,7 +24,9 @@ import Wikipedia from '~icons/mdi/wikipedia'; import ActivityComplete from './ActivityComplete.svelte'; import { appVersion } from '$lib/config'; - import AdventureCard from './AdventureCard.svelte'; + + export let startDate: string | null = null; + export let endDate: string | null = null; let newAdventure: Adventure = { id: NaN, @@ -273,6 +275,8 @@ type="date" id="date" name="date" + min={startDate || ''} + max={endDate || ''} bind:value={newAdventure.date} class="input input-bordered w-full max-w-xs mt-1" /> diff --git a/frontend/src/lib/components/NewTransportation.svelte b/frontend/src/lib/components/NewTransportation.svelte index c6ce76d..a49b12b 100644 --- a/frontend/src/lib/components/NewTransportation.svelte +++ b/frontend/src/lib/components/NewTransportation.svelte @@ -33,6 +33,17 @@ import LinkVariant from '~icons/mdi/link-variant'; import Airplane from '~icons/mdi/airplane'; + export let startDate: string | null = null; + export let endDate: string | null = null; + + let fullStartDate: string = ''; + let fullEndDate: string = ''; + + if (startDate && endDate) { + fullStartDate = `${startDate}T00:00`; + fullEndDate = `${endDate}T23:59`; + } + let type: string = ''; onMount(async () => { @@ -163,6 +174,8 @@ type="datetime-local" id="date" name="date" + min={fullStartDate || ''} + max={fullEndDate || ''} class="input input-bordered w-full max-w-xs mt-1" /> diff --git a/frontend/src/lib/components/TransportationCard.svelte b/frontend/src/lib/components/TransportationCard.svelte index fbe7233..a27ea9a 100644 --- a/frontend/src/lib/components/TransportationCard.svelte +++ b/frontend/src/lib/components/TransportationCard.svelte @@ -52,7 +52,7 @@ {#if transportation.date} {new Date(transportation.date).toLocaleString()} {/if} - {#if user} + {#if user?.pk === transportation.user_id}
(isTransportationEditModalOpen = false)} on:saveEdit={saveNewTransportation} + startDate={collection.start_date} + endDate={collection.end_date} /> {/if} @@ -205,6 +207,8 @@ {adventureToEdit} on:close={() => (isEditModalOpen = false)} on:saveEdit={saveEdit} + startDate={collection.start_date} + endDate={collection.end_date} /> {/if} @@ -214,6 +218,8 @@ collection_id={collection.id} on:create={createAdventure} on:close={() => (isShowingCreateModal = false)} + startDate={collection.start_date} + endDate={collection.end_date} /> {/if} @@ -225,6 +231,8 @@ isShowingTransportationModal = false; }} {collection} + startDate={collection.start_date} + endDate={collection.end_date} /> {/if}