More refinements
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user