From db06a3852a956c54a6647f2953da5e401d3de89b Mon Sep 17 00:00:00 2001 From: Kurt Hutten Date: Sun, 8 Nov 2020 13:15:06 +1100 Subject: [PATCH] Add emote disks onto part card --- web/src/components/Parts/Parts.js | 67 +++++++++++++++-------- web/src/components/PartsCell/PartsCell.js | 3 + 2 files changed, 48 insertions(+), 22 deletions(-) diff --git a/web/src/components/Parts/Parts.js b/web/src/components/Parts/Parts.js index 1b8af53..71719b6 100644 --- a/web/src/components/Parts/Parts.js +++ b/web/src/components/Parts/Parts.js @@ -1,36 +1,59 @@ -import { useMutation, useFlash } from '@redwoodjs/web' +import { useMemo } from 'react' import { Link, routes } from '@redwoodjs/router' import ImageUploader from 'src/components/ImageUploader' const PartsList = ({ parts }) => { + 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 + }) + return Object.entries(emoteCounts).map(([emoji, count]) => ({emoji, count})).sort((a,b) => a.count-b.count).slice(-5) + } return (
-
diff --git a/web/src/components/PartsCell/PartsCell.js b/web/src/components/PartsCell/PartsCell.js index dc2cd9e..1490590 100644 --- a/web/src/components/PartsCell/PartsCell.js +++ b/web/src/components/PartsCell/PartsCell.js @@ -14,6 +14,9 @@ export const QUERY = gql` image userName } + Reaction { + emote + } } } `