From 1f2f47c7e3a90a5485daae28680b3e52b62da457 Mon Sep 17 00:00:00 2001 From: Jorge Manrubia Date: Sat, 10 May 2025 18:46:26 +0200 Subject: [PATCH] More refinements --- .../controllers/terminal_controller.js | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/app/javascript/controllers/terminal_controller.js b/app/javascript/controllers/terminal_controller.js index 46fc9ba60..1191371f5 100644 --- a/app/javascript/controllers/terminal_controller.js +++ b/app/javascript/controllers/terminal_controller.js @@ -43,14 +43,7 @@ export default class extends Controller { if (event.detail.success) { const response = event.detail.fetchResponse if (response && response.response.headers.get("Content-Type")?.includes("application/json")) { - response.response.json().then((commands) => { - if (commands.reply) { - this.element.querySelector("#chat-insight").innerHTML = marked.parse(commands.reply) - } else { - this.element.querySelector("#chat-responses").textContent = JSON.stringify(commands, null, 2) - } - this.#executeCommands(commands) - }) + this.#handleJsonCommandResponse(response) } else { this.#reset() } @@ -95,6 +88,17 @@ export default class extends Controller { } } + #handleJsonCommandResponse(response) { + response.response.json().then((commands) => { + if (commands.reply) { + this.element.querySelector("#chat-insight").innerHTML = marked.parse(commands.reply) + } else { + this.element.querySelector("#chat-responses").textContent = JSON.stringify(commands, null, 2) + } + this.#executeCommands(commands) + }) + } + #reset(inputValue = "") { this.formTarget.reset() this.inputTarget.value = inputValue