diff --git a/src/lib/components/editor.svelte b/src/lib/components/editor.svelte index 04f35a5..b5201ce 100644 --- a/src/lib/components/editor.svelte +++ b/src/lib/components/editor.svelte @@ -27,8 +27,8 @@ }); -
-

{formatDate(entry.date)}

+
+

{formatDate(entry.date)}

{#if !edit} {:else} - + - {/if}
diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 8dd44ac..f2cb652 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -2,25 +2,32 @@ import "./layout.css"; import favicon from "$lib/assets/favicon.svg"; import { ModeWatcher } from "mode-watcher"; - import { today, getLocalTimeZone } from "@internationalized/date"; + import { CalendarDate, today, getLocalTimeZone } from "@internationalized/date"; import Header from "$lib/components/header.svelte"; import Calendar from "$lib/components/calendar.svelte"; import EntrySummaryView from "$lib/components/entrySummaryView.svelte"; - import { onMount } from "svelte"; import { goto } from "$app/navigation"; - let { children } = $props(); - let dateValue = $state(today(getLocalTimeZone())); - let entries = $state([]) + let { children, data } = $props(); + let dateValue = $derived(data.date); + let entries = $derived(data.entries) + + // async function fetchForMonth(d: CalendarDate) { + // const res = await fetch( + // `/api/entry?month=${d.year}-${dateValue.month}`, + // ); + + // return await res.json() + // } - onMount(async () => { - const res = await fetch( - `/api/entry?month=${dateValue.year}-${dateValue.month}`, - ); + // onMount(async () => { + // const res = await fetch( + // `/api/entry?month=${dateValue.year}-${dateValue.month}`, + // ); - entries = await res.json() - }); + // entries = await res.json() + // }); $effect(() => { goto(`/${dateValue}`) @@ -37,7 +44,6 @@
{#key dateValue} - {@render children()} {/key}
diff --git a/src/routes/+layout.ts b/src/routes/+layout.ts new file mode 100644 index 0000000..76e7c10 --- /dev/null +++ b/src/routes/+layout.ts @@ -0,0 +1,13 @@ +import { today, getLocalTimeZone } from "@internationalized/date"; + +export async function load({ params, fetch }) { + const dateValue = today(getLocalTimeZone()); + + const res = await fetch(`/api/entry?month=${dateValue.year}-${dateValue.month}`) + const entries = await res.json() + + return { + entries: entries, + date: dateValue + }; +} diff --git a/src/routes/+page.ts b/src/routes/+page.ts deleted file mode 100644 index 5b64fe7..0000000 --- a/src/routes/+page.ts +++ /dev/null @@ -1,13 +0,0 @@ -export const load = async ({ fetch, params }) => { - const res = await fetch("/api/entry/all"); - const allEntries = await res.json(); - - const today = new Date().toISOString().split('T')[0]; - const todayEntry = await fetch(`/api/entry?date=${today}`); - const todayEntryData = await todayEntry.json(); - - return { - all: allEntries, - today: todayEntryData, - }; -}; diff --git a/src/routes/[date]/+page.svelte b/src/routes/[date]/+page.svelte index 76ab1e3..f216e42 100644 --- a/src/routes/[date]/+page.svelte +++ b/src/routes/[date]/+page.svelte @@ -1,8 +1,16 @@ -{JSON.stringify(data)} \ No newline at end of file + +{#if data.entry.id} + +{:else} + No entry exists for {data.date} +{/if} + diff --git a/src/routes/[date]/+page.ts b/src/routes/[date]/+page.ts index ae596ca..86518e7 100644 --- a/src/routes/[date]/+page.ts +++ b/src/routes/[date]/+page.ts @@ -1,6 +1,6 @@ export async function load({ params, fetch }) { - const res = await fetch(`/api/entry?date=${params.date}`); - const entries = await res.json(); - return { entries }; + const res = await fetch(`/api/entry?date=${params.date}`); + const entries = await res.json(); + return { entry: entries }; }