Page MenuHomeSealhub

page.ts
No OneTemporary

import Router from "@koa/router";
import { Context } from "koa";
import { FlatTemplatable, tempstream } from "tempstream";
import type { FormDataValue } from "../forms/form-types.js";
import {
Fields,
MountableWithFields,
PageErrorMessage,
} from "./mountable-with-fields.js";
import { AllQueryParams, PagePropsParser } from "./props-parser.js";
export abstract class Page<
F extends Fields = Record<string, never>
> extends MountableWithFields<F> {
propsParser: PagePropsParser<Record<keyof Fields, unknown>> =
new AllQueryParams();
controls = [];
mount(router: Router, path: string): void {
router.get(path, async (ctx) => {
ctx.body = await this.render(ctx);
});
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async canAccess(_: Context) {
return { canAccess: true, message: "" };
}
async renderError(
_: Context,
error: PageErrorMessage
): Promise<FlatTemplatable> {
return tempstream/* HTML */ `<div>${error.message}</div>`;
}
public abstract render(ctx: Context): Promise<FlatTemplatable>;
async extractRawValues(
ctx: Context
): Promise<Record<string, FormDataValue>> {
return this.propsParser.decode(ctx) || {};
}
}

File Metadata

Mime Type
text/x-java
Expires
Thu, Jan 23, 19:19 (1 d, 1 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
599874
Default Alt Text
page.ts (1 KB)

Event Timeline