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> </script>
<div class="flex flex-row items-center justify-between"> <div class="flex flex-row items-center space-x-2">
<h1 class="text-3xl">{formatDate(entry.date)}</h1> <h1 class="text-3xl mr-auto">{formatDate(entry.date)}</h1>
{#if !edit} {#if !edit}
<button <button
@@ -36,17 +36,22 @@
onclick={() => (edit = !edit)}>Edit</button onclick={() => (edit = !edit)}>Edit</button
> >
{:else} {: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 delete
</button> </button>
<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)} onclick={() => (edit = false)}
> >
cancel cancel
</button> </button>
<button class="bg-primary text-accent py-2 px-3 rounded-lg">
save
</button>
{/if} {/if}
</div> </div>

View File

@@ -2,29 +2,30 @@
import "./layout.css"; import "./layout.css";
import favicon from "$lib/assets/favicon.svg"; import favicon from "$lib/assets/favicon.svg";
import { ModeWatcher } from "mode-watcher"; 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 Header from "$lib/components/header.svelte";
import Calendar from "$lib/components/calendar.svelte"; import Calendar from "$lib/components/calendar.svelte";
import EntrySummaryView from "$lib/components/entrySummaryView.svelte"; import EntrySummaryView from "$lib/components/entrySummaryView.svelte";
import { onMount } from "svelte";
import { goto } from "$app/navigation"; import { goto } from "$app/navigation";
let { children } = $props(); let { children, data } = $props();
let dateValue = $state(today(getLocalTimeZone())); let dateValue = $derived(data.date);
let entries = $state([]) let entries = $derived(data.entries);
onMount(async () => {
const res = await fetch(
`/api/entry?month=${dateValue.year}-${dateValue.month}`,
);
entries = await res.json()
});
$effect(() => { $effect(() => {
goto(`/${dateValue}`) // Navigate when dateValue changes
}) goto(`/${dateValue}`);
});
$effect(() => {
// Sync dateValue with data.date when it changes
dateValue = data.date;
});
</script> </script>
<svelte:head><link rel="icon" href={favicon} /></svelte:head> <svelte:head><link rel="icon" href={favicon} /></svelte:head>
@@ -37,7 +38,6 @@
<Header /> <Header />
{#key dateValue} {#key dateValue}
<!-- <Editor {dateValue} /> -->
{@render children()} {@render children()}
{/key} {/key}
</div> </div>
@@ -46,11 +46,8 @@
<Calendar bind:value={dateValue} /> <Calendar bind:value={dateValue} />
<ul class="space-y-4"> <ul class="space-y-4">
{#each entries as entry} {#each entries as entry}
<EntrySummaryView <EntrySummaryView {entry} bind:value={dateValue} />
{entry}
bind:value={dateValue}
/>
{/each} {/each}
</ul> </ul>
</div> </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"> <script lang="ts">
import Editor from "$lib/components/editor.svelte";
let { let {
data data
} = $props() } = $props()
</script> </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 }) { export async function load({ params, fetch }) {
const res = await fetch(`/api/entry?date=${params.date}`); const res = await fetch(`/api/entry?date=${params.date}`);
const entries = await res.json(); const entries = await res.json();
return { entries }; return { entry: entries[0] };
} }