This commit is contained in:
Adrien Bouvais 2024-05-21 22:40:37 +02:00
parent fd4adcc136
commit 0dd4a4c696
2 changed files with 12 additions and 9 deletions

View File

@ -4,7 +4,7 @@
<div class="chat-input-container mb-5"> <div class="chat-input-container mb-5">
<div class="textarea-wrapper"> <div class="textarea-wrapper">
<textarea {% if not IsLogin or not HaveKey %}disabled{% endif %} class="textarea" <textarea {% if not IsLogin or not HaveKey %}disabled{% endif %} class="textarea"
placeholder="Type your message here..." name="message" oninput="toggleSendButton(this)" placeholder="Type your message here..." name="message" oninput="toggleSendButton()"
id="chat-input-textarea"></textarea> id="chat-input-textarea"></textarea>
<div class="button-group"> <div class="button-group">
<hx hx-get="/loadSettings" hx-trigger="load" hx-swap="outerHTML" hx-target="this"></hx> <hx hx-get="/loadSettings" hx-trigger="load" hx-swap="outerHTML" hx-target="this"></hx>
@ -37,18 +37,19 @@
</div> </div>
<script> <script>
const textarea = document.querySelector('.textarea'); const textarea = document.querySelector('#chat-input-textarea');
textarea.addEventListener('keydown', handleTextareaKeydown); textarea.addEventListener('keydown', handleTextareaKeydown);
function toggleSendButton(textarea) { function toggleSendButton() {
var sendButton = document.getElementById('chat-input-send-btn'); const sendButton = document.getElementById('chat-input-send-btn');
sendButton.disabled = textarea.value.trim() === ''; const selectedLLMIds = JSON.parse(getSelectedModelsIDs());
sendButton.disabled = textarea.value.trim() === '' || selectedLLMIds.length === 0;
} }
function clearTextArea() { function clearTextArea() {
setTimeout(function () { setTimeout(function () {
textarea.value = ''; textarea.value = '';
toggleSendButton(textarea); toggleSendButton();
}, 200); }, 200);
} }

View File

@ -34,6 +34,7 @@
element.classList.remove('unselected'); element.classList.remove('unselected');
element.classList.add('selected'); element.classList.add('selected');
} }
toggleSendButton();
} }
function getSelectedModelsIDs() { function getSelectedModelsIDs() {
@ -42,7 +43,7 @@
for (var i = 0; i < selectedModels.length; i++) { for (var i = 0; i < selectedModels.length; i++) {
selectedModelsIDs.push(selectedModels[i].getAttribute('value')); selectedModelsIDs.push(selectedModels[i].getAttribute('value'));
} }
return JSON.stringify(selectedModelsIDs); return selectedModelsIDs.length > 0 ? JSON.stringify(selectedModelsIDs) : '[]';
} }
</script> </script>
@ -51,11 +52,12 @@
border: 2px solid #3273dc; border: 2px solid #3273dc;
/* Bulma's primary color */ /* Bulma's primary color */
border-radius: 4px; border-radius: 4px;
padding: 2px; padding: 1px;
margin: 2px;
} }
.unselected { .unselected {
border-radius: 4px; border-radius: 4px;
padding: 4px; padding: 3px;
} }
</style> </style>