2022-09-27 15:49:41 -05:00
|
|
|
import { Handlers, PageProps } from "$fresh/server.ts";
|
2022-10-07 23:22:35 -05:00
|
|
|
import { listNotes } from "@/db/mod.ts";
|
|
|
|
import { type Note } from "@/types.ts";
|
2022-10-08 02:53:13 -05:00
|
|
|
import { NoteItem } from "@/components/Note.tsx";
|
2022-09-27 15:49:41 -05:00
|
|
|
|
2022-09-30 15:14:57 -05:00
|
|
|
export const handler: Handlers<Note[]> = {
|
2022-10-05 17:02:21 -05:00
|
|
|
async GET(_request, context) {
|
2022-10-08 00:24:03 -05:00
|
|
|
return await context.render(await listNotes() || []);
|
2022-09-27 15:49:41 -05:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2022-09-30 15:14:57 -05:00
|
|
|
export default function NotesPage({ data: notes }: PageProps<Note[]>) {
|
2022-09-27 15:49:41 -05:00
|
|
|
return (
|
2022-10-11 17:12:32 -05:00
|
|
|
<>
|
2022-09-29 20:22:30 -05:00
|
|
|
<h1>List of Notes</h1>
|
|
|
|
<p>Create a note:</p>
|
2022-09-30 15:14:57 -05:00
|
|
|
<form class="flex flex-col" action="./note/create" method="POST">
|
2022-10-01 14:03:15 -05:00
|
|
|
<textarea rows={6} class="" name="content">
|
2022-09-30 15:14:57 -05:00
|
|
|
</textarea>
|
2022-10-01 14:03:15 -05:00
|
|
|
<input class="mt-2" type="submit" value="Post" />
|
2022-09-29 20:22:30 -05:00
|
|
|
</form>
|
2022-10-08 02:53:13 -05:00
|
|
|
{notes.map(NoteItem)}
|
2022-10-11 17:12:32 -05:00
|
|
|
</>
|
2022-09-27 15:49:41 -05:00
|
|
|
);
|
|
|
|
}
|