28 lines
751 B
TypeScript
28 lines
751 B
TypeScript
import { Handlers, PageProps } from "$fresh/server.ts";
|
|
import { Database, Option } from "types";
|
|
import Msg from "components/Msg.tsx";
|
|
import { get_db_obj } from "db";
|
|
|
|
export const handler: Handlers<Option<Database>> = {
|
|
async GET(_, ctx) {
|
|
const db = await get_db_obj();
|
|
if (db.isNone() || !db.unwrap().messages[ctx.params.message_id]) {
|
|
return ctx.renderNotFound();
|
|
}
|
|
return ctx.render(db);
|
|
},
|
|
};
|
|
|
|
export default function MessagePreview({
|
|
data,
|
|
params,
|
|
}: PageProps<Option<Database>>) {
|
|
if (
|
|
data.isSome() &&
|
|
params.message_id &&
|
|
data.unwrap().messages[params.message_id]
|
|
) {
|
|
return <Msg message={params.message_id} db={data.unwrap()} />;
|
|
}
|
|
}
|