* Add Actions to ViewModel utility types and specify `this: void` signature Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Add https://typescript-eslint.io/rules/unbound-method/ linter to shared-components also fix stray lint config which doesn't apply to SC Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Add https://typescript-eslint.io/rules/unbound-method/ linter to element-web Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Fix genuine issues identified by the linter Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Specify this:void on i18napi Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Update Module API Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Add comment for MapToVoidThis Added utility type to map VM actions to unbound functions. --------- Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
78 lines
2.3 KiB
TypeScript
78 lines
2.3 KiB
TypeScript
/*
|
|
Copyright 2024 New Vector Ltd.
|
|
Copyright 2019 Michael Telatynski <7t3chguy@gmail.com>
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
|
Please see LICENSE files in the repository root for full details.
|
|
*/
|
|
|
|
import React from "react";
|
|
|
|
import { _t } from "../../../languageHandler";
|
|
import { type Command, CommandCategories, Commands } from "../../../slash-commands/SlashCommands";
|
|
import InfoDialog from "./InfoDialog";
|
|
import { MatrixClientPeg } from "../../../MatrixClientPeg";
|
|
|
|
/**
|
|
* Props for {@link SlashCommandHelpDialog}
|
|
* @param roomId - The room ID to check whether commands are enabled
|
|
* @param onFinished - Callback called when the dialog is closed
|
|
*/
|
|
interface IProps {
|
|
roomId: string;
|
|
onFinished(this: void): void;
|
|
}
|
|
|
|
const SlashCommandHelpDialog: React.FC<IProps> = ({ roomId, onFinished }) => {
|
|
const categories: Record<string, Command[]> = {};
|
|
Commands.forEach((cmd) => {
|
|
if (!cmd.isEnabled(MatrixClientPeg.get(), roomId)) return;
|
|
if (!categories[cmd.category]) {
|
|
categories[cmd.category] = [];
|
|
}
|
|
categories[cmd.category].push(cmd);
|
|
});
|
|
|
|
const body = Object.values(CommandCategories)
|
|
.filter((c) => categories[c])
|
|
.map((category) => {
|
|
const rows = [
|
|
<tr key={"_category_" + category} className="mx_SlashCommandHelpDialog_headerRow">
|
|
<td colSpan={3}>
|
|
<h2>{_t(category)}</h2>
|
|
</td>
|
|
</tr>,
|
|
];
|
|
|
|
categories[category].forEach((cmd) => {
|
|
rows.push(
|
|
<tr key={cmd.command}>
|
|
<td>
|
|
<strong>{cmd.getCommand()}</strong>
|
|
</td>
|
|
<td>{cmd.args}</td>
|
|
<td>{_t(cmd.description)}</td>
|
|
</tr>,
|
|
);
|
|
});
|
|
|
|
return rows;
|
|
});
|
|
|
|
return (
|
|
<InfoDialog
|
|
className="mx_SlashCommandHelpDialog"
|
|
title={_t("slash_command|help_dialog_title")}
|
|
description={
|
|
<table>
|
|
<tbody>{body}</tbody>
|
|
</table>
|
|
}
|
|
hasCloseButton={true}
|
|
onFinished={onFinished}
|
|
/>
|
|
);
|
|
};
|
|
|
|
export default SlashCommandHelpDialog;
|