From dc7c6bb55c50a17df6ad8c4ac5442143df11194a Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Wed, 5 Jun 2019 20:40:37 -0500 Subject: add support for multiple pubs --- app.js | 3 +++ gossip.js | 4 ++-- views.js | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/app.js b/app.js index 053fe3a..8275e5e 100644 --- a/app.js +++ b/app.js @@ -57,6 +57,8 @@ function route (keys) { if (src === 'key') { keyPage(keys) + } else if (src === 'pubs') { + pubs() } else if (src[0] === '@') { profilePage(src, keys) } else if (src[0] === '%') { @@ -73,6 +75,7 @@ keys().then(key => { h('li', [h('a', {href: '#'}, ['Home'])]), h('li', [h('a', {href: '#' + key.publicKey}, [getName(key.publicKey)])]), h('li', [h('a', {href: '#key'}, ['Key'])]), + h('li', [h('a', {href: '#pubs'}, ['Pubs'])]), h('li', {classList: 'right'}, [h('a', {href: 'http://github.com/bogbook/bog/'}, ['Git Repo'])]) ]) ]) diff --git a/gossip.js b/gossip.js index 81c4d5e..0d31afc 100644 --- a/gossip.js +++ b/gossip.js @@ -2,13 +2,13 @@ function sync (subs, keys) { var wsServers - localforage.getItem('servers').then(function (servers) { + localforage.getItem('pubs').then(function (servers) { if (servers) { console.log(servers) wsServers = servers } else { servers = ['ws://localhost:8080/', 'ws://evbogue.com/'] - localforage.setItem('servers', servers) + localforage.setItem('pubs', servers) console.log(servers) wsServers = servers } diff --git a/views.js b/views.js index 5861a01..94fd469 100644 --- a/views.js +++ b/views.js @@ -135,8 +135,7 @@ function keyPage (keys) { message.appendChild(h('button', { onclick: function () { if (textarea.value) { - localforage.setItem('id', JSON.parse(textarea.value)) - location.reload() + localforage.setItem('id', JSON.parse(textarea.value)).then(function () { location.reload() }) } } }, ['Import Key'])) @@ -144,3 +143,49 @@ function keyPage (keys) { scroller.appendChild(message) } +function pubs () { + var message = h('div', {classList: 'message'}) + + message.appendChild(h('p', {innerHTML: marked('These are the Bogbook pubs that your browser will connect to as it looks for new messages from your subscriptions, when you post new bog posts, and when you click on feeds.\n\nAdd or remove these pubs to control where your Bogbook gossips. Localhost is a default, but will only work if you install Bogbook on your local computer by [cloning down the repo](https://git.sr.ht/~ev/bogbook).')})) + + var add = h('input', {placeholder: 'Add a pub'}) + + localforage.getItem('pubs').then(function (servers) { + + message.appendChild(h('div', [ + add, + h('button', { + onclick: function () { + if (add.value) { + servers.push(add.value) + localforage.setItem('pubs', servers).then(function () { location.reload() }) + } + } + }, ['Add a pub']) + ])) + + servers.forEach(function (pub) { + message.appendChild(h('p', [ + pub, + h('button', { + onclick: function () { + var newServers = servers.filter(item => item !== pub) + localforage.setItem('pubs', newServers).then(function () { location.reload() }) + } + }, ['Remove']) + ])) + }) + }) + + message.appendChild(h('button', { + onclick: function () { + localforage.removeItem('pubs').then(function () { + location.hash = '' + location.reload() + }) + } + }, ['Reset pubs'])) + + scroller.appendChild(message) +} + -- cgit v1.2.3-70-g09d2