Implement help menu command to show a help menu with the commands

This commit is contained in:
Jorge Manrubia
2025-05-07 17:21:38 +02:00
parent b7f086d361
commit 2503524b7a
6 changed files with 84 additions and 2 deletions
@@ -3,7 +3,7 @@ import { HttpStatus } from "helpers/http_helpers"
export default class extends Controller {
static targets = [ "input", "form", "confirmation" ]
static classes = [ "error", "confirmation" ]
static classes = [ "error", "confirmation", "help" ]
// Actions
@@ -12,6 +12,23 @@ export default class extends Controller {
}
executeCommand(event) {
if (this.#hasShowHelpMenuCommand) {
this.#showHelpMenu()
event.preventDefault()
event.stopPropagation()
} else {
this.hideHelpMenu()
}
}
hideHelpMenu() {
if (this.#isHelpMenuOpened && this.#hasShowHelpMenuCommand) {
this.#reset()
this.element.classList.remove(this.helpClass)
}
}
handleCommandResponse(event) {
if (event.detail.success) {
this.#reset()
} else {
@@ -28,6 +45,18 @@ export default class extends Controller {
}
}
get #hasShowHelpMenuCommand() {
return this.inputTarget.value == "/help" || this.inputTarget.value == "/?"
}
#showHelpMenu() {
this.element.classList.add(this.helpClass)
}
get #isHelpMenuOpened() {
return this.element.classList.contains(this.helpClass)
}
async #handleErrorResponse(response) {
const status = response.status
const message = await response.text()