diff --git a/src/lib/components/addEntryCover.svelte b/src/lib/components/addEntryCover.svelte
new file mode 100644
index 0000000..d0c7daa
--- /dev/null
+++ b/src/lib/components/addEntryCover.svelte
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/lib/components/editor/index.svelte b/src/lib/components/editor/index.svelte
index d4339c2..b894613 100644
--- a/src/lib/components/editor/index.svelte
+++ b/src/lib/components/editor/index.svelte
@@ -3,9 +3,8 @@
import TextEditor from "./textEditor.svelte";
import { formatDate } from "$lib/date.ts";
- let { entry = $bindable({}) } = $props();
+ let { entry = $bindable({}), edit = $bindable(false) } = $props();
- let edit = $state(false);
let editModeText = $derived(edit ? "done" : "edit")
diff --git a/src/lib/date.ts b/src/lib/date.ts
index f3ee89a..9e6319d 100644
--- a/src/lib/date.ts
+++ b/src/lib/date.ts
@@ -2,4 +2,8 @@ export const formatDate = (dateString: string) => {
const date = new Date(dateString);
const options = { year: "numeric", month: "long", day: "numeric" };
return date.toLocaleDateString(undefined, options);
-};
\ No newline at end of file
+};
+
+export const today = () => {
+ return new Date().toISOString().split('T')[0];
+}
\ No newline at end of file
diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte
index 1dfd2b3..8b011c4 100644
--- a/src/routes/+page.svelte
+++ b/src/routes/+page.svelte
@@ -6,14 +6,24 @@
import Calendar from '$lib/components/calendar.svelte'
import Editor from '$lib/components/editor/index.svelte';
import EntrySummaryView from '$lib/components/entrySummaryView.svelte'
+ import AddEntryCover from '$lib/components/addEntryCover.svelte'
+ import { today } from '$lib/date';
let edit = $state(false)
-
let selectedEntry = $state('')
+ let selectedDate = $state(today())
- let selectEntry = async (entryID: string) => {
- const res = await fetch(`/api/entry?id=${entryID}`)
- selectedEntry = await res.json()
+ let selectEntry = async (hasEntry: boolean, data: string | null) => {
+ console.log(data)
+ // data should be the entryID if hasEntry == true, or the date if there is no entry
+ if (hasEntry) {
+ const res = await fetch(`/api/entry?id=${data}`)
+ selectedEntry = await res.json()
+ selectedDate = selectedEntry.date
+ } else {
+ selectedEntry = ''
+ selectedDate = data as string
+ }
}
@@ -25,9 +35,7 @@
{#if selectedEntry}
{:else}
-
-
Select an entry to view/edit
-
+
{/if}
diff --git a/src/routes/+page.ts b/src/routes/+page.ts
index 2108dea..5b64fe7 100644
--- a/src/routes/+page.ts
+++ b/src/routes/+page.ts
@@ -1,8 +1,13 @@
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,
};
};