ls-deno/routes/note/[id].tsx

31 lines
894 B
TypeScript
Raw Normal View History

2022-09-30 15:14:57 -05:00
import { Handlers, PageProps } from "$fresh/server.ts";
2022-10-07 23:22:35 -05:00
import { getNote } from "@/db/mod.ts";
2022-10-07 14:13:45 -05:00
import { Page } from "@/components/Page.tsx";
2022-10-07 23:22:35 -05:00
import { type Note } from "@/types.ts";
2022-09-30 15:14:57 -05:00
export const handler: Handlers<Note> = {
async GET(request, context) {
console.debug({ request, context });
2022-10-07 23:22:35 -05:00
const result = await getNote(context.params.id);
if (!result) throw "unable to fetch from database";
2022-09-30 15:14:57 -05:00
const [note] = result.rows as Note[];
return await context.render(note);
},
};
export default function NotesPage(
2022-10-07 23:22:35 -05:00
{ data: { id, createdAt, content } }: PageProps<Note>,
2022-09-30 15:14:57 -05:00
) {
return (
<Page>
2022-10-07 23:22:35 -05:00
<a href="/note">Back to notes</a>
<h1>Note {id} created at {createdAt.toLocaleString()}</h1>
2022-09-30 15:14:57 -05:00
<div class="my-4" key={id}>
<blockquote class="mt-2 pl-4 border-l(solid 4)">
<pre>{content}</pre>
</blockquote>
</div>
</Page>
);
}