Files

903 lines
26 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, viewport-fit=cover" />
<title>Support Dashboard — FLÓ</title>
<script>
(function () {
var stored = localStorage.getItem('poc-theme');
var theme = stored || (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'tokyo' : 'light');
document.documentElement.setAttribute('data-theme', theme);
})();
</script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@300;400;500;700&display=swap" rel="stylesheet">
<script src="https://unpkg.com/htmx.org@1.9.12"></script>
<style>
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root,
[data-theme="light"] {
--bg: #f4f1ec;
--bg-panel: rgba(255, 253, 250, 0.72);
--nav-bg: rgba(244, 241, 236, 0.6);
--ink: #1a1d22;
--ink-muted: #595f68;
--ink-dim: #9299a2;
--accent: #2c5a7a;
--border: rgba(26, 29, 34, 0.1);
--danger: #a03030;
--danger-soft: rgba(160, 48, 48, 0.08);
--danger-text: #a03030;
--own-bubble: #2c5a7a;
--own-bubble-ink: #f4f1ec;
--peer-bubble: rgba(26, 29, 34, 0.06);
--peer-bubble-ink: #1a1d22;
--input-bg: rgba(26, 29, 34, 0.04);
--surface-hover: rgba(26, 29, 34, 0.04);
--status-waiting-bg: rgba(180, 130, 20, 0.1);
--status-waiting-ink: #8a6a10;
--status-active-bg: rgba(44, 90, 122, 0.1);
--status-active-ink: #2c5a7a;
--status-closed-bg: rgba(146, 153, 162, 0.1);
--status-closed-ink: #9299a2;
}
[data-theme="tokyo"] {
--bg: #07070d;
--bg-panel: rgba(15, 16, 28, 0.72);
--nav-bg: rgba(7, 7, 13, 0.65);
--ink: #e8f4ff;
--ink-muted: #a3b3cc;
--ink-dim: #7886a0;
--accent: #64dcff;
--border: rgba(100, 220, 255, 0.12);
--danger: #d93d3d;
--danger-soft: rgba(217, 61, 61, 0.16);
--danger-text: #ffd1d1;
--own-bubble: #64dcff;
--own-bubble-ink: #07070d;
--peer-bubble: rgba(100, 220, 255, 0.08);
--peer-bubble-ink: #e8f4ff;
--input-bg: rgba(100, 220, 255, 0.04);
--surface-hover: rgba(100, 220, 255, 0.06);
--status-waiting-bg: rgba(220, 173, 43, 0.15);
--status-waiting-ink: #dcad2b;
--status-active-bg: rgba(100, 220, 255, 0.12);
--status-active-ink: #64dcff;
--status-closed-bg: rgba(163, 179, 204, 0.1);
--status-closed-ink: #7886a0;
}
html, body {
width: 100%;
height: 100%;
height: var(--app-height, 100dvh);
background: var(--bg);
font-family: 'JetBrains Mono', monospace;
font-size: 0.92rem;
font-weight: 300;
line-height: 1.65;
color: var(--ink);
overflow: hidden;
-webkit-text-size-adjust: 100%;
transition: background 0.3s ease, color 0.3s ease;
}
button, input { font: inherit; }
a {
color: var(--accent);
text-decoration: none;
border-bottom: 1px solid transparent;
transition: all 0.2s ease;
}
a:hover { border-bottom-color: var(--accent); }
/* ---- Layout ---- */
.layout {
display: grid;
grid-template-columns: 280px minmax(0, 1fr);
grid-template-rows: 52px minmax(0, 1fr);
width: 100%;
height: 100%;
height: var(--app-height, 100dvh);
overflow: hidden;
}
/* ---- Topbar ---- */
.topbar {
grid-column: 1 / -1;
display: flex;
align-items: center;
gap: 0.75rem;
padding: 0 1.5rem;
border-bottom: 1px solid var(--border);
background: var(--nav-bg);
backdrop-filter: blur(12px) saturate(120%);
-webkit-backdrop-filter: blur(12px) saturate(120%);
min-width: 0;
transition: background 0.3s ease;
}
.menu-button {
display: none;
background: transparent;
color: var(--ink);
border: 1px solid var(--border);
border-radius: 2px;
padding: 0.4rem 0.65rem;
font-family: 'JetBrains Mono', monospace;
font-size: 0.72rem;
font-weight: 500;
letter-spacing: 0.1em;
text-transform: uppercase;
cursor: pointer;
transition: border-color 0.2s, color 0.2s;
}
.menu-button:hover { border-color: var(--ink-muted); }
.topbar-brand {
display: inline-flex;
align-items: baseline;
gap: 0.35rem;
white-space: nowrap;
font-family: 'JetBrains Mono', monospace;
font-weight: 700;
font-size: 1rem;
letter-spacing: -0.02em;
color: var(--ink);
text-decoration: none;
}
.topbar-brand:hover { color: var(--accent); border-bottom: none; }
[data-theme="tokyo"] .topbar-brand {
color: #e8f4ff;
text-shadow: 0 0 8px rgba(100, 220, 255, 0.3);
}
.topbar-brand .brand-sep {
font-weight: 300;
color: var(--ink-dim);
}
.topbar-brand .brand-sub {
font-weight: 400;
font-size: 0.72rem;
letter-spacing: 0.18em;
text-transform: uppercase;
color: var(--ink-muted);
}
.topbar-timer {
display: inline-flex;
align-items: center;
justify-content: center;
margin-left: auto;
font-size: 0.72rem;
font-weight: 500;
letter-spacing: 0.08em;
color: var(--danger-text);
background: var(--danger-soft);
padding: 0.3rem 0.7rem;
border-radius: 2px;
border: 1px solid var(--danger);
white-space: nowrap;
}
.drawer-backdrop {
display: none;
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.45);
z-index: 40;
backdrop-filter: blur(2px);
}
/* ---- Sidebar ---- */
.sidebar {
grid-column: 1;
grid-row: 2;
border-right: 1px solid var(--border);
background: var(--bg-panel);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
display: flex;
flex-direction: column;
overflow: hidden;
min-width: 0;
transition: background 0.3s ease;
}
.sidebar-header {
padding: 1rem;
border-bottom: 1px solid var(--border);
display: flex;
align-items: center;
gap: 0.75rem;
justify-content: space-between;
}
.sidebar-title {
font-size: 0.65rem;
font-weight: 500;
text-transform: uppercase;
letter-spacing: 0.2em;
color: var(--ink-dim);
}
.close-sidebar {
display: none;
background: transparent;
border: 1px solid var(--border);
color: var(--ink-muted);
border-radius: 2px;
padding: 0.35rem 0.6rem;
cursor: pointer;
font-family: 'JetBrains Mono', monospace;
font-size: 0.68rem;
font-weight: 500;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.close-sidebar:hover { color: var(--ink); border-color: var(--ink-muted); }
#session-list {
flex: 1;
overflow-y: auto;
padding: 0.5rem;
display: flex;
flex-direction: column;
gap: 0.25rem;
-webkit-overflow-scrolling: touch;
}
#session-list::-webkit-scrollbar,
#supporter-messages::-webkit-scrollbar { width: 3px; height: 3px; }
#session-list::-webkit-scrollbar-thumb,
#supporter-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.session-item {
width: 100%;
text-align: left;
background: transparent;
border: 1px solid transparent;
border-radius: 2px;
padding: 0.7rem 0.75rem;
cursor: pointer;
color: var(--ink);
font-size: 0.85rem;
transition: background 0.15s, border-color 0.15s;
display: flex;
flex-direction: column;
gap: 0.3rem;
}
.session-item:hover { background: var(--surface-hover); border-color: var(--border); }
.session-item.selected { background: var(--surface-hover); border-color: var(--accent); }
.session-name {
font-weight: 700;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
font-size: 0.85rem;
}
.session-meta {
display: flex;
align-items: center;
gap: 0.5rem;
flex-wrap: wrap;
}
.session-badge {
font-size: 0.6rem;
padding: 0.12rem 0.45rem;
border-radius: 2px;
font-weight: 500;
text-transform: uppercase;
letter-spacing: 0.1em;
}
.status-waiting { background: var(--status-waiting-bg); color: var(--status-waiting-ink); }
.status-active { background: var(--status-active-bg); color: var(--status-active-ink); }
.status-closed { background: var(--status-closed-bg); color: var(--status-closed-ink); }
.session-count { font-size: 0.7rem; color: var(--ink-dim); }
.session-id {
font-size: 0.65rem;
color: var(--ink-dim);
font-family: 'JetBrains Mono', monospace;
letter-spacing: 0.04em;
}
.no-sessions {
padding: 1.5rem 1rem;
font-size: 0.82rem;
color: var(--ink-dim);
text-align: center;
line-height: 1.6;
}
/* ---- Main panel ---- */
.main-panel {
grid-column: 2;
grid-row: 2;
display: flex;
flex-direction: column;
align-items: center;
justify-content: stretch;
overflow: hidden;
min-width: 0;
background: var(--bg);
padding: 1rem;
}
.chat-shell {
display: flex;
flex-direction: column;
width: min(860px, 100%);
height: 100%;
background: var(--bg-panel);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
border: 1px solid var(--border);
border-radius: 3px;
overflow: hidden;
box-shadow: 0 8px 30px rgba(26, 29, 34, 0.06);
transition: background 0.3s ease, border-color 0.3s ease;
}
.main-header {
display: flex;
align-items: center;
gap: 0.55rem;
padding: 0.8rem 1rem;
border-bottom: 1px solid var(--border);
min-height: 50px;
flex-shrink: 0;
}
.active-copy {
min-width: 0;
display: flex;
flex-direction: column;
gap: 0.1rem;
}
#active-session-name {
font-weight: 700;
font-size: 0.88rem;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
#active-session-meta {
font-size: 0.65rem;
color: var(--ink-dim);
white-space: nowrap;
letter-spacing: 0.04em;
}
/* ---- Messages ---- */
#supporter-messages {
flex: 1;
min-height: 0;
overflow-y: auto;
padding: 0.9rem;
display: flex;
flex-direction: column;
gap: 0.5rem;
scroll-behavior: smooth;
-webkit-overflow-scrolling: touch;
}
.empty-state {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
color: var(--ink-dim);
gap: 0.4rem;
font-size: 0.85rem;
text-align: center;
padding: 1rem;
line-height: 1.6;
}
.msg-wrap { display: flex; }
.msg-user-wrap { justify-content: flex-start; }
.msg-supporter-wrap { justify-content: flex-end; }
.msg-user, .msg-supporter {
max-width: 78%;
padding: 0.55rem 0.8rem;
border-radius: 12px;
font-size: 0.85rem;
line-height: 1.55;
overflow-wrap: anywhere;
}
.msg-user {
background: var(--peer-bubble);
color: var(--peer-bubble-ink);
border-bottom-left-radius: 3px;
}
.msg-supporter {
background: var(--own-bubble);
color: var(--own-bubble-ink);
border-bottom-right-radius: 3px;
}
.msg-label {
display: block;
font-size: 0.62rem;
font-weight: 500;
opacity: 0.7;
margin-bottom: 2px;
text-transform: uppercase;
letter-spacing: 0.12em;
}
.msg-text { margin: 0; }
.msg-time {
display: block;
font-size: 0.6rem;
opacity: 0.5;
margin-top: 4px;
text-align: right;
letter-spacing: 0.04em;
}
.msg-system-wrap { display: flex; justify-content: center; margin: 0.25rem 0; }
.msg-system-text {
font-size: 0.7rem;
color: var(--ink-dim);
background: var(--input-bg);
padding: 0.25rem 0.75rem;
border-radius: 2px;
text-align: center;
letter-spacing: 0.04em;
}
/* ---- Typing bubble ---- */
.typing-bubble {
display: none;
padding: 0 0.9rem 0.55rem;
justify-content: flex-start;
flex-shrink: 0;
}
.typing-bubble.visible { display: flex; }
.typing-bubble-inner {
position: relative;
display: inline-flex;
align-items: center;
gap: 4px;
min-width: 48px;
padding: 0.55rem 0.75rem;
background: var(--peer-bubble);
border-radius: 12px;
border-bottom-left-radius: 3px;
}
.typing-dot {
width: 5px;
height: 5px;
border-radius: 50%;
background: var(--ink-dim);
animation: typing-bounce 1.1s infinite ease-in-out;
}
.typing-dot:nth-child(2) { animation-delay: 0.16s; }
.typing-dot:nth-child(3) { animation-delay: 0.32s; }
@keyframes typing-bounce {
0%, 75%, 100% { transform: translateY(0); opacity: 0.45; }
35% { transform: translateY(-4px); opacity: 1; }
}
/* ---- Reply area ---- */
#reply-area {
border-top: 1px solid var(--border);
padding: 0.6rem 0.85rem max(0.75rem, env(safe-area-inset-bottom));
display: none;
flex-shrink: 0;
}
#reply-area.visible { display: flex; gap: 0.45rem; }
#reply-area input[type="text"] {
flex: 1;
min-width: 0;
padding: 0.55rem 0.8rem;
background: var(--input-bg);
border: 1px solid var(--border);
border-radius: 3px;
color: var(--ink);
font-size: 0.85rem;
line-height: 1.25;
outline: none;
transition: border-color 0.2s;
}
#reply-area input[type="text"]:focus { border-color: var(--accent); }
#reply-area input[type="text"]::placeholder { color: var(--ink-dim); }
#reply-area button {
padding: 0.55rem 0.9rem;
background: var(--accent);
color: var(--bg);
border: none;
border-radius: 3px;
font-family: 'JetBrains Mono', monospace;
font-weight: 700;
font-size: 0.78rem;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
transition: opacity 0.2s;
white-space: nowrap;
}
#reply-area button:hover { opacity: 0.85; }
/* ---- Theme toggle ---- */
.theme-toggle {
position: fixed;
bottom: 1.5rem;
right: 1.5rem;
width: 28px;
height: 28px;
border-radius: 50%;
border: 1px solid var(--border);
cursor: pointer;
padding: 0;
z-index: 30;
transition: all 0.3s ease;
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}
.theme-toggle:hover { transform: scale(1.08); }
[data-theme="light"] .theme-toggle {
background: linear-gradient(135deg, #07070d 0%, #64dcff 100%);
border-color: rgba(26, 29, 34, 0.2);
}
[data-theme="tokyo"] .theme-toggle {
background: #f4f1ec;
border-color: rgba(100, 220, 255, 0.4);
box-shadow:
0 0 10px rgba(100, 220, 255, 0.5),
0 0 25px rgba(100, 220, 255, 0.3);
}
/* ---- Mobile ---- */
@media (max-width: 820px) {
.layout {
grid-template-columns: minmax(0, 1fr);
grid-template-rows: 52px minmax(0, 1fr);
}
.topbar { padding: 0 0.75rem; }
.menu-button { display: inline-flex; }
.drawer-backdrop.visible { display: block; }
.sidebar {
position: fixed;
top: 0; left: 0; bottom: 0;
height: 100%;
height: var(--app-height, 100dvh);
width: min(88vw, 320px);
border-right: 1px solid var(--border);
z-index: 50;
transform: translateX(-102%);
transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
box-shadow: 12px 0 35px rgba(0, 0, 0, 0.25);
}
.sidebar.open { transform: translateX(0); }
.close-sidebar { display: inline-flex; }
.main-panel {
grid-column: 1;
grid-row: 2;
padding: 0.65rem;
align-items: stretch;
justify-content: stretch;
}
.chat-shell {
width: 100%;
max-width: none;
height: 100%;
}
.main-header { padding: 0.75rem 0.85rem; }
.msg-user, .msg-supporter { max-width: 86%; }
#reply-area.visible { gap: 0.4rem; }
#reply-area button { padding-inline: 0.75rem; }
}
@media (max-width: 460px) {
.topbar-brand .brand-sub { display: none; }
.topbar-brand .brand-sep { display: none; }
.main-panel { padding: 0.45rem; }
.main-header { min-height: 46px; }
#supporter-messages { padding: 0.75rem; }
.theme-toggle { width: 20px; height: 20px; bottom: 1rem; right: 0.75rem; }
}
</style>
</head>
<body>
<div class="layout">
<header class="topbar">
<button class="menu-button" type="button" onclick="openSidebar()">Chats</button>
<a href="/" class="topbar-brand">
FLÓ <span class="brand-sep">/</span> <span class="brand-sub">SUPPORT</span>
</a>
<span class="topbar-timer" hx-get="/reset-countdown" hx-trigger="load, every 1s" hx-swap="innerHTML">Reset in --:--</span>
</header>
<div id="drawer-backdrop" class="drawer-backdrop" onclick="closeSidebar()"></div>
<aside id="sidebar" class="sidebar">
<div class="sidebar-header">
<span class="sidebar-title">Conversations</span>
<button class="close-sidebar" type="button" onclick="closeSidebar()">Close</button>
</div>
<div id="session-list"
hx-get="/sessions"
hx-trigger="load, refresh, every 5s"
hx-swap="innerHTML">
<p class="no-sessions">Loading...</p>
</div>
</aside>
<section class="main-panel">
<div class="chat-shell">
<div class="main-header">
<div class="active-copy">
<span id="active-session-name" style="color: var(--ink-dim)">Select a conversation</span>
<span id="active-session-meta"></span>
</div>
</div>
<div id="supporter-messages">
<div class="empty-state">
<p>No conversation selected</p>
<p>Open the chat list and choose a conversation.</p>
</div>
</div>
<div id="supporter-peer-typing" class="typing-bubble" aria-live="polite">
<span class="typing-bubble-inner" aria-label="User is typing">
<span class="typing-dot"></span><span class="typing-dot"></span><span class="typing-dot"></span>
</span>
</div>
<div id="reply-area">
<input type="text" id="reply-input" placeholder="Reply to user..." autocomplete="off" maxlength="1000" />
<button id="reply-btn">Send</button>
</div>
</div>
</section>
</div>
<button class="theme-toggle" id="theme-toggle" aria-label="Toggle theme"></button>
<script>
let activeSessionId = null;
let supporterWs = null;
let lastTypingSessionId = null;
let supporterTypingActive = false;
function setAppHeight() {
const height = window.visualViewport ? window.visualViewport.height : window.innerHeight;
document.documentElement.style.setProperty('--app-height', `${height}px`);
}
setAppHeight();
window.addEventListener('resize', setAppHeight);
if (window.visualViewport) {
window.visualViewport.addEventListener('resize', setAppHeight);
window.visualViewport.addEventListener('scroll', setAppHeight);
}
function openSidebar() {
document.getElementById('sidebar').classList.add('open');
document.getElementById('drawer-backdrop').classList.add('visible');
}
function closeSidebar() {
document.getElementById('sidebar').classList.remove('open');
document.getElementById('drawer-backdrop').classList.remove('visible');
}
function selectSession(button) {
document.querySelectorAll('.session-item').forEach(function(b) { b.classList.remove('selected'); });
button.classList.add('selected');
setActiveSession(button.dataset.sessionId, button.dataset.sessionName);
closeSidebar();
}
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 = 'Session #' + 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(--ink-dim)';
document.getElementById('active-session-meta').textContent = '';
document.getElementById('reply-area').classList.remove('visible');
hideUserTyping();
closeSidebar();
document.getElementById('supporter-messages').innerHTML = '<div class="empty-state"><p>Chat history was cleared.</p><p>New conversations will appear in the chat list.</p></div>';
htmx.trigger('#session-list', 'refresh');
}
function scrollSupporterMessages() {
const el = document.getElementById('supporter-messages');
if (el) el.scrollTop = el.scrollHeight;
}
function showUserTyping() {
const indicator = document.getElementById('supporter-peer-typing');
if (!indicator) return;
indicator.classList.add('visible');
scrollSupporterMessages();
}
function hideUserTyping() {
const indicator = document.getElementById('supporter-peer-typing');
if (indicator) indicator.classList.remove('visible');
}
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) => {
if (e.detail.target.id === 'supporter-messages') scrollSupporterMessages();
});
document.getElementById('reply-btn').addEventListener('click', () => {
if (!activeSessionId) return;
const input = document.getElementById('reply-input');
const content = input.value.trim();
if (!content) return;
stopSupporterTyping(activeSessionId);
fetch(`/supporter/send/${activeSessionId}`, {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: `content=${encodeURIComponent(content)}`
})
.then(r => r.text())
.then(html => {
const msgs = document.getElementById('supporter-messages');
msgs.insertAdjacentHTML('beforeend', html);
input.value = '';
scrollSupporterMessages();
setAppHeight();
});
});
document.getElementById('reply-input').addEventListener('keydown', (e) => {
if (e.key === 'Enter') document.getElementById('reply-btn').click();
});
document.getElementById('reply-input').addEventListener('input', handleReplyInput);
document.getElementById('reply-input').addEventListener('focus', () => setTimeout(setAppHeight, 80));
document.getElementById('reply-input').addEventListener('blur', () => setTimeout(setAppHeight, 80));
function connectSupporterWS() {
const wsProtocol = location.protocol === 'https:' ? 'wss' : 'ws';
supporterWs = new WebSocket(`${wsProtocol}://${location.host}/ws/supporter/dashboard`);
supporterWs.onmessage = (e) => {
const data = e.data;
if (data === '__reset__') {
resetSupporterDashboard();
return;
}
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(`/supporter/messages/${activeSessionId}`)
.then(r => r.text())
.then(html => {
document.getElementById('supporter-messages').innerHTML = html;
scrollSupporterMessages();
});
}
};
supporterWs.onopen = () => {
if (supporterTypingActive && lastTypingSessionId) sendSupporterTypingState('start', lastTypingSessionId);
};
supporterWs.onclose = () => setTimeout(connectSupporterWS, 2000);
}
connectSupporterWS();
// Theme toggle
(() => {
function currentSystemTheme() {
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'tokyo' : 'light';
}
const btn = document.getElementById('theme-toggle');
if (btn) {
btn.addEventListener('click', () => {
const current = document.documentElement.getAttribute('data-theme') || 'light';
const next = current === 'light' ? 'tokyo' : 'light';
document.documentElement.setAttribute('data-theme', next);
localStorage.setItem('poc-theme', next);
});
}
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {
if (!localStorage.getItem('poc-theme')) {
document.documentElement.setAttribute('data-theme', currentSystemTheme());
}
});
})();
</script>
</body>
</html>