Compare commits

...

2 Commits

Author SHA1 Message Date
0b038f4dea okay working now, datevalue respects current page 2026-02-17 11:22:38 +13:00
1d6e5b5d4c Just need a checkpoint cos nothings working atm 2026-02-17 11:13:03 +13:00
6 changed files with 64 additions and 45 deletions

View File

@@ -27,8 +27,8 @@
});
</script>
<div class="flex flex-row items-center justify-between">
<h1 class="text-3xl">{formatDate(entry.date)}</h1>
<div class="flex flex-row items-center space-x-2">
<h1 class="text-3xl mr-auto">{formatDate(entry.date)}</h1>
{#if !edit}
<button
@@ -36,17 +36,22 @@
onclick={() => (edit = !edit)}>Edit</button
>
{:else}
<button class="bg-destructive py-2 px-3 rounded-lg" onclick={deleteEntry}>
<button
class="bg-destructive py-2 px-3 rounded-lg hover:opacity-60 transition-brightness"
onclick={deleteEntry}
>
delete
</button>
<button
class="bg-secondary py-2 px-3 rounded-lg"
class="bg-primary text-accent py-2 px-3 rounded-lg hover:opacity-60 transition-brightness"
>
save
</button>
<button
class="bg-secondary py-2 px-3 rounded-lg hover:opacity-60 transition-brightness"
onclick={() => (edit = false)}
>
cancel
</button>
<button class="bg-primary text-accent py-2 px-3 rounded-lg">
save
</button>
{/if}
</div>

View File

@@ -2,29 +2,30 @@
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);
onMount(async () => {
const res = await fetch(
`/api/entry?month=${dateValue.year}-${dateValue.month}`,
);
entries = await res.json()
});
$effect(() => {
goto(`/${dateValue}`)
})
// Navigate when dateValue changes
goto(`/${dateValue}`);
});
$effect(() => {
// Sync dateValue with data.date when it changes
dateValue = data.date;
});
</script>
<svelte:head><link rel="icon" href={favicon} /></svelte:head>
@@ -37,7 +38,6 @@
<Header />
{#key dateValue}
<!-- <Editor {dateValue} /> -->
{@render children()}
{/key}
</div>
@@ -46,11 +46,8 @@
<Calendar bind:value={dateValue} />
<ul class="space-y-4">
{#each entries as entry}
<EntrySummaryView
{entry}
bind:value={dateValue}
/>
<EntrySummaryView {entry} bind:value={dateValue} />
{/each}
</ul>
</div>
</div>
</div>

22
src/routes/+layout.ts Normal file
View File

@@ -0,0 +1,22 @@
import { today, getLocalTimeZone, CalendarDate } from "@internationalized/date";
export async function load({ params, fetch }) {
let dateValue;
if (params.date) {
const [year, month, day] = params.date.split("-").map(Number);
dateValue = new CalendarDate(year, month, day);
} else {
dateValue = today(getLocalTimeZone());
}
const res = await fetch(
`/api/entry?month=${dateValue.year}-${dateValue.month}`,
);
const entries = await res.json();
return {
entries: entries,
date: dateValue,
};
}

View File

@@ -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,
};
};

View File

@@ -1,8 +1,16 @@
<script lang="ts">
import Editor from "$lib/components/editor.svelte";
let {
data
} = $props()
</script>
{JSON.stringify(data)}
{#if data.entry}
<Editor dateValue={data.date} />
{:else}
No entry exists for {data.date}
{/if}

View File

@@ -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[0] };
}