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

29 lines
794 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";
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-08 00:24:03 -05:00
const note = await getNote(context.params.id);
if (!note) throw "unable to fetch from database";
2022-09-30 15:14:57 -05:00
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 (
2022-10-11 17:12:32 -05:00
<>
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>
2022-10-11 17:12:32 -05:00
</>
2022-09-30 15:14:57 -05:00
);
}