mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-08-04 20:55:19 +02:00
notes beta
This commit is contained in:
parent
b8994a531f
commit
4f1ad09470
8 changed files with 172 additions and 10 deletions
|
@ -67,6 +67,7 @@ export type Collection = {
|
|||
start_date?: string;
|
||||
end_date?: string;
|
||||
transportations?: Transportation[];
|
||||
notes?: Note[];
|
||||
};
|
||||
|
||||
export type OpenStreetMapPlace = {
|
||||
|
@ -103,3 +104,15 @@ export type Transportation = {
|
|||
created_at: string; // ISO 8601 date string
|
||||
updated_at: string; // ISO 8601 date string
|
||||
};
|
||||
|
||||
export type Note = {
|
||||
id: number;
|
||||
user_id: number;
|
||||
name: string;
|
||||
content: string | null;
|
||||
date: string | null; // ISO 8601 date string
|
||||
is_public: boolean;
|
||||
collection: Collection | null;
|
||||
created_at: string; // ISO 8601 date string
|
||||
updated_at: string; // ISO 8601 date string
|
||||
};
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<script lang="ts">
|
||||
import type { Adventure, Collection, Transportation } from '$lib/types';
|
||||
import type { Adventure, Collection, Note, Transportation } from '$lib/types';
|
||||
import { onMount } from 'svelte';
|
||||
import type { PageData } from './$types';
|
||||
import { goto } from '$app/navigation';
|
||||
|
@ -17,12 +17,14 @@
|
|||
import NewTransportation from '$lib/components/NewTransportation.svelte';
|
||||
|
||||
export let data: PageData;
|
||||
console.log(data);
|
||||
|
||||
let collection: Collection;
|
||||
|
||||
let adventures: Adventure[] = [];
|
||||
let numVisited: number = 0;
|
||||
let transportations: Transportation[] = [];
|
||||
let notes: Note[] = [];
|
||||
|
||||
let numberOfDays: number = NaN;
|
||||
|
||||
|
@ -52,6 +54,9 @@
|
|||
if (collection.transportations) {
|
||||
transportations = collection.transportations;
|
||||
}
|
||||
if (collection.notes) {
|
||||
notes = collection.notes;
|
||||
}
|
||||
});
|
||||
|
||||
function deleteAdventure(event: CustomEvent<number>) {
|
||||
|
@ -108,6 +113,28 @@
|
|||
return groupedTransportations;
|
||||
}
|
||||
|
||||
function groupNotesByDate(notes: Note[], startDate: Date): Record<string, Note[]> {
|
||||
const groupedNotes: Record<string, Note[]> = {};
|
||||
|
||||
for (let i = 0; i < numberOfDays; i++) {
|
||||
const currentDate = new Date(startDate);
|
||||
currentDate.setDate(startDate.getDate() + i);
|
||||
const dateString = currentDate.toISOString().split('T')[0];
|
||||
groupedNotes[dateString] = [];
|
||||
}
|
||||
|
||||
notes.forEach((note) => {
|
||||
if (note.date) {
|
||||
const noteDate = new Date(note.date).toISOString().split('T')[0];
|
||||
if (groupedNotes[noteDate]) {
|
||||
groupedNotes[noteDate].push(note);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return groupedNotes;
|
||||
}
|
||||
|
||||
function createAdventure(event: CustomEvent<Adventure>) {
|
||||
adventures = [event.detail, ...adventures];
|
||||
isShowingCreateModal = false;
|
||||
|
@ -454,6 +481,17 @@
|
|||
/>
|
||||
{/each}
|
||||
{/if}
|
||||
{#if notes.length > 0}
|
||||
{#each notes as note}
|
||||
{#if note.date && new Date(note.date).toISOString().split('T')[0] === dateString}
|
||||
<div class="bg-base-300 p-4 rounded-lg w-full">
|
||||
<p class="text-lg font-semibold">{note.name}</p>
|
||||
<p class="text-md">{note.date}</p>
|
||||
<p>{note.content}</p>
|
||||
</div>
|
||||
{/if}
|
||||
{/each}
|
||||
{/if}
|
||||
{#if dayAdventures.length == 0 && dayTransportations.length == 0}
|
||||
<p class="text-center text-lg mt-2">
|
||||
No adventures or transportaions planned for this day.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue