From df2ce0191067b909317ed65efa06f2801e4a12da Mon Sep 17 00:00:00 2001 From: Sean Morley Date: Thu, 26 Dec 2024 21:56:14 -0500 Subject: [PATCH] Update note and checklist modals as well as add an unlinked state in the collection page for better organization --- .../src/lib/components/AdventureCard.svelte | 21 ++ .../src/lib/components/ChecklistCard.svelte | 23 +- .../src/lib/components/ChecklistModal.svelte | 272 +++++++++-------- .../src/lib/components/CollectionModal.svelte | 6 +- frontend/src/lib/components/NoteCard.svelte | 18 +- frontend/src/lib/components/NoteModal.svelte | 279 ++++++++++-------- frontend/src/lib/components/ShareModal.svelte | 18 +- .../lib/components/TransportationCard.svelte | 24 +- frontend/src/lib/types.ts | 2 +- frontend/src/locales/en.json | 4 + frontend/src/routes/collections/+page.svelte | 43 +-- .../src/routes/collections/[id]/+page.svelte | 76 ++--- 12 files changed, 460 insertions(+), 326 deletions(-) diff --git a/frontend/src/lib/components/AdventureCard.svelte b/frontend/src/lib/components/AdventureCard.svelte index da80e43..0d903ee 100644 --- a/frontend/src/lib/components/AdventureCard.svelte +++ b/frontend/src/lib/components/AdventureCard.svelte @@ -41,6 +41,24 @@ } } + let unlinked: boolean = false; + + // Reactive block to update `unlinked` when dependencies change + $: { + if (collection && collection?.start_date && collection.end_date) { + unlinked = adventure.visits.every((visit) => { + // Check if visit dates exist + if (!visit.start_date || !visit.end_date) return true; // Consider "unlinked" for incomplete visit data + + // Check if collection dates are completely outside this visit's range + const isBeforeVisit = collection.end_date && collection.end_date < visit.start_date; + const isAfterVisit = collection.start_date && collection.start_date > visit.end_date; + + return isBeforeVisit || isAfterVisit; + }); + } + } + async function deleteAdventure() { let res = await fetch(`/adventures/${adventure.id}?/delete`, { method: 'POST', @@ -140,6 +158,9 @@ {adventure.is_public ? $t('adventures.public') : $t('adventures.private')} + {#if unlinked} +
{$t('adventures.out_of_range')}
+ {/if} {#if adventure.location && adventure.location !== ''}
diff --git a/frontend/src/lib/components/ChecklistCard.svelte b/frontend/src/lib/components/ChecklistCard.svelte index e4d0ee2..13814dc 100644 --- a/frontend/src/lib/components/ChecklistCard.svelte +++ b/frontend/src/lib/components/ChecklistCard.svelte @@ -16,6 +16,24 @@ let isWarningModalOpen: boolean = false; + let unlinked: boolean = false; + + $: { + if (collection?.start_date && collection.end_date) { + const startOutsideRange = + checklist.date && + collection.start_date < checklist.date && + collection.end_date < checklist.date; + + const endOutsideRange = + checklist.date && + collection.start_date > checklist.date && + collection.end_date > checklist.date; + + unlinked = !!(startOutsideRange || endOutsideRange); + } + } + function editChecklist() { dispatch('edit', checklist); } @@ -61,6 +79,9 @@ {checklist.items.length > 1 ? $t('checklist.items') : $t('checklist.item')}

{/if} + {#if unlinked} +
{$t('adventures.out_of_range')}
+ {/if} {#if checklist.date && checklist.date !== ''}
@@ -71,7 +92,7 @@ - {#if checklist.user_id == user?.uuid || (collection && user && collection.shared_with.includes(user.uuid))} + {#if checklist.user_id == user?.uuid || (collection && user && collection.shared_with && collection.shared_with.includes(user.uuid))} -
- {#if items.length > 0} -
-

{$t('checklist.items')}

- {/if} - - {#each items as item, i} -
- - - + +
{$t('adventures.note')}
+ {#if unlinked} +
{$t('adventures.out_of_range')}
+ {/if} {#if note.links && note.links.length > 0}

{note.links.length} @@ -74,7 +90,7 @@ - {#if note.user_id == user?.uuid || (collection && user && collection.shared_with.includes(user.uuid))} + {#if note.user_id == user?.uuid || (collection && user && collection.shared_with && collection.shared_with.includes(user.uuid))} -

- {#if newNote.links.length > 0} -
    - {#each newNote.links as link, i} -
  • - {link} - -
  • - {/each} -
- {/if} + {$t('adventures.date_constrain')} + (constrainDates = !constrainDates)} + /> + {/if} + +
+ + +
+
+ {#if !isReadOnly} + + {:else if note} +

+
+ {@html renderMarkdown(note.content || '')} +
+ {/if} +
+ + + {#if !isReadOnly} +
+ + { + if (e.key === 'Enter') { + e.preventDefault(); + addLink(); + } + }} + /> + +
+ {/if} + + + {#if newNote.links.length > 0} + + {/if} + + + + {#if warning} - + {#if unlinked} +
{$t('adventures.out_of_range')}
+ {/if}
@@ -100,7 +122,7 @@
- {#if transportation.user_id == user?.uuid || (collection && user && collection.shared_with.includes(user.uuid))} + {#if transportation.user_id == user?.uuid || (collection && user && collection.shared_with && collection.shared_with.includes(user.uuid))}
{/if} {#if collection} - {#if data.user && data.user.uuid && (data.user.uuid == collection.user_id || collection.shared_with.includes(data.user.uuid)) && !collection.is_archived} + {#if data.user && data.user.uuid && (data.user.uuid == collection.user_id || (collection.shared_with && collection.shared_with.includes(data.user.uuid))) && !collection.is_archived}