freshter-logs/routes/m/[message_id].tsx

43 lines
1.2 KiB
TypeScript
Raw Normal View History

2023-04-28 19:48:34 -04:00
import { Handlers, PageProps } from "$fresh/server.ts";
import { Database, Option } from "types";
import Msg from "components/Msg.tsx";
import { get_db_obj } from "db";
2023-04-28 20:20:05 -04:00
import Meta from "components/Meta.tsx";
import { msg_style } from "style";
2023-04-28 19:48:34 -04:00
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]
) {
2023-04-28 20:20:05 -04:00
const db = data.unwrap();
const id = params.message_id;
const msg = db.messages[id];
return (
<>
<Meta
title={`freshter log message #${id}`}
description={msg.content}
after_slash={`m/${id}`}
color={`${msg_style(msg, db).color ?? "black"}`}
></Meta>
<Msg message={id} db={db} />
</>
);
2023-04-28 19:48:34 -04:00
}
}