Skip to content

Take control over your live stream video by running it yourself. Streaming + chat out of the box.

fix(chat): restore custom emoji picker entries

Gabe Kangas9820be7e56ec
diff --git a/web/components/chat/ChatTextField/EmojiPicker.tsx b/web/components/chat/ChatTextField/EmojiPicker.tsx
index ea6808b0a4..d7b7a16c59 100644
--- a/web/components/chat/ChatTextField/EmojiPicker.tsx
+++ b/web/components/chat/ChatTextField/EmojiPicker.tsx
@@ -1,4 +1,4 @@
-import { FC, useEffect, useState } from 'react';
+import { FC, useEffect } from 'react';
import Picker from '@emoji-mart/react';
import data from '@emoji-mart/data';
@@ -8,28 +8,18 @@ export type EmojiPickerProps = {
};
export const EmojiPicker: FC<EmojiPickerProps> = ({ onEmojiSelect, customEmoji }) => {
- const [custom, setCustom] = useState({});
- const categories = [
- 'frequent',
- 'custom', // same id as in the setCustom call below
- 'people',
- 'nature',
- 'foods',
- 'activity',
- 'places',
- 'objects',
- 'symbols',
- 'flags',
+ const custom = [
+ {
+ id: 'custom',
+ name: 'Custom',
+ emojis: customEmoji.map(emoji => ({
+ id: emoji.name,
+ name: emoji.name,
+ skins: [{ src: emoji.url }],
+ })),
+ },
];
- // Recreate the emoji picker when the custom emoji changes.
useEffect(() => {
- const e = customEmoji.map(emoji => ({
- id: emoji.name,
- name: emoji.name,
- skins: [{ src: emoji.url }],
- }));
-
- setCustom([{ id: 'custom', name: 'Custom', emojis: e }]);
// hack to make the picker work with viewbox only svgs, 24px is default size
const shadow = document.querySelector('em-emoji-picker').shadowRoot;
@@ -43,7 +33,6 @@ export const EmojiPicker: FC<EmojiPickerProps> = ({ onEmojiSelect, customEmoji }
data={data}
custom={custom}
onEmojiSelect={onEmojiSelect}
- categories={categories}
dynamicWidth
/>
);
diff --git a/web/tests/EmojiPicker.test.tsx b/web/tests/EmojiPicker.test.tsx
new file mode 100644
index 0000000000..ea7873d49c
--- /dev/null
+++ b/web/tests/EmojiPicker.test.tsx
@@ -0,0 +1,33 @@
+import { render, screen } from '@testing-library/react';
+import { EmojiPicker } from '../components/chat/ChatTextField/EmojiPicker';
+
+jest.mock('@emoji-mart/react', () => ({
+ __esModule: true,
+ default: ({ custom, categories }) => (
+ <output data-categories={String(categories)}>{JSON.stringify(custom)}</output>
+ ),
+}));
+
+beforeEach(() => {
+ Object.defineProperty(document, 'querySelector', {
+ configurable: true,
+ value: jest.fn(() => ({ shadowRoot: { adoptedStyleSheets: [] } })),
+ });
+ global.CSSStyleSheet = class {
+ replaceSync = jest.fn();
+ } as unknown as typeof CSSStyleSheet;
+});
+
+test('updates custom emoji after the emoji API response arrives', () => {
+ const { rerender } = render(<EmojiPicker customEmoji={[]} onEmojiSelect={jest.fn()} />);
+
+ rerender(
+ <EmojiPicker
+ customEmoji={[{ name: 'owncat', url: '/img/emoji/owncat.png' }]}
+ onEmojiSelect={jest.fn()}
+ />,
+ );
+
+ expect(screen.getByText(/owncat/)).toHaveTextContent('"id":"owncat"');
+ expect(screen.getByText(/owncat/)).toHaveAttribute('data-categories', 'undefined');
+});