Mark-Lasfar
commited on
Commit
·
aa6008a
1
Parent(s):
f46462b
add chat
Browse files- static/js/chat.js +8 -10
- templates/chat.html +1 -1
static/js/chat.js
CHANGED
|
@@ -127,7 +127,7 @@ function updateSendButtonState() {
|
|
| 127 |
uiElements.fileInput.files.length > 0 ||
|
| 128 |
uiElements.audioInput.files.length > 0;
|
| 129 |
uiElements.sendBtn.disabled = !hasInput || isRequestActive || isRecording;
|
| 130 |
-
console.log('Send button state:', { hasInput, isRequestActive, isRecording, disabled: uiElements.sendBtn.disabled });
|
| 131 |
}
|
| 132 |
}
|
| 133 |
|
|
@@ -967,7 +967,7 @@ if (uiElements.audioInput) uiElements.audioInput.addEventListener('change', prev
|
|
| 967 |
|
| 968 |
if (uiElements.sendBtn) {
|
| 969 |
let pressTimer;
|
| 970 |
-
const
|
| 971 |
e.preventDefault();
|
| 972 |
if (uiElements.sendBtn.disabled || isRequestActive || isRecording) return;
|
| 973 |
if (uiElements.input.value.trim() || uiElements.fileInput.files.length > 0 || uiElements.audioInput.files.length > 0) {
|
|
@@ -986,8 +986,8 @@ if (uiElements.sendBtn) {
|
|
| 986 |
uiElements.sendBtn.replaceWith(uiElements.sendBtn.cloneNode(true));
|
| 987 |
uiElements.sendBtn = document.getElementById('sendBtn');
|
| 988 |
|
| 989 |
-
uiElements.sendBtn.addEventListener('click',
|
| 990 |
-
uiElements.sendBtn.addEventListener('touchstart',
|
| 991 |
uiElements.sendBtn.addEventListener('touchend', handlePressEnd);
|
| 992 |
uiElements.sendBtn.addEventListener('touchcancel', handlePressEnd);
|
| 993 |
}
|
|
@@ -997,18 +997,16 @@ if (uiElements.form) {
|
|
| 997 |
e.preventDefault();
|
| 998 |
if (!isRecording && uiElements.input.value.trim()) {
|
| 999 |
submitMessage();
|
|
|
|
|
|
|
| 1000 |
}
|
| 1001 |
});
|
| 1002 |
}
|
| 1003 |
|
| 1004 |
if (uiElements.input) {
|
| 1005 |
-
let debounceTimer;
|
| 1006 |
uiElements.input.addEventListener('input', () => {
|
| 1007 |
-
|
| 1008 |
-
|
| 1009 |
-
autoResizeTextarea();
|
| 1010 |
-
updateSendButtonState();
|
| 1011 |
-
}, 100);
|
| 1012 |
});
|
| 1013 |
uiElements.input.addEventListener('keydown', (e) => {
|
| 1014 |
if (e.key === 'Enter' && !e.shiftKey) {
|
|
|
|
| 127 |
uiElements.fileInput.files.length > 0 ||
|
| 128 |
uiElements.audioInput.files.length > 0;
|
| 129 |
uiElements.sendBtn.disabled = !hasInput || isRequestActive || isRecording;
|
| 130 |
+
console.log('Send button state updated:', { hasInput, isRequestActive, isRecording, disabled: uiElements.sendBtn.disabled });
|
| 131 |
}
|
| 132 |
}
|
| 133 |
|
|
|
|
| 967 |
|
| 968 |
if (uiElements.sendBtn) {
|
| 969 |
let pressTimer;
|
| 970 |
+
const handleSendAction = (e) => {
|
| 971 |
e.preventDefault();
|
| 972 |
if (uiElements.sendBtn.disabled || isRequestActive || isRecording) return;
|
| 973 |
if (uiElements.input.value.trim() || uiElements.fileInput.files.length > 0 || uiElements.audioInput.files.length > 0) {
|
|
|
|
| 986 |
uiElements.sendBtn.replaceWith(uiElements.sendBtn.cloneNode(true));
|
| 987 |
uiElements.sendBtn = document.getElementById('sendBtn');
|
| 988 |
|
| 989 |
+
uiElements.sendBtn.addEventListener('click', handleSendAction);
|
| 990 |
+
uiElements.sendBtn.addEventListener('touchstart', handleSendAction);
|
| 991 |
uiElements.sendBtn.addEventListener('touchend', handlePressEnd);
|
| 992 |
uiElements.sendBtn.addEventListener('touchcancel', handlePressEnd);
|
| 993 |
}
|
|
|
|
| 997 |
e.preventDefault();
|
| 998 |
if (!isRecording && uiElements.input.value.trim()) {
|
| 999 |
submitMessage();
|
| 1000 |
+
} else if (!isRecording && (uiElements.fileInput.files.length > 0 || uiElements.audioInput.files.length > 0)) {
|
| 1001 |
+
submitMessage();
|
| 1002 |
}
|
| 1003 |
});
|
| 1004 |
}
|
| 1005 |
|
| 1006 |
if (uiElements.input) {
|
|
|
|
| 1007 |
uiElements.input.addEventListener('input', () => {
|
| 1008 |
+
updateSendButtonState();
|
| 1009 |
+
autoResizeTextarea();
|
|
|
|
|
|
|
|
|
|
| 1010 |
});
|
| 1011 |
uiElements.input.addEventListener('keydown', (e) => {
|
| 1012 |
if (e.key === 'Enter' && !e.shiftKey) {
|
templates/chat.html
CHANGED
|
@@ -418,7 +418,7 @@
|
|
| 418 |
</div>
|
| 419 |
|
| 420 |
<!-- Scripts -->
|
| 421 |
-
<script src="/static/js/chat.js?v=1.
|
| 422 |
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
| 423 |
|
| 424 |
<script>
|
|
|
|
| 418 |
</div>
|
| 419 |
|
| 420 |
<!-- Scripts -->
|
| 421 |
+
<script src="/static/js/chat.js?v=1.2"></script>
|
| 422 |
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
| 423 |
|
| 424 |
<script>
|