Files
ThreadNet-Web/src/components/views/dialogs/SlashCommandHelpDialog.tsx
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

72 lines
2.1 KiB
TypeScript
Raw Normal View History

/*
2024-09-09 14:57:16 +01:00
Copyright 2024 New Vector Ltd.
Copyright 2019 Michael Telatynski <7t3chguy@gmail.com>
2024-09-09 14:57:16 +01:00
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
Please see LICENSE files in the repository root for full details.
*/
import React from "react";
2021-10-22 17:23:32 -05:00
2021-06-29 13:11:58 +01:00
import { _t } from "../../../languageHandler";
2023-02-13 11:39:16 +00:00
import { Command, CommandCategories, Commands } from "../../../SlashCommands";
2021-09-05 11:58:38 +02:00
import InfoDialog from "./InfoDialog";
import { MatrixClientPeg } from "../../../MatrixClientPeg";
interface IProps {
onFinished(): void;
}
2021-09-05 11:58:38 +02:00
const SlashCommandHelpDialog: React.FC<IProps> = ({ onFinished }) => {
2023-02-13 11:39:16 +00:00
const categories: Record<string, Command[]> = {};
Commands.forEach((cmd) => {
if (!cmd.isEnabled(MatrixClientPeg.get())) 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>,
);
2022-12-12 12:24:14 +01:00
});
return rows;
});
return (
<InfoDialog
className="mx_SlashCommandHelpDialog"
title={_t("slash_command|help_dialog_title")}
description={
<table>
<tbody>{body}</tbody>
</table>
}
hasCloseButton={true}
onFinished={onFinished}
/>
);
};
2021-09-05 11:58:38 +02:00
export default SlashCommandHelpDialog;