Skip to content

Commit 674dd16

Browse files
committed
feat: allow to override active prop on ChannelPreview
1 parent 99554ce commit 674dd16

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/components/ChannelPreview/ChannelPreview.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ import type { DefaultStreamChatGenerics } from '../../types/types';
2121
export type ChannelPreviewUIComponentProps<
2222
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics
2323
> = ChannelPreviewProps<StreamChatGenerics> & {
24-
/** If the component's channel is the active (selected) Channel */
25-
active?: boolean;
2624
/** Image of Channel to display */
2725
displayImage?: string;
2826
/** Title of Channel to display */
@@ -46,6 +44,8 @@ export type ChannelPreviewProps<
4644
> = {
4745
/** Comes from either the `channelRenderFilterFn` or `usePaginatedChannels` call from [ChannelList](https://github.com/GetStream/stream-chat-react/blob/master/src/components/ChannelList/ChannelList.tsx) */
4846
channel: Channel<StreamChatGenerics>;
47+
/** If the component's channel is the active (selected) Channel */
48+
active?: boolean;
4949
/** Current selected channel object */
5050
activeChannel?: Channel<StreamChatGenerics>;
5151
/** UI component to display an avatar, defaults to [Avatar](https://github.com/GetStream/stream-chat-react/blob/master/src/components/Avatar/Avatar.tsx) component and accepts the same props as: [ChannelAvatar](https://github.com/GetStream/stream-chat-react/blob/master/src/components/Avatar/ChannelAvatar.tsx) */
@@ -77,6 +77,7 @@ export const ChannelPreview = <
7777
props: ChannelPreviewProps<StreamChatGenerics>,
7878
) => {
7979
const {
80+
active,
8081
channel,
8182
Preview = ChannelPreviewMessenger,
8283
channelUpdateCount,
@@ -99,7 +100,7 @@ export const ChannelPreview = <
99100
lastMessage,
100101
});
101102

102-
const isActive = activeChannel?.cid === channel.cid;
103+
const isActive = typeof active === 'undefined' ? activeChannel?.cid === channel.cid : active;
103104
const { muted } = useIsChannelMuted(channel);
104105

105106
useEffect(() => {

0 commit comments

Comments
 (0)