ui cleanup mobile view also

This commit is contained in:
Bartal Læarsson
2026-06-18 22:25:52 +01:00
parent f24da78970
commit 9d9b04d01b
5 changed files with 342 additions and 105 deletions
+189 -44
View File
@@ -15,6 +15,9 @@
--border: #2b303a;
--accent: #8f9cff;
--accent-dim: #737fd3;
--danger: #d93d3d;
--danger-soft: rgba(217, 61, 61, 0.16);
--danger-text: #ffd1d1;
--text: #eceff4;
--muted: #9aa3b2;
--user: #8f9cff;
@@ -32,9 +35,10 @@
.layout {
display: grid;
grid-template-columns: 280px 1fr;
grid-template-rows: 56px 1fr;
grid-template-columns: 280px minmax(0, 1fr);
grid-template-rows: 56px minmax(0, 1fr);
height: 100vh;
height: 100dvh;
}
.topbar {
@@ -42,7 +46,7 @@
display: flex;
align-items: center;
gap: 0.75rem;
padding: 0 1.5rem;
padding: 0 1.25rem;
border-bottom: 1px solid var(--border);
background: var(--surface);
}
@@ -54,13 +58,20 @@
}
.topbar-timer {
display: inline-flex;
align-items: center;
justify-content: center;
margin-left: auto;
font-size: 0.78rem;
color: var(--muted);
background: var(--bg);
padding: 0.25rem 0.65rem;
font-size: 0.82rem;
color: var(--danger-text);
background: var(--danger-soft);
padding: 0.34rem 0.75rem;
border-radius: 20px;
border: 1px solid var(--border);
border: 1px solid var(--danger);
font-weight: 800;
letter-spacing: 0.01em;
box-shadow: 0 0 0 1px rgba(217, 61, 61, 0.08), 0 8px 24px rgba(217, 61, 61, 0.08);
white-space: nowrap;
}
.sidebar {
@@ -68,6 +79,7 @@
display: flex;
flex-direction: column;
overflow: hidden;
min-width: 0;
}
.sidebar-header {
@@ -89,8 +101,10 @@
gap: 0.3rem;
}
#session-list::-webkit-scrollbar { width: 4px; }
#session-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
#session-list::-webkit-scrollbar,
#supporter-messages::-webkit-scrollbar { width: 4px; height: 4px; }
#session-list::-webkit-scrollbar-thumb,
#supporter-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.session-item {
width: 100%;
@@ -117,6 +131,7 @@
display: flex;
align-items: center;
gap: 0.5rem;
flex-wrap: wrap;
}
.session-badge {
@@ -145,41 +160,55 @@
.main-panel {
display: flex;
flex-direction: column;
align-items: center;
overflow: hidden;
min-width: 0;
background: var(--bg);
}
.main-header,
#supporter-messages,
.typing-bubble,
#reply-area {
width: min(760px, 100%);
}
.main-header {
padding: 0.9rem 1.5rem;
padding: 0.85rem 1rem;
border-bottom: 1px solid var(--border);
display: flex;
align-items: center;
gap: 0.5rem;
min-height: 56px;
min-height: 54px;
background: var(--bg);
}
#active-session-name {
font-weight: 700;
font-size: 1rem;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
#active-session-meta {
font-size: 0.8rem;
font-size: 0.78rem;
color: var(--muted);
white-space: nowrap;
}
#supporter-messages {
flex: 1;
min-height: 0;
overflow-y: auto;
padding: 1.2rem 1.5rem;
padding: 1rem;
display: flex;
flex-direction: column;
gap: 0.5rem;
scroll-behavior: smooth;
}
#supporter-messages::-webkit-scrollbar { width: 4px; }
#supporter-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.empty-state {
flex: 1;
display: flex;
@@ -189,6 +218,8 @@
color: var(--muted);
gap: 0.5rem;
font-size: 0.9rem;
text-align: center;
padding: 1rem;
}
.msg-wrap { display: flex; }
@@ -196,11 +227,12 @@
.msg-supporter-wrap { justify-content: flex-start; }
.msg-user, .msg-supporter {
max-width: 65%;
padding: 0.6rem 0.9rem;
max-width: min(72%, 520px);
padding: 0.58rem 0.85rem;
border-radius: 16px;
font-size: 0.88rem;
line-height: 1.5;
line-height: 1.48;
overflow-wrap: anywhere;
}
.msg-user {
@@ -217,7 +249,7 @@
.msg-label {
display: block;
font-size: 0.7rem;
font-size: 0.68rem;
font-weight: 600;
opacity: 0.7;
margin-bottom: 2px;
@@ -229,7 +261,7 @@
.msg-time {
display: block;
font-size: 0.68rem;
font-size: 0.66rem;
opacity: 0.55;
margin-top: 4px;
text-align: right;
@@ -239,30 +271,44 @@
.msg-system-text {
font-size: 0.75rem;
color: var(--muted);
background: var(--bg);
background: var(--surface);
padding: 0.25rem 0.75rem;
border-radius: 20px;
text-align: center;
}
.typing-bubble {
display: none;
padding: 0 1.5rem 0.55rem;
padding: 0 1rem 0.55rem;
justify-content: flex-start;
}
.typing-bubble.visible { display: flex; }
.typing-bubble-inner {
position: relative;
display: inline-flex;
align-items: center;
gap: 4px;
min-width: 48px;
padding: 0.65rem 0.85rem;
padding: 0.58rem 0.78rem;
background: var(--supporter);
border-radius: 16px;
border-bottom-left-radius: 4px;
}
.typing-bubble-inner::after {
content: "";
position: absolute;
left: 7px;
bottom: -4px;
width: 9px;
height: 9px;
background: var(--supporter);
transform: rotate(45deg);
border-radius: 2px;
}
.typing-dot {
width: 6px;
height: 6px;
@@ -281,15 +327,17 @@
#reply-area {
border-top: 1px solid var(--border);
padding: 0.75rem 1.5rem;
padding: 0.65rem 1rem 0.8rem;
display: none;
background: var(--bg);
}
#reply-area.visible { display: flex; gap: 0.6rem; }
#reply-area.visible { display: flex; gap: 0.5rem; }
#reply-area input[type="text"] {
flex: 1;
padding: 0.65rem 1rem;
min-width: 0;
padding: 0.58rem 0.85rem;
background: var(--surface);
border: 1px solid var(--border);
border-radius: var(--radius);
@@ -302,7 +350,7 @@
#reply-area input[type="text"]:focus { border-color: var(--accent); }
#reply-area button {
padding: 0.65rem 1.2rem;
padding: 0.58rem 1rem;
background: var(--accent);
color: #111318;
border: none;
@@ -311,9 +359,70 @@
font-size: 0.88rem;
cursor: pointer;
transition: background 0.2s;
white-space: nowrap;
}
#reply-area button:hover { background: var(--accent-dim); }
@media (max-width: 820px) {
html, body { overflow: hidden; }
.layout {
grid-template-columns: minmax(0, 1fr);
grid-template-rows: auto auto minmax(0, 1fr);
}
.topbar {
min-height: 56px;
padding: 0.65rem 0.85rem;
flex-wrap: wrap;
}
.topbar-timer {
margin-left: 0;
font-size: 0.78rem;
padding: 0.3rem 0.65rem;
}
.sidebar {
border-right: 0;
border-bottom: 1px solid var(--border);
max-height: 30vh;
}
.sidebar-header { padding: 0.7rem 0.85rem; }
#session-list {
flex-direction: row;
overflow-x: auto;
overflow-y: hidden;
padding: 0.5rem 0.75rem 0.65rem;
}
.session-item {
min-width: 190px;
max-width: 230px;
}
.main-header,
#supporter-messages,
.typing-bubble,
#reply-area { width: 100%; }
.main-header { padding: 0.75rem 0.85rem; min-height: 48px; }
#supporter-messages { padding: 0.85rem; }
.msg-user, .msg-supporter { max-width: 86%; }
#reply-area { padding: 0.6rem 0.75rem 0.75rem; }
}
@media (max-width: 460px) {
.topbar { align-items: flex-start; flex-direction: column; gap: 0.45rem; }
.topbar-timer { width: 100%; justify-content: center; text-align: center; }
.sidebar { max-height: 28vh; }
.session-item { min-width: 165px; }
#reply-area.visible { gap: 0.4rem; }
#reply-area button { padding-inline: 0.85rem; }
}
</style>
</head>
<body>
@@ -362,8 +471,8 @@
<script>
let activeSessionId = null;
let supporterWs = null;
let typingHideTimer = null;
let lastTypingSent = 0;
let lastTypingSessionId = null;
let supporterTypingActive = false;
function selectSession(button) {
document.querySelectorAll('.session-item').forEach(function(b) { b.classList.remove('selected'); });
@@ -372,17 +481,22 @@
}
function setActiveSession(sessionId, name) {
stopSupporterTyping(lastTypingSessionId);
activeSessionId = sessionId;
document.getElementById('active-session-name').textContent = name;
document.getElementById('active-session-name').style.color = '';
document.getElementById('active-session-meta').textContent = '#' + sessionId.slice(0, 8);
document.getElementById('reply-area').classList.add('visible');
document.getElementById('reply-input').value = '';
hideUserTyping();
scrollSupporterMessages();
}
function resetSupporterDashboard() {
stopSupporterTyping(lastTypingSessionId);
activeSessionId = null;
document.getElementById('active-session-name').textContent = 'Select a conversation';
document.getElementById('active-session-name').style.color = 'var(--muted)';
document.getElementById('active-session-meta').textContent = '';
document.getElementById('reply-area').classList.remove('visible');
hideUserTyping();
@@ -399,23 +513,43 @@
const indicator = document.getElementById('supporter-peer-typing');
if (!indicator) return;
indicator.classList.add('visible');
clearTimeout(typingHideTimer);
typingHideTimer = setTimeout(hideUserTyping, 1400);
scrollSupporterMessages();
}
function hideUserTyping() {
const indicator = document.getElementById('supporter-peer-typing');
if (indicator) indicator.classList.remove('visible');
clearTimeout(typingHideTimer);
}
function sendSupporterTyping() {
if (!activeSessionId || !supporterWs || supporterWs.readyState !== WebSocket.OPEN) return;
const now = Date.now();
if (now - lastTypingSent < 500) return;
lastTypingSent = now;
supporterWs.send(`typing:supporter:${activeSessionId}`);
function sendSupporterTypingState(state, sessionId = activeSessionId) {
if (!sessionId || !supporterWs || supporterWs.readyState !== WebSocket.OPEN) return;
supporterWs.send(`typing:supporter:${state}:${sessionId}`);
}
function startSupporterTyping() {
const input = document.getElementById('reply-input');
if (!activeSessionId || !input || !input.value.trim()) {
stopSupporterTyping(lastTypingSessionId || activeSessionId);
return;
}
if (supporterTypingActive && lastTypingSessionId === activeSessionId) return;
supporterTypingActive = true;
lastTypingSessionId = activeSessionId;
sendSupporterTypingState('start', activeSessionId);
}
function stopSupporterTyping(sessionId = activeSessionId) {
if (!supporterTypingActive && !sessionId) return;
const targetSession = sessionId || lastTypingSessionId;
if (targetSession) sendSupporterTypingState('stop', targetSession);
supporterTypingActive = false;
lastTypingSessionId = null;
}
function handleReplyInput() {
const input = document.getElementById('reply-input');
if (input && input.value.trim()) startSupporterTyping();
else stopSupporterTyping(lastTypingSessionId || activeSessionId);
}
document.addEventListener('htmx:afterSwap', (e) => {
@@ -428,6 +562,8 @@
const content = input.value.trim();
if (!content) return;
stopSupporterTyping(activeSessionId);
fetch(`/supporter/send/${activeSessionId}`, {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
@@ -437,8 +573,8 @@
.then(html => {
const msgs = document.getElementById('supporter-messages');
msgs.insertAdjacentHTML('beforeend', html);
scrollSupporterMessages();
input.value = '';
scrollSupporterMessages();
});
});
@@ -446,7 +582,7 @@
if (e.key === 'Enter') document.getElementById('reply-btn').click();
});
document.getElementById('reply-input').addEventListener('input', sendSupporterTyping);
document.getElementById('reply-input').addEventListener('input', handleReplyInput);
function connectSupporterWS() {
const wsProtocol = location.protocol === 'https:' ? 'wss' : 'ws';
@@ -458,16 +594,22 @@
resetSupporterDashboard();
return;
}
if (data.startsWith('typing:user:')) {
const sessionId = data.replace('typing:user:', '');
if (data.startsWith('typing:user:start:')) {
const sessionId = data.replace('typing:user:start:', '');
if (sessionId === activeSessionId) showUserTyping();
return;
}
if (data.startsWith('typing:user:stop:')) {
const sessionId = data.replace('typing:user:stop:', '');
if (sessionId === activeSessionId) hideUserTyping();
return;
}
if (data.startsWith('typing:supporter:')) return;
htmx.trigger('#session-list', 'refresh');
if (data === activeSessionId) {
hideUserTyping();
fetch(`/messages/${activeSessionId}`)
.then(r => r.text())
.then(html => {
@@ -477,6 +619,9 @@
}
};
supporterWs.onopen = () => {
if (supporterTypingActive && lastTypingSessionId) sendSupporterTypingState('start', lastTypingSessionId);
};
supporterWs.onclose = () => setTimeout(connectSupporterWS, 2000);
}