freshter-logs/routes/[conversation_id]/i/index.tsx
2023-04-28 19:48:34 -04:00

34 lines
964 B
TypeScript

import { Handlers, PageProps } from "$fresh/server.ts";
import { Database, Option } from "types";
import { get_db_obj } from "db";
import Interactive from "../../../islands/Interactive.tsx";
export const handler: Handlers<Option<Database>> = {
async GET(req, ctx) {
const db = await get_db_obj();
if (
db.isNone() ||
(db.isSome() &&
!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 <Interactive conv={params.conversation_id} db={data.unwrap()} />;
}
}
//TODO: keyboard shortcut (advertised elsewhere) that activates interactive mode