From 96087dc04129a0520a349055ef48bd383f862258 Mon Sep 17 00:00:00 2001 From: OFF0 Date: Fri, 9 Dec 2022 22:19:11 +0100 Subject: [PATCH] feed: fix multiple upvotes (reactions) Fixes error when upvoting already starred events. Now the tooltip should display the reactions again. --- src/main.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main.js b/src/main.js index fac23a7..d5ebf2b 100644 --- a/src/main.js +++ b/src/main.js @@ -77,6 +77,10 @@ function handleTextNote(evt, relay) { const replyList = []; const reactionMap = {}; +const getReactionList = (id) => { + return reactionMap[id]?.map(({content}) => content) || []; +}; + function handleReaction(evt, relay) { if (!evt.content.length) { // console.log('reaction with no content', evt) @@ -110,9 +114,9 @@ function handleReaction(evt, relay) { const reactions = button.querySelector('[data-reactions]'); reactions.textContent = reactionMap[eventId].length; if (evt.pubkey === pubkey) { - const star = button.querySelector('img[src$="star.svg"]'); - star.setAttribute('src', 'assets/star-fill.svg'); - star.setAttribute('title', reactionMap[eventId]); + const star = button.querySelector('img[src*="star"]'); + star?.setAttribute('src', 'assets/star-fill.svg'); + star?.setAttribute('title', getReactionList(eventId).join(' ')); } } } @@ -183,7 +187,7 @@ function createTextNote(evt, relay) { alt: didReact ? '✭' : '✩', // ♥ height: 24, width: 24, src: `assets/${didReact ? 'star-fill' : 'star'}.svg`, - title: reactionMap[evt.id]?.map(({content}) => content).join(' '), + title: getReactionList(evt.id).join(' '), }), elem('small', {data: {reactions: evt.id}}, hasReactions ? reactionMap[evt.id].length : ''), ]),