From 265680149ccdb989ba6af214c72ea79bb59dc703 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 7 Apr 2019 19:31:31 -0500 Subject: add subscribe/unsubscribe buttons to top of feeds --- app.js | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/app.js b/app.js index 0730463..578afb9 100644 --- a/app.js +++ b/app.js @@ -11,6 +11,12 @@ var navbar = h('div', {classList: 'navbar'}, [ ]) ]) +if (!localStorage['subscribees']) { + var subscribees = ['@218Fd2bCrmXe4gwnMg5Gcb9qVZrjXquym2AlelbkBro='] + localStorage['subscribees'] = JSON.stringify(subscribees) +} + + document.body.appendChild(navbar) function compose (keys, opts) { @@ -82,10 +88,10 @@ function route () { } else if (src[0] === '@') { + var profile = h('div', {classList: 'message'}) + scroller.appendChild(profile) if (src == keys.publicKey) { - var profile = h('div', {classList: 'message'}) - scroller.appendChild(profile) var nameInput = h('input', {placeholder: 'Publish a new name'}) var namePublisher = h('div',[ @@ -136,6 +142,31 @@ function route () { profile.appendChild(imagePublisher) document.getElementById("inp").addEventListener("change", readFile); + + } else { + var subscribees = JSON.parse(localStorage['subscribees']) + if (subscribees.includes(src)) { + profile.appendChild(h('button', { + onclick: function () { + for (var i = subscribees.length; i--;) { + if (subscribees[i] === src) { + subscribees.splice(i, 1); + localStorage['subscribees'] = JSON.stringify(subscribees) + window.location.reload() + } + } + } + // remove subscribee + }, ['UNSUBSCRIBE'])) + } else { + profile.appendChild(h('button', { + onclick: function () { + subscribees.push(src) + localStorage['subscribees'] = JSON.stringify(subscribees) + window.location.reload() + } + }, ['SUBSCRIBE'])) + } } var ws = new WebSocket('ws://bogbook.com/' + src) -- cgit v1.2.3-70-g09d2