ls-deno/routes/note.tsx
2022-10-11 17:12:32 -05:00

26 lines
737 B
TypeScript

import { Handlers, PageProps } from "$fresh/server.ts";
import { listNotes } from "@/db/mod.ts";
import { type Note } from "@/types.ts";
import { NoteItem } from "@/components/Note.tsx";
export const handler: Handlers<Note[]> = {
async GET(_request, context) {
return await context.render(await listNotes() || []);
},
};
export default function NotesPage({ data: notes }: PageProps<Note[]>) {
return (
<>
<h1>List of Notes</h1>
<p>Create a note:</p>
<form class="flex flex-col" action="./note/create" method="POST">
<textarea rows={6} class="" name="content">
</textarea>
<input class="mt-2" type="submit" value="Post" />
</form>
{notes.map(NoteItem)}
</>
);
}