-
Notifications
You must be signed in to change notification settings - Fork 1
/
client-demo-raw.html
43 lines (33 loc) · 1.14 KB
/
client-demo-raw.html
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
<h1>Hi guys!</h1>
You can view the raw <a href="/feed">/feed</a>, or play with the UI below.
<h2>Feed</h2>
<pre id=feed-pre></pre>
<div id=feed-post></div>
<br>
<textarea id=subject placeholder=subject></textarea>
<textarea id=body placeholder=body></textarea>
<input type=button value='new post' onclick='make_new_post()' />
<script type=module>
import * as client from '/feed-client.js'
var feed = []
client.subscribe_to_feed('/feed', new_feed => { feed = new_feed; render() })
function render () {
document.getElementById('feed-post').innerHTML =
feed.map(post =>
`<p><a href='${post.url}'><code style='font-size:10'>${post.url}</code></a><br>
<b>${post.subject || ''}</b><br>
${post.body}</p>`
).join('\n')
}
// Make new post
function make_new_post () {
client.make_new_post('', {
subject: document.getElementById('subject').value,
body: document.getElementById('body').value
})
// Now clear the form
document.getElementById('subject').value = ''
document.getElementById('body').value = ''
}
window.make_new_post = make_new_post
</script>