freshter-logs/routes/[conversation_id].tsx

33 lines
904 B
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 { get_db_obj } from "db";
import Conv from "components/Conv.tsx";
export const handler: Handlers<Option<Database>> = {
async GET(req, ctx) {
const db = await get_db_obj();
if (
db.isNone() ||
!db.unwrap().conversations[ctx.params.conversation_id]
) {
return ctx.renderNotFound();
}
return ctx.render(db);
},
};
export default function ConversationPreview({
data,
params,
}: PageProps<Option<Database>>) {
if (
data.isSome() &&
params.conversation_id &&
data.unwrap().conversations[params.conversation_id]
) {
return <Conv conv={params.conversation_id} db={data.unwrap()} />;
}
}
//TODO: keyboard shortcut (advertised elsewhere) that activates interactive mode