diff options
author | Ev Bogue <ev@evbogue.com> | 2019-06-05 20:40:37 -0500 |
---|---|---|
committer | Ev Bogue <ev@evbogue.com> | 2019-06-05 20:40:37 -0500 |
commit | dc7c6bb55c50a17df6ad8c4ac5442143df11194a (patch) | |
tree | 828ea23e04388ce2e6523c9a3b3549fe8400e09d | |
parent | ade5d9af558c97e4c484ea78dbc8fdd7f98096e3 (diff) |
add support for multiple pubs
-rw-r--r-- | app.js | 3 | ||||
-rw-r--r-- | gossip.js | 4 | ||||
-rw-r--r-- | views.js | 49 |
3 files changed, 52 insertions, 4 deletions
@@ -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'])]) ]) ]) @@ -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 } @@ -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) +} + |