diff --git a/frontend/src/lib/components/ChecklistCard.svelte b/frontend/src/lib/components/ChecklistCard.svelte index 89a0c6c..1cdd979 100644 --- a/frontend/src/lib/components/ChecklistCard.svelte +++ b/frontend/src/lib/components/ChecklistCard.svelte @@ -38,7 +38,7 @@ {checklist.name} -
Checklist
+
Checklist
{#if checklist.items.length > 0}

{checklist.items.length} {checklist.items.length > 1 ? 'Items' : 'Item'}

{/if} diff --git a/frontend/src/lib/components/NoteCard.svelte b/frontend/src/lib/components/NoteCard.svelte index 2949254..656ffd9 100644 --- a/frontend/src/lib/components/NoteCard.svelte +++ b/frontend/src/lib/components/NoteCard.svelte @@ -39,7 +39,7 @@ {note.name} -
Note
+
Note
{#if note.links && note.links.length > 0}

{note.links.length} {note.links.length > 1 ? 'Links' : 'Link'}

{/if} diff --git a/frontend/src/lib/index.ts b/frontend/src/lib/index.ts index 701dd13..233dd3f 100644 --- a/frontend/src/lib/index.ts +++ b/frontend/src/lib/index.ts @@ -57,9 +57,10 @@ export function groupAdventuresByDate( ): Record { const groupedAdventures: Record = {}; + // Initialize all days in the range for (let i = 0; i < numberOfDays; i++) { const currentDate = new Date(startDate); - currentDate.setDate(startDate.getDate() + i); + currentDate.setUTCDate(startDate.getUTCDate() + i); const dateString = currentDate.toISOString().split('T')[0]; groupedAdventures[dateString] = []; } @@ -69,10 +70,14 @@ export function groupAdventuresByDate( const adventureDate = new Date(adventure.date).toISOString().split('T')[0]; if (adventure.end_date) { const endDate = new Date(adventure.end_date).toISOString().split('T')[0]; - const currentDate = new Date(startDate); + + // Loop through all days and include adventure if it falls within the range for (let i = 0; i < numberOfDays; i++) { - currentDate.setDate(startDate.getDate() + i); + const currentDate = new Date(startDate); + currentDate.setUTCDate(startDate.getUTCDate() + i); const dateString = currentDate.toISOString().split('T')[0]; + + // Include the current day if it falls within the adventure date range if (dateString >= adventureDate && dateString <= endDate) { if (groupedAdventures[dateString]) { groupedAdventures[dateString].push(adventure); @@ -80,6 +85,7 @@ export function groupAdventuresByDate( } } } else if (groupedAdventures[adventureDate]) { + // If there's no end date, add adventure to the start date only groupedAdventures[adventureDate].push(adventure); } } @@ -95,9 +101,10 @@ export function groupTransportationsByDate( ): Record { const groupedTransportations: Record = {}; + // Initialize all days in the range for (let i = 0; i < numberOfDays; i++) { const currentDate = new Date(startDate); - currentDate.setDate(startDate.getDate() + i); + currentDate.setUTCDate(startDate.getUTCDate() + i); const dateString = currentDate.toISOString().split('T')[0]; groupedTransportations[dateString] = []; } @@ -107,10 +114,14 @@ export function groupTransportationsByDate( const transportationDate = new Date(transportation.date).toISOString().split('T')[0]; if (transportation.end_date) { const endDate = new Date(transportation.end_date).toISOString().split('T')[0]; - const currentDate = new Date(startDate); + + // Loop through all days and include transportation if it falls within the range for (let i = 0; i < numberOfDays; i++) { - currentDate.setDate(startDate.getDate() + i); + const currentDate = new Date(startDate); + currentDate.setUTCDate(startDate.getUTCDate() + i); const dateString = currentDate.toISOString().split('T')[0]; + + // Include the current day if it falls within the transportation date range if (dateString >= transportationDate && dateString <= endDate) { if (groupedTransportations[dateString]) { groupedTransportations[dateString].push(transportation); @@ -118,6 +129,7 @@ export function groupTransportationsByDate( } } } else if (groupedTransportations[transportationDate]) { + // If there's no end date, add transportation to the start date only groupedTransportations[transportationDate].push(transportation); } } @@ -133,9 +145,10 @@ export function groupNotesByDate( ): Record { const groupedNotes: Record = {}; + // Initialize all days in the range for (let i = 0; i < numberOfDays; i++) { const currentDate = new Date(startDate); - currentDate.setDate(startDate.getDate() + i); + currentDate.setUTCDate(startDate.getUTCDate() + i); const dateString = currentDate.toISOString().split('T')[0]; groupedNotes[dateString] = []; } @@ -143,6 +156,8 @@ export function groupNotesByDate( notes.forEach((note) => { if (note.date) { const noteDate = new Date(note.date).toISOString().split('T')[0]; + + // Add note to the appropriate date group if it exists if (groupedNotes[noteDate]) { groupedNotes[noteDate].push(note); } @@ -159,18 +174,21 @@ export function groupChecklistsByDate( ): Record { const groupedChecklists: Record = {}; + // Initialize all days in the range for (let i = 0; i < numberOfDays; i++) { const currentDate = new Date(startDate); - currentDate.setDate(startDate.getDate() + i); + currentDate.setUTCDate(startDate.getUTCDate() + i); const dateString = currentDate.toISOString().split('T')[0]; groupedChecklists[dateString] = []; } checklists.forEach((checklist) => { if (checklist.date) { - const noteDate = new Date(checklist.date).toISOString().split('T')[0]; - if (groupedChecklists[noteDate]) { - groupedChecklists[noteDate].push(checklist); + const checklistDate = new Date(checklist.date).toISOString().split('T')[0]; + + // Add checklist to the appropriate date group if it exists + if (groupedChecklists[checklistDate]) { + groupedChecklists[checklistDate].push(checklist); } } }); diff --git a/frontend/src/routes/collections/[id]/+page.svelte b/frontend/src/routes/collections/[id]/+page.svelte index e4245c9..0bea574 100644 --- a/frontend/src/routes/collections/[id]/+page.svelte +++ b/frontend/src/routes/collections/[id]/+page.svelte @@ -487,30 +487,33 @@

{#each Array(numberOfDays) as _, i} - {@const currentDate = new Date(collection.start_date)} - {@const temp = currentDate.setDate(currentDate.getDate() + i)} - {@const dateString = currentDate.toISOString().split('T')[0]} - {@const dayAdventures = groupAdventuresByDate( - adventures, - new Date(collection.start_date), - numberOfDays - )[dateString]} - {@const dayTransportations = groupTransportationsByDate( - transportations, - new Date(collection.start_date), - numberOfDays - )[dateString]} - {@const dayNotes = groupNotesByDate(notes, new Date(collection.start_date), numberOfDays)[ - dateString - ]} - {@const dayChecklists = groupChecklistsByDate( - checklists, - new Date(collection.start_date), - numberOfDays - )[dateString]} + {@const startDate = new Date(collection.start_date)} + {@const tempDate = new Date(startDate.getTime())} + + {@const adjustedDate = new Date(tempDate.setUTCDate(tempDate.getUTCDate() + i))} + + {@const dateString = adjustedDate.toISOString().split('T')[0]} + + {@const dayAdventures = + groupAdventuresByDate(adventures, new Date(collection.start_date), numberOfDays)[ + dateString + ] || []} + + {@const dayTransportations = + groupTransportationsByDate(transportations, new Date(collection.start_date), numberOfDays)[ + dateString + ] || []} + + {@const dayNotes = + groupNotesByDate(notes, new Date(collection.start_date), numberOfDays)[dateString] || []} + + {@const dayChecklists = + groupChecklistsByDate(checklists, new Date(collection.start_date), numberOfDays)[ + dateString + ] || []}

- Day {i + 1} - {currentDate.toLocaleDateString(undefined, { timeZone: 'UTC' })} + Day {i + 1} - {adjustedDate.toLocaleDateString(undefined, { timeZone: 'UTC' })}

{#if dayAdventures.length > 0}