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 --- app.js | 30 ------------------------------ lib.js | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/app.js b/app.js index f2a66f8..17715de 100644 --- a/app.js +++ b/app.js @@ -1,35 +1,5 @@ var screen = h('div', {id: 'screen'}) document.body.appendChild(screen) -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) -} - function keyPage (keys) { var scroller = document.getElementById('scroller') 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