Render reaction with string only key (#1522)
authorAjay Bura <32841439+ajbura@users.noreply.github.com>
Tue, 31 Oct 2023 03:17:57 +0000 (14:17 +1100)
committerGitHub <noreply@github.com>
Tue, 31 Oct 2023 03:17:57 +0000 (14:17 +1100)
src/app/organisms/room/message/Reactions.tsx
src/app/organisms/room/reaction-viewer/ReactionViewer.tsx

index 17b914e5fd8e9e7de12cc95b71f94daeff9c309c..728cf81077f01f736ad1365d6681b8a1e69c40bb 100644 (file)
@@ -43,7 +43,6 @@ export const Reactions = as<'div', ReactionsProps>(
       evt.stopPropagation();
       evt.preventDefault();
       const key = evt.currentTarget.getAttribute('data-reaction-key');
-      console.log(key);
       if (!key) setViewer(true);
       else setViewer(key);
     };
@@ -58,7 +57,7 @@ export const Reactions = as<'div', ReactionsProps>(
       >
         {reactions.map(([key, events]) => {
           const rEvents = Array.from(events);
-          if (rEvents.length === 0) return null;
+          if (rEvents.length === 0 || typeof key !== 'string') return null;
           const myREvent = myUserId ? rEvents.find(factoryEventSentBy(myUserId)) : undefined;
           const isPressed = !!myREvent?.getRelation();
 
index 5626981efa8b08ce205c08aaff59b86a3f361bbb..7bcc0ccf8bc6bb97d997467ef7ef8c68c93bea78 100644 (file)
@@ -41,7 +41,12 @@ export const ReactionViewer = as<'div', ReactionViewerProps>(
       relations,
       useCallback((rel) => [...(rel.getSortedAnnotationsByKey() ?? [])], [])
     );
-    const [selectedKey, setSelectedKey] = useState<string>(initialKey ?? reactions[0][0]);
+
+    const [selectedKey, setSelectedKey] = useState<string>(() => {
+      if (initialKey) return initialKey;
+      const defaultReaction = reactions.find((reaction) => typeof reaction[0] === 'string');
+      return defaultReaction ? defaultReaction[0] : '';
+    });
 
     const getName = (member: RoomMember) =>
       getMemberDisplayName(room, member.userId) ?? getMxIdLocalPart(member.userId) ?? member.userId;
@@ -68,16 +73,19 @@ export const ReactionViewer = as<'div', ReactionViewerProps>(
         <Box shrink="No" className={css.Sidebar}>
           <Scroll visibility="Hover" hideTrack size="300">
             <Box className={css.SidebarContent} direction="Column" gap="200">
-              {reactions.map(([key, evts]) => (
-                <Reaction
-                  key={key}
-                  mx={mx}
-                  reaction={key}
-                  count={evts.size}
-                  aria-selected={key === selectedKey}
-                  onClick={() => setSelectedKey(key)}
-                />
-              ))}
+              {reactions.map(([key, evts]) => {
+                if (typeof key !== 'string') return null;
+                return (
+                  <Reaction
+                    key={key}
+                    mx={mx}
+                    reaction={key}
+                    count={evts.size}
+                    aria-selected={key === selectedKey}
+                    onClick={() => setSelectedKey(key)}
+                  />
+                );
+              })}
             </Box>
           </Scroll>
         </Box>