Skip to content

Commit bbf81de

Browse files
committed
cleaner focus handling after submit, allow clear and new to run before input validation
1 parent 1e25e6d commit bbf81de

3 files changed

Lines changed: 12 additions & 15 deletions

File tree

frontend/app/aipanel/aipanel.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,10 @@ const AIPanelComponentInner = memo(({ className, onClose }: AIPanelProps) => {
289289

290290
const handleSubmit = async (e: React.FormEvent) => {
291291
e.preventDefault();
292-
await model.handleSubmit(true);
292+
await model.handleSubmit();
293+
setTimeout(() => {
294+
model.focusInput();
295+
}, 100);
293296
};
294297

295298
const hasFilesDragged = (dataTransfer: DataTransfer): boolean => {

frontend/app/aipanel/waveai-model.tsx

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,16 @@ export class WaveAIModel {
248248
}
249249
}
250250

251-
async handleSubmit(shouldFocus: boolean) {
251+
async handleSubmit() {
252252
const input = globalStore.get(this.inputAtom);
253253
const droppedFiles = globalStore.get(this.droppedFiles);
254254

255+
if (input.trim() === "/clear" || input.trim() === "/new") {
256+
this.clearChat();
257+
globalStore.set(this.inputAtom, "");
258+
return;
259+
}
260+
255261
if (
256262
(!input.trim() && droppedFiles.length === 0) ||
257263
(this.useChatStatus !== "ready" && this.useChatStatus !== "error") ||
@@ -260,12 +266,6 @@ export class WaveAIModel {
260266
return;
261267
}
262268

263-
if (input.trim() === "/clear" || input.trim() === "/new") {
264-
this.clearChat();
265-
globalStore.set(this.inputAtom, "");
266-
return;
267-
}
268-
269269
this.clearError();
270270

271271
const aiMessageParts: AIMessagePart[] = [];
@@ -313,12 +313,6 @@ export class WaveAIModel {
313313
this.isChatEmpty = false;
314314
globalStore.set(this.inputAtom, "");
315315
this.clearFiles();
316-
317-
if (shouldFocus) {
318-
setTimeout(() => {
319-
this.focusInput();
320-
}, 100);
321-
}
322316
}
323317

324318
async uiLoadChat() {

frontend/app/store/tabrpcclient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export class TabClient extends WshClient {
8686
}
8787

8888
if (data.submit) {
89-
await model.handleSubmit(false);
89+
await model.handleSubmit();
9090
}
9191
}
9292
}

0 commit comments

Comments
 (0)