758 lines
21 KiB
HTML
758 lines
21 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</title>
|
|
<script src="https://unpkg.com/htmx.org@1.9.12"></script>
|
|
<style>
|
|
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
|
|
|
|
:root {
|
|
--bg: #111318;
|
|
--surface: #191c22;
|
|
--surface2: #20242c;
|
|
--border: #2b303a;
|
|
--accent: #8f9cff;
|
|
--accent-dim: #737fd3;
|
|
--danger: #d93d3d;
|
|
--danger-soft: rgba(217, 61, 61, 0.16);
|
|
--danger-text: #ffd1d1;
|
|
--text: #eceff4;
|
|
--muted: #9aa3b2;
|
|
--own: #8f9cff;
|
|
--peer: #2b303a;
|
|
--radius: 12px;
|
|
}
|
|
|
|
html, body {
|
|
width: 100%;
|
|
height: 100%;
|
|
height: var(--app-height, 100dvh);
|
|
background: var(--bg);
|
|
font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
|
color: var(--text);
|
|
overflow: hidden;
|
|
-webkit-text-size-adjust: 100%;
|
|
}
|
|
|
|
button, input { font: inherit; }
|
|
|
|
.layout {
|
|
display: grid;
|
|
grid-template-columns: 320px minmax(0, 1fr);
|
|
grid-template-rows: 58px minmax(0, 1fr);
|
|
width: 100%;
|
|
height: 100%;
|
|
height: var(--app-height, 100dvh);
|
|
overflow: hidden;
|
|
}
|
|
|
|
.topbar {
|
|
grid-column: 1 / -1;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.75rem;
|
|
padding: 0.6rem 1rem;
|
|
border-bottom: 1px solid var(--border);
|
|
background: var(--surface);
|
|
min-width: 0;
|
|
}
|
|
|
|
.menu-button {
|
|
display: none;
|
|
background: var(--surface2);
|
|
color: var(--text);
|
|
border: 1px solid var(--border);
|
|
border-radius: 10px;
|
|
padding: 0.55rem 0.75rem;
|
|
font-size: 0.9rem;
|
|
font-weight: 700;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.topbar h1 {
|
|
font-size: 1rem;
|
|
font-weight: 700;
|
|
letter-spacing: -0.01em;
|
|
min-width: 0;
|
|
white-space: nowrap;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
}
|
|
|
|
.topbar-timer {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
margin-left: auto;
|
|
font-size: 0.86rem;
|
|
color: var(--danger-text);
|
|
background: var(--danger-soft);
|
|
padding: 0.42rem 0.85rem;
|
|
border-radius: 999px;
|
|
border: 1px solid var(--danger);
|
|
font-weight: 850;
|
|
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;
|
|
}
|
|
|
|
.drawer-backdrop {
|
|
display: none;
|
|
position: fixed;
|
|
inset: 0;
|
|
background: rgba(0, 0, 0, 0.58);
|
|
z-index: 40;
|
|
}
|
|
|
|
.sidebar {
|
|
grid-column: 1;
|
|
grid-row: 2;
|
|
border-right: 1px solid var(--border);
|
|
background: var(--surface);
|
|
display: flex;
|
|
flex-direction: column;
|
|
overflow: hidden;
|
|
min-width: 0;
|
|
}
|
|
|
|
.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.78rem;
|
|
font-weight: 700;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.08em;
|
|
color: var(--muted);
|
|
}
|
|
|
|
.close-sidebar {
|
|
display: none;
|
|
background: transparent;
|
|
border: 1px solid var(--border);
|
|
color: var(--text);
|
|
border-radius: 10px;
|
|
padding: 0.5rem 0.7rem;
|
|
cursor: pointer;
|
|
font-size: 0.9rem;
|
|
font-weight: 700;
|
|
}
|
|
|
|
#session-list {
|
|
flex: 1;
|
|
overflow-y: auto;
|
|
padding: 0.55rem;
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 0.35rem;
|
|
-webkit-overflow-scrolling: touch;
|
|
}
|
|
|
|
#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%;
|
|
text-align: left;
|
|
background: transparent;
|
|
border: 1px solid transparent;
|
|
border-radius: var(--radius);
|
|
padding: 0.8rem;
|
|
cursor: pointer;
|
|
color: var(--text);
|
|
font-size: 0.9rem;
|
|
transition: background 0.15s, border-color 0.15s;
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 0.35rem;
|
|
}
|
|
|
|
.session-item:hover { background: var(--surface2); border-color: var(--border); }
|
|
.session-item.selected { background: var(--surface2); border-color: var(--accent); }
|
|
|
|
.session-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
|
|
.session-meta {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.5rem;
|
|
flex-wrap: wrap;
|
|
}
|
|
|
|
.session-badge {
|
|
font-size: 0.68rem;
|
|
padding: 0.15rem 0.5rem;
|
|
border-radius: 20px;
|
|
font-weight: 700;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.04em;
|
|
}
|
|
|
|
.status-waiting { background: rgba(220, 173, 43, 0.15); color: #dcad2b; }
|
|
.status-active { background: rgba(143, 156, 255, 0.16); color: var(--accent); }
|
|
.status-closed { background: rgba(154, 163, 178, 0.12); color: var(--muted); }
|
|
|
|
.session-count { font-size: 0.75rem; color: var(--muted); }
|
|
.session-id { font-size: 0.7rem; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
|
|
|
|
.no-sessions {
|
|
padding: 1.5rem 1rem;
|
|
font-size: 0.88rem;
|
|
color: var(--muted);
|
|
text-align: center;
|
|
line-height: 1.5;
|
|
}
|
|
|
|
.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: 1.1rem;
|
|
}
|
|
|
|
.chat-shell {
|
|
display: flex;
|
|
flex-direction: column;
|
|
width: min(960px, 100%);
|
|
height: 100%;
|
|
background: var(--surface);
|
|
border: 1px solid var(--border);
|
|
border-radius: 20px;
|
|
overflow: hidden;
|
|
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.22);
|
|
}
|
|
|
|
.main-header {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.55rem;
|
|
padding: 0.9rem 1rem;
|
|
border-bottom: 1px solid var(--border);
|
|
min-height: 52px;
|
|
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.96rem;
|
|
min-width: 0;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
white-space: nowrap;
|
|
}
|
|
|
|
#active-session-meta {
|
|
font-size: 0.72rem;
|
|
color: var(--muted);
|
|
white-space: nowrap;
|
|
}
|
|
|
|
#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(--muted);
|
|
gap: 0.5rem;
|
|
font-size: 0.9rem;
|
|
text-align: center;
|
|
padding: 1rem;
|
|
line-height: 1.5;
|
|
}
|
|
|
|
.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.58rem 0.85rem;
|
|
border-radius: 16px;
|
|
font-size: 0.9rem;
|
|
line-height: 1.48;
|
|
overflow-wrap: anywhere;
|
|
}
|
|
|
|
.msg-user {
|
|
background: var(--peer);
|
|
color: var(--text);
|
|
border-bottom-left-radius: 4px;
|
|
}
|
|
|
|
.msg-supporter {
|
|
background: var(--own);
|
|
color: #111318;
|
|
border-bottom-right-radius: 4px;
|
|
}
|
|
|
|
.msg-label {
|
|
display: block;
|
|
font-size: 0.68rem;
|
|
font-weight: 600;
|
|
opacity: 0.7;
|
|
margin-bottom: 2px;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.05em;
|
|
}
|
|
|
|
.msg-text { margin: 0; }
|
|
|
|
.msg-time {
|
|
display: block;
|
|
font-size: 0.66rem;
|
|
opacity: 0.55;
|
|
margin-top: 4px;
|
|
text-align: right;
|
|
}
|
|
|
|
.msg-system-wrap { display: flex; justify-content: center; margin: 0.25rem 0; }
|
|
.msg-system-text {
|
|
font-size: 0.75rem;
|
|
color: var(--muted);
|
|
background: var(--bg);
|
|
padding: 0.25rem 0.75rem;
|
|
border-radius: 20px;
|
|
text-align: center;
|
|
}
|
|
|
|
.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.58rem 0.78rem;
|
|
background: var(--peer);
|
|
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(--peer);
|
|
transform: rotate(45deg);
|
|
border-radius: 2px;
|
|
}
|
|
|
|
.typing-dot {
|
|
width: 6px;
|
|
height: 6px;
|
|
border-radius: 50%;
|
|
background: var(--muted);
|
|
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(-5px); opacity: 1; }
|
|
}
|
|
|
|
#reply-area {
|
|
border-top: 1px solid var(--border);
|
|
padding: 0.65rem 0.85rem max(0.8rem, 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.62rem 0.85rem;
|
|
background: var(--bg);
|
|
border: 1px solid var(--border);
|
|
border-radius: var(--radius);
|
|
color: var(--text);
|
|
font-size: 16px;
|
|
line-height: 1.25;
|
|
outline: none;
|
|
transition: border-color 0.2s;
|
|
}
|
|
|
|
#reply-area input[type="text"]:focus { border-color: var(--accent); }
|
|
|
|
#reply-area button {
|
|
padding: 0.62rem 0.95rem;
|
|
background: var(--accent);
|
|
color: #111318;
|
|
border: none;
|
|
border-radius: var(--radius);
|
|
font-weight: 700;
|
|
font-size: 0.92rem;
|
|
cursor: pointer;
|
|
transition: background 0.2s;
|
|
white-space: nowrap;
|
|
}
|
|
|
|
#reply-area button:hover { background: var(--accent-dim); }
|
|
|
|
@media (max-width: 820px) {
|
|
.layout {
|
|
display: grid;
|
|
grid-template-columns: minmax(0, 1fr);
|
|
grid-template-rows: 58px minmax(0, 1fr);
|
|
}
|
|
|
|
.topbar {
|
|
min-height: 58px;
|
|
padding: 0.55rem 0.75rem;
|
|
}
|
|
|
|
.menu-button { display: inline-flex; }
|
|
|
|
.topbar h1 { font-size: 0.95rem; }
|
|
|
|
.topbar-timer {
|
|
font-size: 0.78rem;
|
|
padding: 0.36rem 0.65rem;
|
|
}
|
|
|
|
.drawer-backdrop.visible { display: block; }
|
|
|
|
.sidebar {
|
|
position: fixed;
|
|
top: 0;
|
|
left: 0;
|
|
bottom: 0;
|
|
height: 100%;
|
|
height: var(--app-height, 100dvh);
|
|
width: min(88vw, 340px);
|
|
border-right: 1px solid var(--border);
|
|
z-index: 50;
|
|
transform: translateX(-102%);
|
|
transition: transform 0.2s ease;
|
|
box-shadow: 16px 0 40px rgba(0, 0, 0, 0.35);
|
|
}
|
|
|
|
.sidebar.open { transform: translateX(0); }
|
|
.close-sidebar { display: inline-flex; }
|
|
|
|
.main-panel {
|
|
grid-column: 1;
|
|
grid-row: 2;
|
|
padding: 0.75rem;
|
|
align-items: stretch;
|
|
justify-content: stretch;
|
|
}
|
|
|
|
.chat-shell {
|
|
width: 100%;
|
|
max-width: none;
|
|
height: 100%;
|
|
border-radius: 18px;
|
|
}
|
|
|
|
.main-header { padding: 0.8rem 0.9rem; }
|
|
.msg-user, .msg-supporter { max-width: 86%; }
|
|
#reply-area.visible { gap: 0.4rem; }
|
|
#reply-area button { padding-inline: 0.85rem; }
|
|
}
|
|
|
|
@media (max-width: 460px) {
|
|
.topbar h1 { display: none; }
|
|
.topbar-timer { flex: 1; margin-left: 0; }
|
|
.main-panel { padding: 0.55rem; }
|
|
.chat-shell { border-radius: 16px; }
|
|
.main-header { min-height: 50px; }
|
|
#supporter-messages { padding: 0.8rem; }
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<div class="layout">
|
|
<header class="topbar">
|
|
<button class="menu-button" type="button" onclick="openSidebar()">Chats</button>
|
|
<h1>Support dashboard</h1>
|
|
<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(--muted)">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>
|
|
|
|
<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(--muted)';
|
|
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();
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|