Skip to content

Commit 32a6b37

Browse files
committed
fix: do not prefer ChannelAvatar from component context in ChannelHeader
1 parent f9e24eb commit 32a6b37

File tree

3 files changed

+10
-37
lines changed

3 files changed

+10
-37
lines changed

src/components/ChannelHeader/ChannelHeader.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { MenuIcon as DefaultMenuIcon } from './icons';
55
import { ChannelAvatarProps, Avatar as DefaultAvatar } from '../Avatar';
66
import { useChannelPreviewInfo } from '../ChannelPreview/hooks/useChannelPreviewInfo';
77

8-
import { useComponentContext } from '../../context';
98
import { useChannelStateContext } from '../../context/ChannelStateContext';
109
import { useChatContext } from '../../context/ChatContext';
1110
import { useTranslationContext } from '../../context/TranslationContext';
@@ -34,7 +33,7 @@ export const ChannelHeader = <
3433
props: ChannelHeaderProps,
3534
) => {
3635
const {
37-
Avatar: PropAvatar = DefaultAvatar,
36+
Avatar = DefaultAvatar,
3837
MenuIcon = DefaultMenuIcon,
3938
image: overrideImage,
4039
live,
@@ -50,9 +49,6 @@ export const ChannelHeader = <
5049
overrideTitle,
5150
});
5251

53-
const { ChannelAvatar } = useComponentContext();
54-
const Avatar = ChannelAvatar ?? PropAvatar;
55-
5652
const { member_count, subtitle } = channel?.data || {};
5753

5854
return (

src/components/ChannelHeader/__tests__/ChannelHeader.test.js

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {
2121
import { toHaveNoViolations } from 'jest-axe';
2222
import { axe } from '../../../../axe-helper';
2323
import { ChannelAvatar } from '../../Avatar';
24-
import { ComponentProvider } from '../../../context';
2524

2625
expect.extend(toHaveNoViolations);
2726

@@ -39,33 +38,26 @@ const defaultChannelState = {
3938

4039
const t = jest.fn((key) => key);
4140

42-
const renderComponentBase = ({ channel, client, componentOverrides, props }) =>
41+
const renderComponentBase = ({ channel, client, props }) =>
4342
render(
4443
<ChatProvider value={{ channel, client }}>
45-
<ComponentProvider value={componentOverrides ?? {}}>
46-
<ChannelStateProvider value={{ channel }}>
47-
<TranslationProvider value={{ t }}>
48-
<ChannelHeader {...props} />
49-
</TranslationProvider>
50-
</ChannelStateProvider>
51-
</ComponentProvider>
44+
<ChannelStateProvider value={{ channel }}>
45+
<TranslationProvider value={{ t }}>
46+
<ChannelHeader {...props} />
47+
</TranslationProvider>
48+
</ChannelStateProvider>
5249
</ChatProvider>,
5350
);
5451

55-
async function renderComponent({
56-
channelData,
57-
channelType = 'messaging',
58-
componentOverrides,
59-
props,
60-
} = {}) {
52+
async function renderComponent({ channelData, channelType = 'messaging', props } = {}) {
6153
client = await getTestClientWithUser(user1);
6254
testChannel1 = generateChannel({ ...defaultChannelState, channel: channelData });
6355
/* eslint-disable-next-line react-hooks/rules-of-hooks */
6456
useMockedApis(client, [getOrCreateChannelApi(testChannel1)]);
6557
const channel = client.channel(channelType, testChannel1.id, channelData);
6658
await channel.query();
6759

68-
return renderComponentBase({ channel, client, componentOverrides, props });
60+
return renderComponentBase({ channel, client, props });
6961
}
7062

7163
afterEach(cleanup); // eslint-disable-line
@@ -211,21 +203,6 @@ describe('ChannelHeader', () => {
211203
);
212204
});
213205

214-
it('prefers the ChannelAvatar provided over component context', async () => {
215-
const channelAvatarTestID = 'custom-channel-avatar';
216-
const propsAvatarTestID = 'props-avatar';
217-
const ChannelAvatar = () => <div data-testid={channelAvatarTestID} />;
218-
const PropsAvatar = () => <div data-testid={propsAvatarTestID} />;
219-
220-
await renderComponent({
221-
componentOverrides: { ChannelAvatar },
222-
props: { Avatar: PropsAvatar },
223-
});
224-
225-
expect(screen.queryByTestId(propsAvatarTestID)).not.toBeInTheDocument();
226-
expect(screen.getByTestId(channelAvatarTestID)).toBeInTheDocument();
227-
});
228-
229206
describe('group channel', () => {
230207
const props = {
231208
Avatar: ChannelAvatar,

src/components/ChannelList/ChannelList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ const UnMemoizedChannelList = <SCG extends DefaultStreamChatGenerics = DefaultSt
217217
theme,
218218
useImageFlagEmojisOnWindows,
219219
} = useChatContext<SCG>('ChannelList');
220-
const { Search } = useComponentContext();
220+
const { Search } = useComponentContext(); // FIXME: us component context to retrieve ChannelPreview UI components too
221221
const channelListRef = useRef<HTMLDivElement>(null);
222222
const [channelUpdateCount, setChannelUpdateCount] = useState(0);
223223
const [searchActive, setSearchActive] = useState(false);

0 commit comments

Comments
 (0)