Repository navigation
Expand file tree
/
Copy pathchat.html
More file actions
165 lines (142 loc) · 7.07 KB
/
Copy pathchat.html
File metadata and controls
165 lines (142 loc) · 7.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Inbox - rnxJS</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<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=Archivo:wght@600;700&family=JetBrains+Mono:wght@400;500&family=Public+Sans:wght@400;500;600&display=swap" rel="stylesheet">
<link rel="stylesheet" href="index.css">
<link rel="stylesheet" href="demo.css">
</head>
<body>
<div class="topbar">
<div class="shell topbar-in mono">
<a class="wordmark" href="./" style="color:inherit;text-decoration:none">rnxJS</a>
<span class="sep">/</span>
<span>inbox</span>
<span class="spacer"></span>
<a class="chan" href="./"><i class="bi bi-arrow-left"></i> All demos</a>
</div>
</div>
<div class="shell">
<header class="page-head">
<div class="titles">
<h1>Ticket conversation</h1>
<p class="sub">
A list that appends without re-rendering the whole thread, and an
input bound to reactive state.
</p>
</div>
</header>
<section class="grid-sidebar">
<nav class="panel">
<div class="panel-head"><h2>Threads</h2></div>
<div class="side-nav" data-ref="threads"></div>
</nav>
<div class="panel chat-panel">
<div class="panel-head">
<h2 data-ref="threadTitle"></h2>
<p class="hint" data-ref="threadMeta"></p>
</div>
<div class="thread" data-ref="thread"></div>
<div class="composer">
<div data-ref="composer" style="flex:1"></div>
<div data-ref="send"></div>
</div>
</div>
</section>
</div>
<footer style="margin-top:2.5rem">
<div class="shell" style="display:flex;gap:1.25rem;flex-wrap:wrap;align-items:center;">
<span class="mono" data-ref="footVersion">rnxJS</span>
<a href="./">All demos</a>
<a href="https://github.com/BaryoDev/rnxJS_samples">Source</a>
<span style="margin-left:auto" class="mono">MPL-2.0</span>
</div>
</footer>
<script src="https://cdn.jsdelivr.net/npm/@arnelirobles/rnxjs@2.3.1/dist/rnx.global.js"></script>
<script>
const { Input, Button, createReactiveState } = rnx;
const $ = (ref) => document.querySelector(`[data-ref="${ref}"]`);
const THREADS = {
'SUP-4182': {
account: 'Northwind Freight', who: 'Priya Raman', unread: 2,
messages: [
['them', 'Priya Raman', 'Our renewal card was declined this morning but the card is fine, we used it elsewhere an hour ago.', '09:14'],
['me', 'You', 'Thanks Priya. I can see two attempts at 08:52 and 08:58, both returned a soft decline from the issuer rather than from us.', '09:21'],
['them', 'Priya Raman', 'So it is on the bank side?', '09:23'],
['me', 'You', 'Most likely. I have paused the retry schedule so it will not lock the card. Can you ask them to allow a recurring charge from us?', '09:26'],
['them', 'Priya Raman', 'Doing that now. How long do we have?', '09:31'],
],
},
'SUP-4179': {
account: 'Halden Media', who: 'Tomas Vlk', unread: 0,
messages: [
['them', 'Tomas Vlk', 'SSO login loops back to the sign-in page on Safari only. Chrome is fine.', '08:02'],
['me', 'You', 'That usually means the session cookie is being dropped. Is Prevent Cross-Site Tracking on?', '08:40'],
['them', 'Tomas Vlk', 'It is, yes.', '08:44'],
],
},
'SUP-4171': {
account: 'Cedarlane Health', who: 'Marta Nowak', unread: 0,
messages: [
['them', 'Marta Nowak', 'The CSV export is missing the last column since Friday.', 'Mon'],
['me', 'You', 'Reproduced. It only affects exports with a filter applied. Fix is in the next release.', 'Mon'],
],
},
};
const state = createReactiveState({ open: 'SUP-4182', draft: '' });
const composer = Input({ placeholder: 'Write a reply' });
const sendBtn = Button({ label: 'Send', icon: 'send', variant: 'primary' });
$('composer').append(composer);
$('send').append(sendBtn);
const input = composer.querySelector('input') || composer;
function renderThreads() {
$('threads').innerHTML = Object.entries(THREADS).map(([ref, t]) => `
<a href="#${ref}" data-ref-id="${ref}" aria-current="${state.open === ref}">
<span class="mono" style="font-size:0.75rem">${ref}</span>
<span style="display:block;font-size:0.82rem;color:var(--faint)">${t.account}</span>
</a>`).join('');
}
function renderThread() {
const t = THREADS[state.open];
$('threadTitle').textContent = state.open;
$('threadMeta').textContent = `${t.account} · ${t.who}`;
$('thread').innerHTML = t.messages.map(([side, who, text, when]) => `
<div class="msg ${side}">
<div class="bubble">${text}</div>
<div class="meta mono">${who} · ${when}</div>
</div>`).join('');
$('thread').scrollTop = $('thread').scrollHeight;
}
function send() {
const text = input.value.trim();
if (!text) return;
const now = new Date();
const when = String(now.getHours()).padStart(2, '0') + ':' + String(now.getMinutes()).padStart(2, '0');
THREADS[state.open].messages.push(['me', 'You', text, when]);
input.value = '';
state.draft = '';
renderThread();
}
(sendBtn.querySelector('button') || sendBtn).addEventListener('click', send);
input.addEventListener('keydown', (e) => { if (e.key === 'Enter') send(); });
$('threads').addEventListener('click', (e) => {
const a = e.target.closest('[data-ref-id]');
if (!a) return;
e.preventDefault();
state.open = a.dataset.refId;
renderThreads();
renderThread();
});
renderThreads();
renderThread();
const build = (document.documentElement.dataset.rnxVersion || '').trim();
if (build) $('footVersion').textContent = 'rnxJS ' + build;
</script>
</body>
</html>