Skip to content

Commit cd1b2fd

Browse files
committed
feat: add ability to customize channel preview last message
1 parent f175d27 commit cd1b2fd

File tree

7 files changed

+27
-12
lines changed

7 files changed

+27
-12
lines changed

package/src/components/ChannelList/hooks/useCreateChannelsContext.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export const useCreateChannelsContext = ({
3030
PreviewMutedStatus,
3131
PreviewStatus,
3232
PreviewTitle,
33+
PreviewLastMessage,
3334
PreviewTypingIndicator,
3435
PreviewMessageDeliveryStatus,
3536
PreviewUnreadCount,
@@ -84,6 +85,7 @@ export const useCreateChannelsContext = ({
8485
PreviewUnreadCount,
8586
PreviewTypingIndicator,
8687
PreviewMessageDeliveryStatus,
88+
PreviewLastMessage,
8789
ChannelDetailsBottomSheet,
8890
swipeActionsEnabled,
8991
refreshing,

package/src/components/ChannelPreview/ChannelMessagePreview.tsx renamed to package/src/components/ChannelPreview/ChannelLastMessagePreview.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import { useTheme } from '../../contexts/themeContext/ThemeContext';
77
import { useMessagePreviewIcon, useMessagePreviewText } from '../../hooks';
88
import { primitives } from '../../theme';
99

10-
export type ChannelMessagePreviewProps = {
10+
export type ChannelLastMessagePreviewProps = {
1111
message: LocalMessage | MessageResponse | DraftMessage;
1212
};
1313

14-
export const ChannelMessagePreview = ({ message }: ChannelMessagePreviewProps) => {
14+
export const ChannelLastMessagePreview = ({ message }: ChannelLastMessagePreviewProps) => {
1515
const isMessageDeleted = message?.type === 'deleted';
1616
const {
1717
theme: { semantics },

package/src/components/ChannelPreview/ChannelPreviewMessage.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useMemo } from 'react';
22
import { StyleSheet, Text, View } from 'react-native';
33

4-
import { ChannelMessagePreview } from './ChannelMessagePreview';
4+
import { ChannelLastMessagePreview } from './ChannelLastMessagePreview';
55
import { ChannelMessagePreviewDeliveryStatus } from './ChannelMessagePreviewDeliveryStatus';
66
import { ChannelPreviewProps } from './ChannelPreview';
77

@@ -24,7 +24,10 @@ import { MessageStatusTypes } from '../../utils/utils';
2424
import { ErrorBadge } from '../ui';
2525

2626
export type ChannelPreviewMessageProps = Pick<ChannelPreviewProps, 'channel'> &
27-
Pick<ChannelsContextValue, 'PreviewTypingIndicator' | 'PreviewMessageDeliveryStatus'> & {
27+
Pick<
28+
ChannelsContextValue,
29+
'PreviewTypingIndicator' | 'PreviewMessageDeliveryStatus' | 'PreviewLastMessage'
30+
> & {
2831
lastMessage?: LastMessageType;
2932
};
3033

@@ -34,6 +37,7 @@ export const ChannelPreviewMessage = (props: ChannelPreviewMessageProps) => {
3437
lastMessage,
3538
PreviewTypingIndicator = ChannelPreviewTypingIndicator,
3639
PreviewMessageDeliveryStatus = ChannelMessagePreviewDeliveryStatus,
40+
PreviewLastMessage = ChannelLastMessagePreview,
3741
} = props;
3842
const {
3943
theme: { semantics },
@@ -66,7 +70,7 @@ export const ChannelPreviewMessage = (props: ChannelPreviewMessageProps) => {
6670
return (
6771
<View style={styles.container}>
6872
<Text style={styles.draftText}>{t('Draft')}:</Text>
69-
<ChannelMessagePreview message={draftMessage} />
73+
<PreviewLastMessage message={draftMessage} />
7074
</View>
7175
);
7276
}
@@ -102,14 +106,14 @@ export const ChannelPreviewMessage = (props: ChannelPreviewMessageProps) => {
102106
return (
103107
<View style={styles.container}>
104108
<PreviewMessageDeliveryStatus channel={channel} message={lastMessage} />
105-
<ChannelMessagePreview message={lastMessage} />
109+
<PreviewLastMessage message={lastMessage} />
106110
</View>
107111
);
108112
} else {
109113
return (
110114
<View style={styles.container}>
111115
<PreviewMessageDeliveryStatus channel={channel} message={lastMessage} />
112-
<ChannelMessagePreview message={lastMessage} />
116+
<PreviewLastMessage message={lastMessage} />
113117
</View>
114118
);
115119
}

package/src/components/ChannelPreview/ChannelPreviewMessenger.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ const ChannelPreviewMessengerWithContext = (props: ChannelPreviewMessengerPropsW
111111
]}
112112
testID='channel-preview-button'
113113
>
114-
<PreviewAvatar channel={channel} size='xl' />
114+
<PreviewAvatar channel={channel} />
115115
<View
116116
style={[styles.contentContainer, contentContainer]}
117117
testID={`channel-preview-content-${channel.id}`}

package/src/components/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,13 @@ export * from './ChannelList/hooks';
4545

4646
/** Channel Preview exports */
4747
export * from './ChannelPreview/ChannelDetailsBottomSheet';
48-
export * from './ChannelPreview/ChannelMessagePreview';
48+
export * from './ChannelPreview/ChannelLastMessagePreview';
4949
export * from './ChannelPreview/ChannelMessagePreviewDeliveryStatus';
5050
export * from './ChannelPreview/ChannelPreview';
5151
export * from './ChannelPreview/ChannelPreviewMessage';
5252
export * from './ChannelPreview/ChannelPreviewMessenger';
5353
export * from './ChannelPreview/ChannelPreviewMutedStatus';
54+
export * from './ChannelPreview/ChannelLastMessagePreview';
5455
export * from './ChannelPreview/ChannelPreviewStatus';
5556
export * from './ChannelPreview/ChannelPreviewTitle';
5657
export * from './ChannelPreview/ChannelPreviewTypingIndicator';

package/src/components/ui/Avatar/ChannelAvatar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ import { hashStringToNumber } from '../../../utils/utils';
1616
export type ChannelAvatarProps = {
1717
channel: Channel;
1818
showOnlineIndicator?: boolean;
19-
size: 'lg' | 'xl' | '2xl';
19+
size?: 'lg' | 'xl' | '2xl';
2020
showBorder?: boolean;
2121
};
2222

2323
export const ChannelAvatar = (props: ChannelAvatarProps) => {
2424
const { client } = useChatContext();
2525
const { channel } = props;
2626
const online = useChannelPreviewDisplayPresence(channel);
27-
const { showOnlineIndicator = online, size, showBorder = true } = props;
27+
const { showOnlineIndicator = online, size = 'xl', showBorder = true } = props;
2828

2929
const {
3030
theme: { semantics },

package/src/contexts/channelsContext/ChannelsContext.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type { HeaderErrorProps } from '../../components/ChannelList/ChannelListH
99
import type { GetChannelActionItems } from '../../components/ChannelList/hooks/useChannelActionItems';
1010
import type { QueryChannels } from '../../components/ChannelList/hooks/usePaginatedChannels';
1111
import type { ChannelDetailsBottomSheetProps } from '../../components/ChannelPreview/ChannelDetailsBottomSheet';
12+
import { ChannelLastMessagePreviewProps } from '../../components/ChannelPreview/ChannelLastMessagePreview';
1213
import { ChannelMessagePreviewDeliveryStatusProps } from '../../components/ChannelPreview/ChannelMessagePreviewDeliveryStatus';
1314
import { ChannelPreviewMessageProps } from '../../components/ChannelPreview/ChannelPreviewMessage';
1415
import type { ChannelPreviewMessengerProps } from '../../components/ChannelPreview/ChannelPreviewMessenger';
@@ -20,6 +21,7 @@ import type { EmptyStateProps } from '../../components/Indicators/EmptyStateIndi
2021
import type { LoadingErrorProps } from '../../components/Indicators/LoadingErrorIndicator';
2122
import type { LoadingProps } from '../../components/Indicators/LoadingIndicator';
2223

24+
import { ChannelAvatarProps } from '../../components/ui/Avatar/ChannelAvatar';
2325
import { DEFAULT_BASE_CONTEXT_VALUE } from '../utils/defaultBaseContextValue';
2426

2527
import { isTestEnvironment } from '../utils/isTestEnvironment';
@@ -179,7 +181,7 @@ export type ChannelsContextValue = {
179181
*
180182
* **Default** [ChannelAvatar](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/ChannelPreview/ChannelAvatar.tsx)
181183
*/
182-
PreviewAvatar?: React.ComponentType;
184+
PreviewAvatar?: React.ComponentType<ChannelAvatarProps>;
183185
/**
184186
* Custom UI component to render preview of latest message on channel.
185187
*
@@ -218,6 +220,12 @@ export type ChannelsContextValue = {
218220
PreviewUnreadCount?: React.ComponentType<ChannelPreviewUnreadCountProps>;
219221
PreviewTypingIndicator?: React.ComponentType<ChannelPreviewTypingIndicatorProps>;
220222
ChannelDetailsBottomSheet?: React.ComponentType<ChannelDetailsBottomSheetProps>;
223+
/**
224+
* Custom UI component to render preview of last message on channel.
225+
*
226+
* **Default** [ChannelLastMessagePreview](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/ChannelPreview/ChannelLastMessagePreview.tsx)
227+
*/
228+
PreviewLastMessage?: React.ComponentType<ChannelLastMessagePreviewProps>;
221229
getChannelActionItems?: GetChannelActionItems;
222230
swipeActionsEnabled?: boolean;
223231

0 commit comments

Comments
 (0)