fix(ui): Improve send button state handling

This commit is contained in:
Chris Christiansen 2026-06-24 16:34:15 +00:00
parent 57407bbd91
commit 327b0aa633

View File

@ -403,7 +403,7 @@
<div class="input-wrap">
<div class="input-row">
<textarea id="msg-input" rows="1" placeholder="Skriv til Jason... (Enter sender, Shift+Enter ny linje)" oninput="autoResize(this)" onkeydown="handleKey(event)"></textarea>
<button class="send-btn" id="send-btn" onclick="sendMessage()" disabled>
<button class="send-btn" id="send-btn" onclick="sendMessage()">
<svg width="15" height="15" fill="none" stroke="currentColor" stroke-width="2.5" viewBox="0 0 24 24"><line x1="22" y1="2" x2="11" y2="13"/><polygon points="22 2 15 22 11 13 2 9 22 2"/></svg>
</button>
</div>
@ -1100,7 +1100,10 @@ function appendTyping(){
function rmTyping(){ document.getElementById('typing')?.remove() }
const chatInp=document.getElementById('msg-input'),sbtn=document.getElementById('send-btn')
chatInp.addEventListener('input',()=>sbtn.disabled=!chatInp.value.trim())
function updateSendBtn() { sbtn.disabled = !chatInp.value.trim() }
chatInp.addEventListener('input', updateSendBtn)
chatInp.addEventListener('keyup', updateSendBtn)
chatInp.addEventListener('paste', () => setTimeout(updateSendBtn, 0))
function autoResize(el){ el.style.height='auto';el.style.height=Math.min(el.scrollHeight,160)+'px' }
function handleKey(e){ if(e.key==='Enter'&&!e.shiftKey){e.preventDefault();if(!sbtn.disabled)sendMessage()} }
function suggest(btn){ chatInp.value=btn.textContent.trim();chatInp.dispatchEvent(new Event('input', { bubbles: true }));autoResize(chatInp);sbtn.disabled=false;sendMessage() }
@ -1128,8 +1131,9 @@ function exportHistory(){
const h=lh(),lines=h.map(m=>`[${new Date(m.ts).toISOString()}] ${m.role.toUpperCase()}: ${m.text}`)
const a=document.createElement('a');a.href=URL.createObjectURL(new Blob([lines.join('\n\n')],{type:'text/plain'}));a.download='jason-historikk-'+new Date().toISOString().slice(0,10)+'.txt';a.click()
}
;(function(){ const h=lh();if(!h.length)return;h.forEach(m=>appendMsg(m.role,m.text,m.ts));document.getElementById('messages').scrollTop=99999 })()
;(() => { const h = lh(); if (!h.length) return; h.forEach(m => appendMsg(m.role, m.text, m.ts)); document.getElementById('messages').scrollTop = 99999 })()
chatInp.focus()
updateSendBtn()
renderTierGrid(5000)
updatePricing(5000)
</script>