/* 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 "../../../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(): void; } const SlashCommandHelpDialog: React.FC = ({ roomId, onFinished }) => { const categories: Record = {}; 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 = [

{_t(category)}

, ]; categories[category].forEach((cmd) => { rows.push( {cmd.getCommand()} {cmd.args} {_t(cmd.description)} , ); }); return rows; }); return ( {body} } hasCloseButton={true} onFinished={onFinished} /> ); }; export default SlashCommandHelpDialog;