style: optimize chat bubbles size and add character avatar to header line

This commit is contained in:
Jannik committed 2026-10-25 22:14:31 +01:00
1 parent 94e15b2f3e
commit 8d7aa39ff8
2 files changed
+33 -17

No files matched your search

+23 -12
View File
@@ -1141,6 +1141,20 @@ async function viewThread(main, id) {
renderThread(main);
}
function chatMsgHTML(m, c) {
const isMsgError = m.isError || /^\[(?:Fehler|Error)\]/i.test(m.text || '');
return `
<div class="msg ${m.sender === 'user' ? 'user' : 'char'}${isMsgError ? ' is-error' : ''}">
${m.sender === 'user' ? '' : `
<div class="who-line" data-go-char="${c.id}" title="${esc(c.name)}">
${avatar(c.name, c.avatarKey, 'xs')}
<span class="who-name">${esc(c.name)}</span>
</div>
`}
<div class="msg-content${isMsgError ? ' text-error' : ''}">${esc(m.text)}</div>
</div>`;
}
function renderThread(main) {
const { character: c, messages, recentActivity } = state.chat;
main.innerHTML = `
@@ -1161,14 +1175,7 @@ function renderThread(main) {
: ''
}</div>
<div class="thread" id="thread">
${messages.length ? messages.map((m) => {
const isMsgError = m.isError || /^\[(?:Fehler|Error)\]/i.test(m.text || '');
return `
<div class="msg ${m.sender === 'user' ? 'user' : 'char'}${isMsgError ? ' is-error' : ''}">
${m.sender === 'user' ? '' : `<div class="who-line">${esc(c.name)}</div>`}
<div class="msg-content${isMsgError ? ' text-error' : ''}">${esc(m.text)}</div>
</div>`;
}).join('') : `<div class="empty">${getNoMsgsText(c)}</div>`}
${messages.length ? messages.map((m) => chatMsgHTML(m, c)).join('') : `<div class="empty">${getNoMsgsText(c)}</div>`}
<div id="thread-end"></div>
</div>
<div class="chat-input">
@@ -1178,6 +1185,13 @@ function renderThread(main) {
$('[data-go]', main).addEventListener('click', () => go('chats'));
$('#prof').addEventListener('click', () => go('char', c.id));
$('#thread')?.addEventListener('click', (e) => {
const who = e.target.closest('[data-go-char]');
if (who) {
const charId = who.getAttribute('data-go-char');
if (charId) go('char', charId);
}
});
$('#del-thread')?.addEventListener('click', async () => {
if (!confirm(t('confirm_delete_chat'))) return;
const btn = $('#del-thread');
@@ -2467,10 +2481,7 @@ function initPolling() {
state.chat.messages = fresh.messages;
const thread = $('#thread');
if (thread) {
thread.innerHTML = fresh.messages.map((m) => `
<div class="msg ${m.sender === 'user' ? 'user' : 'char'}">
${m.sender === 'user' ? '' : `<div class="who-line">${esc(state.chat.character.name)}</div>`}${esc(m.text)}
</div>`).join('') + '<div id="thread-end"></div>';
thread.innerHTML = fresh.messages.map((m) => chatMsgHTML(m, state.chat.character)).join('') + '<div id="thread-end"></div>';
$('#thread-end')?.scrollIntoView({ block: 'end' });
}
}
+10 -5
View File
@@ -60,6 +60,7 @@ img{max-width:100%;display:block}
.post-head{display:flex;gap:10px;align-items:center;margin-bottom:8px}
.avatar{width:42px;height:42px;border-radius:50%;flex:none;display:grid;place-items:center;font-weight:700;color:#fff;font-size:16px;
background:linear-gradient(135deg,var(--acc),var(--acc2)); object-fit:cover; overflow:hidden}
.avatar.xs{width:20px;height:20px;min-width:20px;min-height:20px;font-size:10px;line-height:1;border-radius:50%;flex:none}
.avatar.sm{width:32px;height:32px;font-size:13px}
.avatar.lg{width:72px;height:72px;font-size:28px}
.who{display:flex;flex-direction:column;line-height:1.25;min-width:0}
@@ -144,11 +145,15 @@ input[type=text]:focus,input[type=number]:focus,input[type=password]:focus,texta
.chat-list .chat-item:hover{background:var(--card)}
.chat-item .last{color:var(--muted);font-size:13.5px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:56vw}
.chat-item .cnt{margin-left:auto;font-size:12px;background:var(--bg2);border:1px solid var(--line);color:var(--muted);border-radius:999px;padding:3px 9px;flex:none}
.thread{display:flex;flex-direction:column;gap:10px;padding-bottom:8px}
.msg{max-width:82%;padding:10px 14px;border-radius:20px;font-size:15px;line-height:1.45;white-space:pre-wrap;word-break:break-word}
.msg.user{align-self:flex-end;background:linear-gradient(135deg,var(--acc),var(--acc2));color:#fff;border-bottom-right-radius:6px}
.msg.char{align-self:flex-start;background:var(--card);border:1px solid var(--line);border-bottom-left-radius:6px}
.msg.char .who-line{font-size:12px;color:var(--acc);font-weight:700;margin-bottom:3px}
.thread{display:flex;flex-direction:column;gap:6px;padding-bottom:8px}
.msg{display:inline-flex;flex-direction:column;width:fit-content;max-width:min(78%, 460px);padding:7px 11px;border-radius:14px;font-size:14px;line-height:1.4;white-space:pre-wrap;word-break:break-word;overflow-wrap:break-word;box-sizing:border-box}
.msg.user{align-self:flex-end;background:linear-gradient(135deg,var(--acc),var(--acc2));color:#fff;border-bottom-right-radius:4px}
.msg.char{align-self:flex-start;background:var(--card);border:1px solid var(--line);border-bottom-left-radius:4px;padding:5px 11px 7px}
.msg.char .who-line{display:inline-flex;align-items:center;gap:6px;font-size:11.5px;color:var(--acc);font-weight:700;margin-bottom:3px;line-height:1.2;cursor:pointer;user-select:none;max-width:100%}
.msg.char .who-line:hover .who-name{text-decoration:underline}
.msg.char .who-line .who-name{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.msg-content{white-space:pre-wrap;word-break:break-word;overflow-wrap:break-word}
.msg.typing{padding:8px 12px;height:32px;display:inline-flex;align-items:center}
.chat-input{position:sticky;bottom:calc(var(--nav-h) + 6px);display:flex;gap:8px;background:var(--bg);padding-top:8px}
.chat-input input{border-radius:999px}
.ctx-note{font-size:12.5px;color:var(--muted);background:var(--card);border:1px dashed var(--line);border-radius:12px;padding:8px 12px;margin-bottom:10px}