Skip to content

Commit

Permalink
fix: menu action handling bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ephrimlawrence committed Jun 28, 2024
1 parent d43bdc3 commit 4c1223f
Show file tree
Hide file tree
Showing 5 changed files with 216 additions and 208 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"simulate": "tsx src/cli/simulator.ts",
"bundle": "npm run build && npm run prebuild && tsup",
"prebuild": "rimraf dist",
"format": "biome format --write ./src ./tests"
"format": "biome format --write ./src ./tests",
"biome": "biome"
},
"bin": {
"simulator": "dist/cli/simulator.js"
Expand Down
2 changes: 1 addition & 1 deletion src/core/pagination_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class PaginationHandler {
});

// No more actions, return pagination tree
if (actions.length == 0) {
if (actions.length === 0) {
return opts.pages;
}

Expand Down
24 changes: 12 additions & 12 deletions src/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {
import type {
BaseMenu,
DynamicMenu,
Menu,
MenuAction,
ValidationResponse,
} from "@src/menus";
import { State } from "@src/models";
import { FormInput } from "@src/types";
import { Request, Response } from "@src/types/request";
import type { State } from "@src/models";
import type { FormInput, Null } from "@src/types";
import type { Request, Response } from "@src/types/request";
import { SupportedGateway } from "./constants";
import { menuType } from "./menu.helper";

Expand All @@ -27,8 +27,8 @@ export async function validateInput(opts: {
let resp: { error: string | undefined; valid: boolean } = {
valid: true,
error: undefined,
},
status: ValidationResponse = true;
};
let status: ValidationResponse = true;

if (menu != null) {
if (menuType(menu) == "class") {
Expand Down Expand Up @@ -80,8 +80,8 @@ export async function buildUserResponse(opts: {

// TODO: build paginated response

let message: string | undefined = undefined;
if (menuType(menu!) == "class") {
let message: string | Null = undefined;
if (menuType(menu!) === "class") {
message = await (menu as unknown as BaseMenu).message();
} else {
message = await (menu as DynamicMenu).getMessage(request, response);
Expand All @@ -96,7 +96,7 @@ export async function buildUserResponse(opts: {
let actions: MenuAction[] | undefined = opts.actions;

if (actions == null) {
if (menuType(menu!) == "class") {
if (menuType(menu!) === "class") {
actions = (await (menu as unknown as BaseMenu).actions()) || [];
} else {
actions = await (menu as DynamicMenu).getActions();
Expand All @@ -106,10 +106,10 @@ export async function buildUserResponse(opts: {
for await (const action of actions) {
if (action.display == null) continue;

if (typeof action.display == "function") {
message += "\n" + (await action.display(this.request, this.response));
if (typeof action.display === "function") {
message += `\n${await action.display(request, response)}`;
} else {
message += "\n" + action.display || "";
message += `\n${action.display}`;
}
}

Expand Down
Loading

0 comments on commit 4c1223f

Please sign in to comment.