From d4e69ef860b7715536bde821f49b1d2830338df2 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Fri, 19 Apr 2019 09:58:39 -0500 Subject: move composer to lib --- lib.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'lib.js') diff --git a/lib.js b/lib.js index 6062940..23a570e 100644 --- a/lib.js +++ b/lib.js @@ -1,5 +1,7 @@ // generate a public.private keypair with TweetNaCl.js + + function requestFeed (src, server) { var ws = new WebSocket(server + src) @@ -106,6 +108,37 @@ function publish (content, keys) { }) } +function compose (keys) { + var message = h('div', {classList: 'message'}) + + var scroller = document.getElementById('scroller') + + scroller.insertBefore(message, scroller.firstChild) + + var textarea = h('textarea', {placeholder: 'Write a new bog post'}) + + message.appendChild(textarea) + + var composer = h('div', [ + h('button', { + onclick: function () { + if (textarea.value) { + var content = { + author: keys.publicKey, + type: 'post', + text: textarea.value, + timestamp: Date.now() + } + textarea.value = '' + publish(content, keys) + } + } + }, ['Publish']) + ]) + message.appendChild(composer) +} + + // update your log in the browser function updateLog (feed, post) { -- cgit v1.2.3-70-g09d2