import { Controller } from "@hotwired/stimulus" export default class extends Controller { static targets = [ "code", "result", "run", "history", "resultSection", "historySection", ] connect() { this.myCodeMirror = CodeMirror.fromTextArea(document.getElementById("codemirror-console"), { value: "SELECT 1\n", mode: "sql", lineNumbers: true, }); this.history = [] } runQuery(event) { event.preventDefault() const query = event.currentTarget.querySelector("code").innerHTML this.myCodeMirror.setValue(query) this.run(event, query) } addQueryToHistory(query) { this.history.push(query) if (this.history.length > 10) { this.history.shift() } let innerHTML = "" // Templates? Please. React? Nah. for (let query of this.history.reverse()) { innerHTML += `
${query}