This commit is contained in:
Bartal Læarsson
2026-06-18 12:02:58 +01:00
parent df0a578207
commit f24da78970
9 changed files with 1250 additions and 96 deletions
+117
View File
@@ -0,0 +1,117 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Support Chat</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;
--surface-soft: #20242c;
--border: #2b303a;
--accent: #8f9cff;
--text: #eceff4;
--muted: #9aa3b2;
--radius: 14px;
}
body {
min-height: 100vh;
background: var(--bg);
color: var(--text);
font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
display: flex;
align-items: center;
justify-content: center;
padding: 1.5rem;
}
.card {
width: min(560px, 100%);
background: var(--surface);
border: 1px solid var(--border);
border-radius: 22px;
padding: 2rem;
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.25);
}
.timer {
display: inline-flex;
margin-bottom: 1rem;
color: var(--muted);
border: 1px solid var(--border);
border-radius: 999px;
padding: 0.35rem 0.75rem;
font-size: 0.78rem;
background: var(--bg);
}
h1 {
font-size: clamp(1.6rem, 4vw, 2.15rem);
letter-spacing: -0.035em;
margin-bottom: 0.5rem;
}
p {
color: var(--muted);
line-height: 1.6;
margin-bottom: 1.5rem;
}
.choices {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 0.9rem;
}
a {
display: flex;
flex-direction: column;
gap: 0.35rem;
text-decoration: none;
color: var(--text);
background: var(--surface-soft);
border: 1px solid var(--border);
border-radius: var(--radius);
padding: 1.1rem;
transition: transform 0.15s, border-color 0.15s, background 0.15s;
}
a:hover {
transform: translateY(-1px);
border-color: var(--accent);
background: #242936;
}
.role-title { font-weight: 700; font-size: 1rem; }
.role-detail { color: var(--muted); font-size: 0.88rem; }
@media (max-width: 560px) {
.choices { grid-template-columns: 1fr; }
.card { padding: 1.5rem; }
}
</style>
</head>
<body>
<main class="card">
<span class="timer" hx-get="/reset-countdown" hx-trigger="load, every 1s" hx-swap="innerHTML">Reset in --:--</span>
<h1>Support chat</h1>
<p>Open the side you want to test. Each option opens in a new tab.</p>
<div class="choices">
<a href="/user" target="_blank" rel="noopener noreferrer">
<span class="role-title">User</span>
<span class="role-detail">Start a new conversation</span>
</a>
<a href="/supporter" target="_blank" rel="noopener noreferrer">
<span class="role-title">Supporter</span>
<span class="role-detail">View and reply to conversations</span>
</a>
</div>
</main>
</body>
</html>
+487
View File
@@ -0,0 +1,487 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<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;
--text: #eceff4;
--muted: #9aa3b2;
--user: #8f9cff;
--supporter: #2b303a;
--radius: 10px;
}
html, body {
height: 100%;
background: var(--bg);
font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
color: var(--text);
overflow: hidden;
}
.layout {
display: grid;
grid-template-columns: 280px 1fr;
grid-template-rows: 56px 1fr;
height: 100vh;
}
.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(--surface);
}
.topbar h1 {
font-size: 1rem;
font-weight: 700;
letter-spacing: -0.01em;
}
.topbar-timer {
margin-left: auto;
font-size: 0.78rem;
color: var(--muted);
background: var(--bg);
padding: 0.25rem 0.65rem;
border-radius: 20px;
border: 1px solid var(--border);
}
.sidebar {
border-right: 1px solid var(--border);
display: flex;
flex-direction: column;
overflow: hidden;
}
.sidebar-header {
padding: 1rem;
border-bottom: 1px solid var(--border);
font-size: 0.78rem;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.08em;
color: var(--muted);
}
#session-list {
flex: 1;
overflow-y: auto;
padding: 0.5rem;
display: flex;
flex-direction: column;
gap: 0.3rem;
}
#session-list::-webkit-scrollbar { width: 4px; }
#session-list::-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.7rem 0.8rem;
cursor: pointer;
color: var(--text);
font-size: 0.88rem;
transition: background 0.15s, border-color 0.15s;
display: flex;
flex-direction: column;
gap: 0.3rem;
}
.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; }
.session-meta {
display: flex;
align-items: center;
gap: 0.5rem;
}
.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.85rem;
color: var(--muted);
text-align: center;
}
.main-panel {
display: flex;
flex-direction: column;
overflow: hidden;
}
.main-header {
padding: 0.9rem 1.5rem;
border-bottom: 1px solid var(--border);
display: flex;
align-items: center;
gap: 0.5rem;
min-height: 56px;
}
#active-session-name {
font-weight: 700;
font-size: 1rem;
}
#active-session-meta {
font-size: 0.8rem;
color: var(--muted);
}
#supporter-messages {
flex: 1;
overflow-y: auto;
padding: 1.2rem 1.5rem;
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;
flex-direction: column;
align-items: center;
justify-content: center;
color: var(--muted);
gap: 0.5rem;
font-size: 0.9rem;
}
.msg-wrap { display: flex; }
.msg-user-wrap { justify-content: flex-end; }
.msg-supporter-wrap { justify-content: flex-start; }
.msg-user, .msg-supporter {
max-width: 65%;
padding: 0.6rem 0.9rem;
border-radius: 16px;
font-size: 0.88rem;
line-height: 1.5;
}
.msg-user {
background: var(--user);
color: #111318;
border-bottom-right-radius: 4px;
}
.msg-supporter {
background: var(--supporter);
color: var(--text);
border-bottom-left-radius: 4px;
}
.msg-label {
display: block;
font-size: 0.7rem;
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.68rem;
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;
}
.typing-bubble {
display: none;
padding: 0 1.5rem 0.55rem;
justify-content: flex-start;
}
.typing-bubble.visible { display: flex; }
.typing-bubble-inner {
display: inline-flex;
align-items: center;
gap: 4px;
min-width: 48px;
padding: 0.65rem 0.85rem;
background: var(--supporter);
border-radius: 16px;
border-bottom-left-radius: 4px;
}
.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.75rem 1.5rem;
display: none;
}
#reply-area.visible { display: flex; gap: 0.6rem; }
#reply-area input[type="text"] {
flex: 1;
padding: 0.65rem 1rem;
background: var(--surface);
border: 1px solid var(--border);
border-radius: var(--radius);
color: var(--text);
font-size: 0.9rem;
outline: none;
transition: border-color 0.2s;
}
#reply-area input[type="text"]:focus { border-color: var(--accent); }
#reply-area button {
padding: 0.65rem 1.2rem;
background: var(--accent);
color: #111318;
border: none;
border-radius: var(--radius);
font-weight: 700;
font-size: 0.88rem;
cursor: pointer;
transition: background 0.2s;
}
#reply-area button:hover { background: var(--accent-dim); }
</style>
</head>
<body>
<div class="layout">
<header class="topbar">
<h1>Support dashboard</h1>
<span class="topbar-timer" hx-get="/reset-countdown" hx-trigger="load, every 1s" hx-swap="innerHTML">Reset in --:--</span>
</header>
<aside class="sidebar">
<div class="sidebar-header">Conversations</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="main-header">
<span id="active-session-name" style="color: var(--muted)">Select a conversation</span>
<span id="active-session-meta"></span>
</div>
<div id="supporter-messages">
<div class="empty-state">
<p>No conversation selected</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>
</section>
</div>
<script>
let activeSessionId = null;
let supporterWs = null;
let typingHideTimer = null;
let lastTypingSent = 0;
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);
}
function setActiveSession(sessionId, name) {
activeSessionId = sessionId;
document.getElementById('active-session-name').textContent = name;
document.getElementById('active-session-meta').textContent = '#' + sessionId.slice(0, 8);
document.getElementById('reply-area').classList.add('visible');
hideUserTyping();
scrollSupporterMessages();
}
function resetSupporterDashboard() {
activeSessionId = null;
document.getElementById('active-session-name').textContent = 'Select a conversation';
document.getElementById('active-session-meta').textContent = '';
document.getElementById('reply-area').classList.remove('visible');
hideUserTyping();
document.getElementById('supporter-messages').innerHTML = '<div class="empty-state"><p>Chat history was cleared. New conversations will appear here.</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');
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}`);
}
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;
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);
scrollSupporterMessages();
input.value = '';
});
});
document.getElementById('reply-input').addEventListener('keydown', (e) => {
if (e.key === 'Enter') document.getElementById('reply-btn').click();
});
document.getElementById('reply-input').addEventListener('input', sendSupporterTyping);
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:')) {
const sessionId = data.replace('typing:user:', '');
if (sessionId === activeSessionId) showUserTyping();
return;
}
if (data.startsWith('typing:supporter:')) return;
htmx.trigger('#session-list', 'refresh');
if (data === activeSessionId) {
fetch(`/messages/${activeSessionId}`)
.then(r => r.text())
.then(html => {
document.getElementById('supporter-messages').innerHTML = html;
scrollSupporterMessages();
});
}
};
supporterWs.onclose = () => setTimeout(connectSupporterWS, 2000);
}
connectSupporterWS();
</script>
</body>
</html>
+364
View File
@@ -0,0 +1,364 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Support Chat</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;
--surface-soft: #20242c;
--border: #2b303a;
--accent: #8f9cff;
--accent-dim: #737fd3;
--text: #eceff4;
--muted: #9aa3b2;
--user: #8f9cff;
--supporter: #2b303a;
--radius: 12px;
}
body {
background: var(--bg);
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
color: var(--text);
padding: 1rem;
}
.page-timer {
position: fixed;
top: 1rem;
left: 50%;
transform: translateX(-50%);
color: var(--muted);
border: 1px solid var(--border);
border-radius: 999px;
padding: 0.35rem 0.75rem;
font-size: 0.78rem;
background: var(--surface);
z-index: 10;
}
#start-form {
background: var(--surface);
border: 1px solid var(--border);
border-radius: 20px;
padding: 2.2rem;
width: min(360px, 100%);
text-align: left;
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.22);
}
#start-form h1 {
font-size: 1.35rem;
font-weight: 700;
margin-bottom: 0.45rem;
letter-spacing: -0.02em;
}
#start-form p {
font-size: 0.9rem;
color: var(--muted);
margin-bottom: 1.5rem;
line-height: 1.55;
}
#start-form input[type="text"] {
width: 100%;
padding: 0.75rem 1rem;
background: var(--bg);
border: 1px solid var(--border);
border-radius: var(--radius);
color: var(--text);
font-size: 0.95rem;
margin-bottom: 1rem;
outline: none;
transition: border-color 0.2s;
}
#start-form input[type="text"]:focus { border-color: var(--accent); }
#start-form button {
width: 100%;
padding: 0.75rem;
background: var(--accent);
color: #111318;
border: none;
border-radius: var(--radius);
font-size: 0.95rem;
font-weight: 700;
cursor: pointer;
transition: background 0.2s;
}
#start-form button:hover { background: var(--accent-dim); }
#chat-container {
display: none;
flex-direction: column;
width: min(390px, 100%);
height: min(600px, calc(100vh - 4.5rem));
background: var(--surface);
border: 1px solid var(--border);
border-radius: 20px;
overflow: hidden;
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.22);
}
#chat-header {
display: flex;
align-items: center;
gap: 0.6rem;
padding: 1rem 1.2rem;
border-bottom: 1px solid var(--border);
font-weight: 700;
font-size: 0.95rem;
}
.chat-session-id {
margin-left: auto;
font-size: 0.75rem;
color: var(--muted);
font-weight: 400;
}
#messages {
flex: 1;
overflow-y: auto;
padding: 1rem;
display: flex;
flex-direction: column;
gap: 0.5rem;
scroll-behavior: smooth;
}
#messages::-webkit-scrollbar { width: 4px; }
#messages::-webkit-scrollbar-track { background: transparent; }
#messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.msg-wrap { display: flex; }
.msg-user-wrap { justify-content: flex-end; }
.msg-supporter-wrap { justify-content: flex-start; }
.msg-user, .msg-supporter {
max-width: 75%;
padding: 0.6rem 0.9rem;
border-radius: 16px;
font-size: 0.88rem;
line-height: 1.5;
}
.msg-user {
background: var(--user);
color: #111318;
border-bottom-right-radius: 4px;
}
.msg-supporter {
background: var(--supporter);
color: var(--text);
border-bottom-left-radius: 4px;
}
.msg-label {
display: block;
font-size: 0.7rem;
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.68rem;
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;
}
.typing-bubble {
display: none;
padding: 0 1rem 0.55rem;
justify-content: flex-start;
}
.typing-bubble.visible { display: flex; }
.typing-bubble-inner {
display: inline-flex;
align-items: center;
gap: 4px;
min-width: 48px;
padding: 0.65rem 0.85rem;
background: var(--supporter);
border-radius: 16px;
border-bottom-left-radius: 4px;
}
.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; }
}
#chat-form {
display: flex;
gap: 0.5rem;
padding: 0.75rem 1rem;
border-top: 1px solid var(--border);
}
#chat-form input[type="text"] {
flex: 1;
padding: 0.6rem 0.9rem;
background: var(--bg);
border: 1px solid var(--border);
border-radius: var(--radius);
color: var(--text);
font-size: 0.9rem;
outline: none;
transition: border-color 0.2s;
}
#chat-form input[type="text"]:focus { border-color: var(--accent); }
#chat-form button {
padding: 0.6rem 1.1rem;
background: var(--accent);
color: #111318;
border: none;
border-radius: var(--radius);
font-weight: 700;
font-size: 0.88rem;
cursor: pointer;
transition: background 0.2s;
}
#chat-form button:hover { background: var(--accent-dim); }
</style>
</head>
<body>
<span class="page-timer" hx-get="/reset-countdown" hx-trigger="load, every 1s" hx-swap="innerHTML">Reset in --:--</span>
<div id="start-form">
<h1>Talk to support</h1>
<p>Start a conversation and a supporter can reply from the dashboard.</p>
<form hx-post="/sessions/new"
hx-target="body"
hx-swap="beforeend">
<input type="text" name="name" placeholder="Your name (optional)" maxlength="40" />
<button type="submit">Start chat</button>
</form>
</div>
<div id="chat-container"></div>
<script>
let ws = null;
let typingHideTimer = null;
let lastTypingSent = 0;
function scrollMessages() {
const el = document.getElementById('messages');
if (el) el.scrollTop = el.scrollHeight;
}
function showSupporterTyping() {
const indicator = document.getElementById('peer-typing');
if (!indicator) return;
indicator.classList.add('visible');
clearTimeout(typingHideTimer);
typingHideTimer = setTimeout(() => indicator.classList.remove('visible'), 1400);
scrollMessages();
}
function sendUserTyping() {
if (!ws || ws.readyState !== WebSocket.OPEN || !window.__sessionId) return;
const now = Date.now();
if (now - lastTypingSent < 500) return;
lastTypingSent = now;
ws.send(`typing:user:${window.__sessionId}`);
}
document.addEventListener('htmx:afterSwap', (e) => {
if (e.detail.target.id === 'messages') scrollMessages();
});
function resetChat() {
const oldWs = ws;
ws = null;
window.__sessionId = null;
if (oldWs) oldWs.close();
const startForm = document.getElementById('start-form');
const chatContainer = document.getElementById('chat-container');
startForm.style.display = 'block';
chatContainer.style.display = 'none';
chatContainer.innerHTML = '';
alert('Chat history was cleared. Please start a new chat.');
}
document.addEventListener('htmx:afterRequest', (e) => {
if (e.detail.requestConfig?.path === '/sessions/new' && !ws) {
const container = document.getElementById('chat-container');
if (!container) return;
const match = container.innerHTML.match(/\/messages\/([a-f0-9-]+)/);
if (!match) return;
const sessionId = match[1];
window.__sessionId = sessionId;
const wsProtocol = location.protocol === 'https:' ? 'wss' : 'ws';
ws = new WebSocket(`${wsProtocol}://${location.host}/ws/user/${sessionId}`);
ws.onmessage = (message) => {
if (message.data === '__reset__') {
resetChat();
return;
}
if (message.data.startsWith('typing:supporter:')) {
showSupporterTyping();
return;
}
if (message.data.startsWith('typing:user:')) return;
htmx.trigger('#messages', 'refresh');
};
ws.onerror = () => console.warn('WebSocket error; polling will continue.');
}
});
</script>
</body>
</html>