From 4a710ee5d147f892dfe33f157f5c3abc53d47b55 Mon Sep 17 00:00:00 2001 From: OFF0 Date: Mon, 21 Nov 2022 22:04:39 +0100 Subject: [PATCH] getting ready - added favicon.ico to get rid of anoying logs in the future - clicking the idea bubble brings back the text input field - stop accidentally submitting the reply form - updated idea cloud to dark/light mode neutral gray - contact list not needed yet, disabled - add a detailed list of reactions in star tooltip - removed debug debounce was for testing chronological feed order - started username prototype --- esbuildconf.js | 3 +- src/assets/bubble.svg | 4 +- src/cards.css | 16 ++++- src/favicon.ico | Bin 0 -> 4158 bytes src/form.css | 13 +++- src/index.html | 18 ++++-- src/main.css | 31 ++++++--- src/main.js | 145 +++++++++++++++++++++++++----------------- src/tabs.css | 5 +- 9 files changed, 153 insertions(+), 82 deletions(-) create mode 100644 src/favicon.ico diff --git a/esbuildconf.js b/esbuildconf.js index c0508d4..43e48a8 100644 --- a/esbuildconf.js +++ b/esbuildconf.js @@ -14,10 +14,11 @@ export const options = { 'src/assets/heart-fill.svg', 'src/assets/star.svg', 'src/assets/star-fill.svg', + 'src/favicon.ico', ], outdir: 'dist', //entryNames: '[name]-[hash]', TODO: replace urls in index.html with hashed paths - loader: {'.html': 'copy', '.svg': 'copy'}, + loader: {'.html': 'copy', '.svg': 'copy', '.ico': 'copy'}, bundle: true, platform: 'browser', minify: false, // TODO: true for release and enable sourcemap diff --git a/src/assets/bubble.svg b/src/assets/bubble.svg index 583c79f..9b9d947 100644 --- a/src/assets/bubble.svg +++ b/src/assets/bubble.svg @@ -1,4 +1,6 @@ - + + + diff --git a/src/cards.css b/src/cards.css index 2d91ac1..5db1daa 100644 --- a/src/cards.css +++ b/src/cards.css @@ -17,6 +17,8 @@ max-width: var(--size); max-width: var(--size); } + +.mbox-updated-contact .mbox-img, .mbox-recommend-server .mbox-img { --size: 4.5ch; margin-left: 3ch; @@ -27,7 +29,6 @@ flex-basis: calc(100% - 64px - 1rem); flex-grow: 0; flex-shrink: 1; - max-width: 96ch; word-break: break-word; } @@ -38,15 +39,26 @@ margin-top: 0; } .mbox-header time, -.mbox-username { +.mbox-username, +.mbox-updated-contact, +.mbox mbox-recommend-server { + color: var(--color-accent); } +.mbox-updated-contact .mbox-body, .mbox-recommend-server .mbox-body { display: block; flex-basis: 100%; font-size: var(--font-small); + overflow: scroll; } +.mbox-updated-contact .mbox-header, .mbox-recommend-server .mbox-header { display: inline; } + +.mbox-updated-contact { + padding: 0 0 1rem 0; + margin: 0; +} \ No newline at end of file diff --git a/src/favicon.ico b/src/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..9b1f7e628689fdaca9e7e531c83b022719796bfd GIT binary patch literal 4158 zcmcIm%T8255G@yiJ25c`JC-aY{(>7tga6>@PmoLkgYge!0R0!o(Zr}rKL8m`=w<4HN zfq4zs1fBr9!1obe<2wKz0OXu4@>vqwd=CD$fGe+l6_8S1_sM^v# zZP$V6RvyeR!sgioadmtz;A^gE4CYJVei#$`7j)eJhd^%xwuiuPKx4=Ld+07VYRL+F z-4uHt`a8f(qYv{7(BB0PfEYLZat!%15%!zwl=9jB19X9@nnsziAAGHiY@;-OpF>_h z59aqEkDU1Z3faw?G-^-!ny={vRBM1LroiyT1IsO)YcnP-pifMyS8!o9~E@($&g{ za(+u?;r*cOtt0>D^N9CD#=tvs<%px!rG0a*vEILoHDB>w*ncNaD~Z~EpNFMqd(efR{uj)DC>;5N{ln<2+K;OJc+ z{qb#k{O*a;^lN?voTf35$@(w=cxHPeu+3Vc`JH

nuaW+{v9unxJsP-bcWC47#b zw|WZafoD?lLYd?GwB@@xzu)65qb{rk*H>#)WaPf&@=e=r&N)v}7V0Exbsu;N>;jx0 O!8T>o@jY3bEB^o - nostr sandbox + nostr
- + - +
- +
-
+ - +
@@ -46,6 +46,10 @@
+
diff --git a/src/main.css b/src/main.css index 7052d73..61d53db 100644 --- a/src/main.css +++ b/src/main.css @@ -24,23 +24,25 @@ @media (prefers-color-scheme: light) { html { - --bgcolor: #fff; - --bgcolor-accent: #ff731d; + --bgcolor: #fdfefa; + --bgcolor-accent: #37ff1d; --bgcolor-inactive: #bababa; + --bgcolor-textinput: #fff; --color: rgb(68 68 68); --color-accent: #ff731d; - --bgcolor-danger: rgb(255 0 0); + --bgcolor-danger: rgb(255, 80, 80); } } @media (prefers-color-scheme: dark) { html { --bgcolor: #191919; - --bgcolor-accent: #2d4263; - --bgcolor-inactive: #535353; - --color: #c84b31; - --color-accent: #ecdbba; - --bgcolor-danger: rgb(255 0 0); + --bgcolor-accent: #1e437d; + --bgcolor-inactive: #333333; + --bgcolor-textinput: #0e0e0e; + --color: #fff; + --color-accent: #bbb;; + --bgcolor-danger: rgb(169, 0, 0); } img { @@ -81,14 +83,27 @@ time { background-color: var(--bgcolor-danger); } +a { + color: var(--color-accent); +} + a:focus { border-radius: var(--focus-border-radius); outline: var(--focus-outline); outline-offset: 0; } +a:visited { + color: darkmagenta; +} + img[alt] { font-size: .9rem; text-align: center; word-break: break-all; } + +pre { + margin: 0; + padding: .5rem 0; +} diff --git a/src/main.js b/src/main.js index 858eb9f..9fca2fd 100644 --- a/src/main.js +++ b/src/main.js @@ -4,23 +4,14 @@ import {dateTime, formatTime} from './timeutil.js'; // curl -H 'accept: application/nostr+json' https://nostr.x1ddos.ch const pool = relayPool(); pool.addRelay('wss://relay.nostr.info', {read: true, write: true}); -// pool.addRelay('wss://relay.damus.io', {read: true, write: true}); +pool.addRelay('wss://relay.damus.io', {read: true, write: true}); pool.addRelay('wss://nostr.x1ddos.ch', {read: true, write: true}); // pool.addRelay('wss://nostr.openchain.fr', {read: true, write: true}); // pool.addRelay('wss://nostr.bitcoiner.social/', {read: true, write: true}); // read only // pool.addRelay('wss://nostr.rocks', {read: true, write: false}); - -let max = 0; - function onEvent(evt, relay) { - if (evt.id === '209eefe6c940377fa8730853a75d1b4bb31bd929d79') { - console.log(evt) - } - // if (max++ >= 223) { - // return subscription.unsub(); - // } switch (evt.kind) { case 0: handleMetadata(evt, relay); @@ -32,7 +23,7 @@ function onEvent(evt, relay) { handleRecommendServer(evt, relay); break; case 3: - updateContactList(evt, relay); + // handleContactList(evt, relay); break; case 7: handleReaction(evt, relay); @@ -41,7 +32,13 @@ function onEvent(evt, relay) { } } -let pubkey = localStorage.getItem('pub_key') +let pubkey = localStorage.getItem('pub_key') || (() => { + const privatekey = generatePrivateKey(); + const pubkey = getPublicKey(privatekey); + localStorage.setItem('private_key', privatekey); + localStorage.setItem('pub_key', pubkey); + return pubkey; +})(); const subscription = pool.sub({ cb: onEvent, @@ -55,7 +52,7 @@ const subscription = pool.sub({ // '32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245', // jb55 // ], // since: new Date(Date.now() - (24 * 60 * 60 * 1000)), - limit: 400, + limit: 500, } }); @@ -112,9 +109,10 @@ function handleReaction(evt, relay) { const button = article.querySelector('button[name="star"]'); const reactions = button.querySelector('[data-reactions]'); reactions.textContent = reactionMap[eventId].length; - console.log(evt.pubkey, pubkey) if (evt.pubkey === pubkey) { - button.querySelector('img[src$="star.svg"]').setAttribute('src', 'assets/star-fill.svg'); + const star = button.querySelector('img[src$="star.svg"]'); + star.setAttribute('src', 'assets/star-fill.svg'); + star.setAttribute('title', reactionMap[eventId]) } } } @@ -131,14 +129,8 @@ const sortByCreatedAt = (evt1, evt2) => { return evt1.created_at > evt2.created_at ? -1 : 1; }; -// let debounceDebugMessageTimer; function renderFeed() { const sortedFeeds = textNoteList.sort(sortByCreatedAt).reverse(); - // debug - // clearTimeout(debounceDebugMessageTimer); - // debounceDebugMessageTimer = setTimeout(() => { - // console.log(`${sortedFeeds.reverse().map(e => dateTime.format(e.created_at * 1000)).join('\n')}`) - // }, 2000); sortedFeeds.forEach((textNoteEvent, i) => { if (feedDomMap[textNoteEvent.id]) { // TODO check eventRelayMap if event was published to different relays @@ -178,22 +170,26 @@ function createTextNote(evt, relay) { elem('strong', {className: 'mbox-username'}, userName), ' ', elem('time', {dateTime: time.toISOString()}, formatTime(time)), - ` kind:${evt.kind} ${evt.id}`, ]), ]), elem('div', {data: isLongContent ? {append: evt.content.slice(280)} : null}, content), - elem('button', { - className: 'btn-inline', name: 'reply', type: 'button', - data: {'eventId': evt.id, relay}, - }, [elem('img', {height: 24, width: 24, src: 'assets/comment.svg'})]), elem('button', { className: 'btn-inline', name: 'star', type: 'button', data: {'eventId': evt.id, relay}, }, [ - elem('img', {alt: didReact ? '✭' : '✩', height: 24, width: 24, src: `assets/${didReact ? 'star-fill' : 'star'}.svg`}), // ♥ + elem('img', { + alt: didReact ? '✭' : '✩', // ♥ + height: 24, width: 24, + src: `assets/${didReact ? 'star-fill' : 'star'}.svg`, + title: reactionMap[evt.id]?.map(({content}) => content).join(' '), + }), elem('small', {data: {reactions: evt.id}}, hasReactions ? reactionMap[evt.id].length : ''), ]), - replies[0] ? elem('div', {className: 'mobx-replies'}, replyFeed) : '', + elem('button', { + className: 'btn-inline', name: 'reply', type: 'button', + data: {'eventId': evt.id, relay}, + }, [elem('img', {height: 24, width: 24, src: 'assets/comment.svg'})]), + replies[0] ? elem('div', {className: 'mobx-replies'}, replyFeed.reverse()) : '', ]); return rendernArticle([img, body]); } @@ -210,8 +206,7 @@ function handleReply(evt, relay) { function renderReply(evt, relay) { const eventId = evt.tags[0][1]; // TODO: double check const article = feedDomMap[eventId] || replyDomMap[eventId]; - if (!article) { - // root article has not been rendered + if (!article) { // root article has not been rendered return; } let replyContainer = article.querySelector('.mobx-replies'); @@ -245,6 +240,45 @@ function handleRecommendServer(evt, relay) { feedDomMap[evt.id] = art; } +function handleContactList(evt, relay) { + if (feedDomMap[evt.id]) { + return; + } + const art = renderUpdateContact(evt, relay); + if (textNoteList.length < 2) { + feedContainer.append(art); + return; + } + const closestTextNotes = textNoteList.sort(sortEventCreatedAt(evt.created_at)); + feedDomMap[closestTextNotes[0].id].after(art); + feedDomMap[evt.id] = art; + // const user = userList.find(u => u.pupkey === evt.pubkey); + // if (user) { + // console.log(`TODO: add contact list for ${evt.pubkey.slice(0, 8)} on ${relay}`, evt.tags); + // } else { + // tempContactList[relay] = tempContactList[relay] + // ? [...tempContactList[relay], evt] + // : [evt]; + // } +} + +function renderUpdateContact(evt, relay) { + const {img, time, userName} = getMetadata(evt, relay); + const body = elem('div', {className: 'mbox-body', title: dateTime.format(time)}, [ + elem('header', {className: 'mbox-header'}, [ + elem('small', {}, [ + + ]), + ]), + elem('pre', {title: JSON.stringify(evt.content)}, [ + elem('strong', {}, userName), + ' updated contacts: ', + JSON.stringify(evt.tags), + ]), + ]); + return rendernArticle([img, body], {className: 'mbox-updated-contact'}); +} + function renderRecommendServer(evt, relay) { const {img, time, userName} = getMetadata(evt, relay); const body = elem('div', {className: 'mbox-body', title: dateTime.format(time)}, [ @@ -264,7 +298,7 @@ function rendernArticle(content, props = {}) { } const userList = []; -const tempContactList = {}; +// const tempContactList = {}; function handleMetadata(evt, relay) { try { @@ -280,9 +314,7 @@ function setMetadata(evt, relay, content) { const user = userList.find(u => u.pubkey === evt.pubkey); if (!user) { userList.push({ - metadata: { - [relay]: content - }, + metadata: {[relay]: content}, pubkey: evt.pubkey, }); } else { @@ -292,12 +324,12 @@ function setMetadata(evt, relay, content) { ...content, }; } - if (tempContactList[relay]) { - const updates = tempContactList[relay].filter(update => update.pubkey === evt.pubkey); - if (updates) { - // console.log('TODO: add contact list (kind 3)', updates); - } - } + // if (tempContactList[relay]) { + // const updates = tempContactList[relay].filter(update => update.pubkey === evt.pubkey); + // if (updates) { + // console.log('TODO: add contact list (kind 3)', updates); + // } + // } } const getHost = (url) => { @@ -326,19 +358,6 @@ function getMetadata(evt, relay) { return {host, img, isReply, replies, time, userName}; } -function updateContactList(evt, relay) { - const user = userList.find(u => u.pupkey === evt.pubkey); - if (user) { - console.log(`TODO: add contact list for ${evt.pubkey.slice(0, 8)} on ${relay}`, evt.tags); - } else { - tempContactList[relay] = tempContactList[relay] - ? [...tempContactList[relay], evt] - : [evt]; - } -} - -// check pool.status - // reply const writeForm = document.querySelector('#writeForm'); const input = document.querySelector('input[name="message"]'); @@ -351,8 +370,9 @@ feedContainer.addEventListener('click', (e) => { lastReplyBtn.hidden = false; } lastReplyBtn = button; - button.hidden = true; + // button.hidden = true; button.after(writeForm); + button.after(sendStatus); writeForm.hidden = false; replyTo = ['e', button.dataset.eventId, button.dataset.relay]; input.focus(); @@ -364,6 +384,14 @@ feedContainer.addEventListener('click', (e) => { } }); +const newMessageDiv = document.querySelector('#newMessage'); +document.querySelector('#bubble').addEventListener('click', (e) => { + replyTo = null; + newMessageDiv.prepend(writeForm); + newMessageDiv.append(sendStatus); + input.focus(); +}); + async function upvote(eventId, relay) { const privatekey = localStorage.getItem('private_key'); const newReaction = { @@ -393,7 +421,8 @@ const onSendError = err => { sendStatus.hidden = false; }; const publish = document.querySelector('#publish'); -publish.addEventListener('click', async () => { +writeForm.addEventListener('submit', async (e) => { + e.preventDefault(); // const pubkey = localStorage.getItem('pub_key'); const privatekey = localStorage.getItem('private_key'); if (!pubkey || !privatekey) { @@ -424,7 +453,8 @@ publish.addEventListener('click', async () => { lastReplyBtn.hidden = false; lastReplyBtn = null; replyTo = null; - document.querySelector('#newMessage').append(writeForm); + newMessageDiv.append(writeForm); + newMessageDiv.append(sendStatus); } // console.info(`event published by ${url}`, ev); } @@ -433,6 +463,7 @@ publish.addEventListener('click', async () => { }); input.addEventListener('input', () => publish.disabled = !input.value); +input.addEventListener('blur', () => sendStatus.textContent = ''); // settings const form = document.querySelector('form[name="settings"]'); @@ -502,4 +533,4 @@ document.body.addEventListener('click', (e) => { delete append.dataset.append; return; } -}); \ No newline at end of file +}); diff --git a/src/tabs.css b/src/tabs.css index 2edcedf..e92c055 100644 --- a/src/tabs.css +++ b/src/tabs.css @@ -1,4 +1,4 @@ - +.tabs { margin-top: 4rem; } .tabs .tab-content { display: none; } #feed:checked ~ .tabs .tab-content:nth-child(1), #trending:checked ~ .tabs .tab-content:nth-child(2), @@ -43,9 +43,6 @@ input[type="radio"]:checked + label { /* -.tabs { - position: relative; -} .tab { float: left;