2019-08-06 18:03:38 +01:00
|
|
|
/*
|
2024-09-09 14:57:16 +01:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2019-08-06 18:03:38 +01:00
|
|
|
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.
|
2019-08-06 18:03:38 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
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";
|
2023-06-14 13:49:18 +01:00
|
|
|
import { MatrixClientPeg } from "../../../MatrixClientPeg";
|
2019-08-06 18:03:38 +01:00
|
|
|
|
2023-02-28 10:31:48 +00:00
|
|
|
interface IProps {
|
|
|
|
|
onFinished(): void;
|
|
|
|
|
}
|
2019-08-06 18:03:38 +01:00
|
|
|
|
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[]> = {};
|
2020-03-30 13:59:08 +01:00
|
|
|
Commands.forEach((cmd) => {
|
2023-06-14 13:49:18 +01:00
|
|
|
if (!cmd.isEnabled(MatrixClientPeg.get())) return;
|
2019-08-06 18:03:38 +01:00
|
|
|
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}>
|
2021-07-19 22:43:11 +01:00
|
|
|
<h2>{_t(category)}</h2>
|
2019-08-06 18:03:38 +01:00
|
|
|
</td>
|
|
|
|
|
</tr>,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
categories[category].forEach((cmd) => {
|
|
|
|
|
rows.push(
|
|
|
|
|
<tr key={cmd.command}>
|
2021-07-19 22:43:11 +01:00
|
|
|
<td>
|
|
|
|
|
<strong>{cmd.getCommand()}</strong>
|
|
|
|
|
</td>
|
|
|
|
|
<td>{cmd.args}</td>
|
2024-10-01 13:33:07 +01:00
|
|
|
<td>{_t(cmd.description)}</td>
|
2019-08-06 18:03:38 +01:00
|
|
|
</tr>,
|
|
|
|
|
);
|
2022-12-12 12:24:14 +01:00
|
|
|
});
|
|
|
|
|
|
2019-08-06 18:03:38 +01:00
|
|
|
return rows;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<InfoDialog
|
|
|
|
|
className="mx_SlashCommandHelpDialog"
|
2023-10-03 19:17:26 +01:00
|
|
|
title={_t("slash_command|help_dialog_title")}
|
2019-08-06 18:03:38 +01:00
|
|
|
description={
|
|
|
|
|
<table>
|
|
|
|
|
<tbody>{body}</tbody>
|
|
|
|
|
</table>
|
|
|
|
|
}
|
|
|
|
|
hasCloseButton={true}
|
|
|
|
|
onFinished={onFinished}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
};
|
2021-09-05 11:58:38 +02:00
|
|
|
|
|
|
|
|
export default SlashCommandHelpDialog;
|