Compare commits
3 Commits
1eb42c7a18
...
c5d689a9a8
| Author | SHA1 | Date | |
|---|---|---|---|
| c5d689a9a8 | |||
| f557360105 | |||
| caf6eabe32 |
@@ -1,30 +1,52 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { CalendarDate } from "@internationalized/date";
|
import { CalendarDate } from "@internationalized/date";
|
||||||
import { onMount } from "svelte";
|
import { onMount } from "svelte";
|
||||||
|
import { formatDate } from "$lib/date";
|
||||||
|
import { createEntry, updateEntry, deleteEntry } from "$lib/upload.ts";
|
||||||
|
|
||||||
let {
|
let {
|
||||||
dateValue = $bindable<CalendarDate | undefined>(
|
dateValue = $bindable<CalendarDate | undefined>(
|
||||||
new CalendarDate(2026, 2, 1),
|
new CalendarDate(2026, 2, 1),
|
||||||
),
|
),
|
||||||
} = $props()
|
} = $props();
|
||||||
|
|
||||||
let edit = $state(false)
|
let edit = $state<boolean>(false);
|
||||||
|
|
||||||
let entry = $state({
|
let entry = $state({
|
||||||
date: dateValue.toString(),
|
date: dateValue.toString(),
|
||||||
image: "",
|
image: "",
|
||||||
content: ""
|
content: "",
|
||||||
})
|
});
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
const res = await fetch(`/api/entry?date=${dateValue.toString()}`)
|
const res = await fetch(`/api/entry?date=${dateValue.toString()}`);
|
||||||
const data = await res.json()
|
const data = await res.json();
|
||||||
entry = data
|
if (data) {
|
||||||
})
|
entry = { date: dateValue.toString(), ...data[0] };
|
||||||
|
}
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{JSON.stringify(entry)}
|
<div class="flex flex-row items-center justify-between">
|
||||||
|
<h1 class="text-3xl">{formatDate(entry.date)}</h1>
|
||||||
|
|
||||||
<!-- <div class="flex flex-row items-center justify-between"> -->
|
{#if !edit}
|
||||||
<h1 class="text-3xl">{entry["date"]}</h1>
|
<button
|
||||||
<!-- </div> -->
|
class="btn bg-secondary py-2 px-3 rounded-lg hover:opacity-60 transition-brightness"
|
||||||
|
onclick={() => (edit = !edit)}>Edit</button
|
||||||
|
>
|
||||||
|
{:else}
|
||||||
|
<button class="bg-destructive py-2 px-3 rounded-lg" onclick={deleteEntry}>
|
||||||
|
delete
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
class="bg-secondary py-2 px-3 rounded-lg"
|
||||||
|
onclick={() => (edit = false)}
|
||||||
|
>
|
||||||
|
cancel
|
||||||
|
</button>
|
||||||
|
<button class="bg-primary text-accent py-2 px-3 rounded-lg">
|
||||||
|
save
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|||||||
@@ -55,3 +55,19 @@ export async function updateEntry(entry) {
|
|||||||
body: JSON.stringify(entry),
|
body: JSON.stringify(entry),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function deleteEntry(entry) {
|
||||||
|
const res = await fetch(`/api/entry/delete`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ id: entry.id })
|
||||||
|
});
|
||||||
|
|
||||||
|
if (res.ok) {
|
||||||
|
entry = null;
|
||||||
|
} else {
|
||||||
|
alert('Failed to delete entry');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,14 +1,56 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
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";
|
||||||
|
|
||||||
let { children } = $props();
|
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([])
|
||||||
|
|
||||||
|
onMount(async () => {
|
||||||
|
const res = await fetch(
|
||||||
|
`/api/entry?month=${dateValue.year}-${dateValue.month}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
entries = await res.json()
|
||||||
|
});
|
||||||
|
|
||||||
|
$effect(() => {
|
||||||
|
goto(`/${dateValue}`)
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:head><link rel="icon" href={favicon} /></svelte:head>
|
<svelte:head><link rel="icon" href={favicon} /></svelte:head>
|
||||||
|
<ModeWatcher />
|
||||||
|
|
||||||
<div class="md:max-w-3/4 mx-auto">
|
<div
|
||||||
<ModeWatcher />
|
class="flex flex-col md:flex-row space-y-4 w-full mt-6 mx-auto md:max-w-3/4"
|
||||||
{@render children()}
|
>
|
||||||
</div>
|
<div class="md:w-1/2 md:order-2">
|
||||||
|
<Header />
|
||||||
|
|
||||||
|
{#key dateValue}
|
||||||
|
<!-- <Editor {dateValue} /> -->
|
||||||
|
{@render children()}
|
||||||
|
{/key}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="md:w-1/2 lg:max-w-1/4 space-y-4 md:mr-4">
|
||||||
|
<Calendar bind:value={dateValue} />
|
||||||
|
<ul class="space-y-4">
|
||||||
|
{#each entries as entry}
|
||||||
|
<EntrySummaryView
|
||||||
|
{entry}
|
||||||
|
bind:value={dateValue}
|
||||||
|
/>
|
||||||
|
{/each}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -13,8 +13,14 @@
|
|||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<!-- <Editor {dateValue} /> -->
|
||||||
|
|
||||||
<div class="flex flex-col md:flex-row space-y-4 w-full mt-6">
|
<div>
|
||||||
|
Click on a date to view or edit an entry.
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- <div class="flex flex-col md:flex-row space-y-4 w-full mt-6">
|
||||||
<div class="md:w-1/2 md:order-2">
|
<div class="md:w-1/2 md:order-2">
|
||||||
<Header />
|
<Header />
|
||||||
|
|
||||||
@@ -23,7 +29,7 @@
|
|||||||
{/key}
|
{/key}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="md:w-1/2 space-y-4 md:mr-4">
|
<div class="md:w-1/2 lg:max-w-1/4 space-y-4 md:mr-4">
|
||||||
<Calendar bind:value={dateValue} />
|
<Calendar bind:value={dateValue} />
|
||||||
<ul class="space-y-4">
|
<ul class="space-y-4">
|
||||||
{#each data.all as entry}
|
{#each data.all as entry}
|
||||||
@@ -34,4 +40,4 @@
|
|||||||
{/each}
|
{/each}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div> -->
|
||||||
|
|||||||
8
src/routes/[date]/+page.svelte
Normal file
8
src/routes/[date]/+page.svelte
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
|
||||||
|
let {
|
||||||
|
data
|
||||||
|
} = $props()
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{JSON.stringify(data)}
|
||||||
6
src/routes/[date]/+page.ts
Normal file
6
src/routes/[date]/+page.ts
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
export async function load({ params, fetch }) {
|
||||||
|
const res = await fetch(`/api/entry?date=${params.date}`);
|
||||||
|
const entries = await res.json();
|
||||||
|
return { entries };
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user