Hook up reactions data

This commit is contained in:
Kurt Hutten
2020-11-08 15:41:59 +11:00
parent db06a3852a
commit 9ff1d5043d
13 changed files with 103 additions and 36 deletions

10
web/src/helpers/emote.js Normal file
View File

@@ -0,0 +1,10 @@
export const countEmotes = (reactions) => {
// would be good to do this sever side
// counting unique emojis, and limiting to the 5 largest
const emoteCounts = {}
reactions.forEach(({emote}) => {
emoteCounts[emote] = emoteCounts[emote] ? emoteCounts[emote] + 1 : 1
})
// TODO the sort is causing the emotes to jump around after the user clicks one, not ideal
return Object.entries(emoteCounts).map(([emoji, count]) => ({emoji, count})).sort((a,b) => a.count-b.count).slice(-5)
}