mirror of
https://github.com/outbackdingo/optimclaw.git
synced 2026-08-25 14:53:34 +00:00
fix: block send until thread is selected (#306)
* fix: block send until thread is selected Prevents messages from ending up in orphan threads when user sends while currentThreadId is null during page load. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * fix: guard enableChatInput against null thread + add user feedback Prevents SSE events from re-enabling input before a thread is selected. Adds status message when user tries to send without a thread. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
510fba4c92
commit
82f24bf08f
@@ -241,6 +241,11 @@ function isCurrentThread(threadId) {
|
||||
function sendMessage() {
|
||||
const input = document.getElementById('chat-input');
|
||||
const sendBtn = document.getElementById('send-btn');
|
||||
if (!currentThreadId) {
|
||||
console.warn('sendMessage: no thread selected, ignoring');
|
||||
setStatus('Waiting for thread to load...');
|
||||
return;
|
||||
}
|
||||
const content = input.value.trim();
|
||||
if (!content) return;
|
||||
|
||||
@@ -263,6 +268,8 @@ function sendMessage() {
|
||||
}
|
||||
|
||||
function enableChatInput() {
|
||||
// Don't re-enable until a thread is selected (prevents orphan messages)
|
||||
if (!currentThreadId) return;
|
||||
const input = document.getElementById('chat-input');
|
||||
const sendBtn = document.getElementById('send-btn');
|
||||
sendBtn.disabled = false;
|
||||
@@ -740,6 +747,11 @@ function loadThreads() {
|
||||
if (!currentThreadId && assistantThreadId) {
|
||||
switchToAssistant();
|
||||
}
|
||||
|
||||
// Enable chat input once a thread is available
|
||||
if (currentThreadId) {
|
||||
enableChatInput();
|
||||
}
|
||||
}).catch(() => {});
|
||||
}
|
||||
|
||||
@@ -788,6 +800,10 @@ chatInput.addEventListener('keydown', (e) => {
|
||||
});
|
||||
chatInput.addEventListener('input', () => autoResizeTextarea(chatInput));
|
||||
|
||||
// Disable send until a thread is selected (loadThreads will enable it)
|
||||
chatInput.disabled = true;
|
||||
document.getElementById('send-btn').disabled = true;
|
||||
|
||||
// Infinite scroll: load older messages when scrolled near the top
|
||||
document.getElementById('chat-messages').addEventListener('scroll', function () {
|
||||
if (this.scrollTop < 100 && hasMore && !loadingOlder) {
|
||||
|
||||
Reference in New Issue
Block a user