evt.stopPropagation();
evt.preventDefault();
const key = evt.currentTarget.getAttribute('data-reaction-key');
- console.log(key);
if (!key) setViewer(true);
else setViewer(key);
};
>
{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();
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;
<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>