Skip to content
This repository was archived by the owner on Oct 15, 2025. It is now read-only.

Commit 70b3882

Browse files
committed
fix(challenge): lastQuery should be changed after submission
Also: * Disable the submit button while the query is being executed * Simplify $submitButton.disabled logic
1 parent 28ec249 commit 70b3882

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

assets/controllers/challenge_executor_controller.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default class extends Controller<HTMLElement> {
1616

1717
async connect() {
1818
const component = await getComponent(this.element);
19-
const lastQuery = this.element.dataset["lastQuery"];
19+
let lastQuery = this.element.dataset["lastQuery"];
2020

2121
const $editor = this.element.querySelector(this.editorSelectorValue);
2222
if (!$editor) {
@@ -35,15 +35,10 @@ export default class extends Controller<HTMLElement> {
3535
basicSetup,
3636
sql(),
3737
EditorView.updateListener.of(() => {
38-
const doc = editorView.state.doc.toString();
38+
const query = editorView.state.doc.toString();
3939

40-
if (doc.trim() === "" || doc === lastQuery) {
41-
// Disable the button if the user does not query something new.
42-
$submitButton.disabled = true;
43-
} else {
44-
// Enable the button if the user types something.
45-
$submitButton.disabled = false;
46-
}
40+
// Enable the submit button only if the query is not empty and different from the last one.
41+
$submitButton.disabled = query.trim() === "" || query === lastQuery;
4742
}),
4843
],
4944
parent: $editor,
@@ -52,12 +47,17 @@ export default class extends Controller<HTMLElement> {
5247

5348
// If the user presses the submit button, we'll send the query to the server.
5449
$submitButton.addEventListener("click", async () => {
50+
// Disable the submit button while the query is being executed
51+
$submitButton.disabled = true;
52+
5553
const query = editorView.state.doc.toString();
5654

5755
console.debug("Executing query", { query });
5856
await component.action("execute", {
5957
query,
6058
});
59+
60+
lastQuery = query;
6161
});
6262
}
6363

0 commit comments

Comments
 (0)