@@ -12,30 +12,33 @@ import { ChatContextValue, useChatContext } from '../../contexts/chatContext/Cha
1212
1313import type { DefaultStreamChatGenerics } from '../../types/types' ;
1414import { useChannelPreviewData } from './hooks/useChannelPreviewData' ;
15- import { useIsChannelMuted } from './hooks/useIsChannelMuted' ;
1615
17- export type ChannelPreviewPropsWithContext <
16+ export type ChannelPreviewProps <
1817 StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics ,
19- > = Pick < ChatContextValue < StreamChatGenerics > , 'client' > &
20- Pick < ChannelsContextValue < StreamChatGenerics > , 'Preview' | 'forceUpdate' > & {
18+ > = Partial < Pick < ChatContextValue < StreamChatGenerics > , 'client' > > &
19+ Partial < Pick < ChannelsContextValue < StreamChatGenerics > , 'Preview' | 'forceUpdate' > > & {
2120 /**
2221 * Instance of Channel from stream-chat package.
2322 */
2423 channel : Channel < StreamChatGenerics > ;
2524 } ;
2625
27- /**
28- * This component manages state for the ChannelPreviewMessenger UI component and receives
29- * all props from the ChannelListMessenger component.
30- */
31- const ChannelPreviewWithContext = <
26+ export const ChannelPreview = <
3227 StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics ,
3328> (
34- props : ChannelPreviewPropsWithContext < StreamChatGenerics > ,
29+ props : ChannelPreviewProps < StreamChatGenerics > ,
3530) => {
36- const { forceUpdate, channel, client, Preview } = props ;
37- const { muted } = useIsChannelMuted ( channel ) ;
38- const { lastMessage, unread } = useChannelPreviewData ( channel , client , forceUpdate , muted ) ;
31+ const { channel, client : propClient , forceUpdate : propForceUpdate , Preview : propPreview } = props ;
32+
33+ const { client : contextClient } = useChatContext < StreamChatGenerics > ( ) ;
34+ const { forceUpdate : contextForceUpdate , Preview : contextPreview } =
35+ useChannelsContext < StreamChatGenerics > ( ) ;
36+
37+ const client = propClient || contextClient ;
38+ const forceUpdate = propForceUpdate || contextForceUpdate ;
39+ const Preview = propPreview || contextPreview ;
40+
41+ const { lastMessage, muted, unread } = useChannelPreviewData ( channel , client , forceUpdate ) ;
3942 const latestMessagePreview = useLatestMessagePreview ( channel , forceUpdate , lastMessage ) ;
4043
4144 return (
@@ -47,19 +50,3 @@ const ChannelPreviewWithContext = <
4750 />
4851 ) ;
4952} ;
50-
51- export type ChannelPreviewProps <
52- StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics ,
53- > = Partial < Omit < ChannelPreviewPropsWithContext < StreamChatGenerics > , 'channel' > > &
54- Pick < ChannelPreviewPropsWithContext < StreamChatGenerics > , 'channel' > ;
55-
56- export const ChannelPreview = <
57- StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics ,
58- > (
59- props : ChannelPreviewProps < StreamChatGenerics > ,
60- ) => {
61- const { client } = useChatContext < StreamChatGenerics > ( ) ;
62- const { forceUpdate, Preview } = useChannelsContext < StreamChatGenerics > ( ) ;
63-
64- return < ChannelPreviewWithContext { ...{ client, forceUpdate, Preview } } { ...props } /> ;
65- } ;
0 commit comments