Skip to content

Commit d6f0ba8

Browse files
committed
fix: export relevant hooks from channel preview and channellist and improve customization
1 parent 06b9eed commit d6f0ba8

File tree

12 files changed

+75
-30
lines changed

12 files changed

+75
-30
lines changed

package/src/components/ChannelList/ChannelList.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ export type ChannelListProps = Partial<
5252
| 'PreviewStatus'
5353
| 'PreviewTitle'
5454
| 'PreviewUnreadCount'
55+
| 'PreviewTypingIndicator'
56+
| 'PreviewMessageDeliveryStatus'
5557
| 'ChannelDetailsBottomSheet'
5658
| 'getChannelActionItems'
5759
| 'swipeActionsEnabled'
@@ -287,6 +289,8 @@ export const ChannelList = (props: ChannelListProps) => {
287289
PreviewStatus,
288290
PreviewTitle,
289291
PreviewUnreadCount,
292+
PreviewTypingIndicator,
293+
PreviewMessageDeliveryStatus,
290294
ChannelDetailsBottomSheet,
291295
setFlatListRef,
292296
Skeleton = SkeletonDefault,
@@ -417,6 +421,8 @@ export const ChannelList = (props: ChannelListProps) => {
417421
PreviewStatus,
418422
PreviewTitle,
419423
PreviewUnreadCount,
424+
PreviewTypingIndicator,
425+
PreviewMessageDeliveryStatus,
420426
ChannelDetailsBottomSheet,
421427
swipeActionsEnabled,
422428
refreshing,
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export * from './listeners/useChannelUpdated';
2+
export * from './useChannelActionItems';
3+
export * from './useChannelActionItemsById';
4+
export * from './useChannelActions';
5+
export * from './useChannelMembershipState';
6+
export * from './useChannelMembersState';
7+
export * from './useChannelMuteActive';
8+
export * from './useChannelOnlineMemberCount';
9+
export * from './useIsDirectChat';
10+
export * from './useMutedChannels';
11+
export * from './useMutedUsers';

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ export const useCreateChannelsContext = ({
3030
PreviewMutedStatus,
3131
PreviewStatus,
3232
PreviewTitle,
33+
PreviewTypingIndicator,
34+
PreviewMessageDeliveryStatus,
3335
PreviewUnreadCount,
3436
ChannelDetailsBottomSheet,
3537
swipeActionsEnabled,
@@ -80,6 +82,8 @@ export const useCreateChannelsContext = ({
8082
PreviewStatus,
8183
PreviewTitle,
8284
PreviewUnreadCount,
85+
PreviewTypingIndicator,
86+
PreviewMessageDeliveryStatus,
8387
ChannelDetailsBottomSheet,
8488
swipeActionsEnabled,
8589
refreshing,

package/src/components/ChannelPreview/ChannelPreviewMessage.tsx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ import { ChannelMessagePreview } from './ChannelMessagePreview';
55
import { ChannelMessagePreviewDeliveryStatus } from './ChannelMessagePreviewDeliveryStatus';
66
import { ChannelPreviewProps } from './ChannelPreview';
77

8-
import { ChannelTypingIndicatorPreview } from './ChannelTypingIndicatorPreview';
8+
import { ChannelPreviewTypingIndicator } from './ChannelPreviewTypingIndicator';
99
import { LastMessageType } from './hooks/useChannelPreviewData';
1010

1111
import { useChannelPreviewDraftMessage } from './hooks/useChannelPreviewDraftMessage';
1212
import { useChannelPreviewPollLabel } from './hooks/useChannelPreviewPollLabel';
1313

1414
import { useChannelTypingState } from './hooks/useChannelTypingState';
1515

16+
import { ChannelsContextValue } from '../../contexts/channelsContext/ChannelsContext';
1617
import { useChatContext } from '../../contexts/chatContext/ChatContext';
1718
import { useTheme } from '../../contexts/themeContext/ThemeContext';
1819
import { useTranslationContext } from '../../contexts/translationContext/TranslationContext';
@@ -22,12 +23,18 @@ import { primitives } from '../../theme';
2223
import { MessageStatusTypes } from '../../utils/utils';
2324
import { ErrorBadge } from '../ui';
2425

25-
export type ChannelPreviewMessageProps = Pick<ChannelPreviewProps, 'channel'> & {
26-
lastMessage?: LastMessageType;
27-
};
26+
export type ChannelPreviewMessageProps = Pick<ChannelPreviewProps, 'channel'> &
27+
Pick<ChannelsContextValue, 'PreviewTypingIndicator' | 'PreviewMessageDeliveryStatus'> & {
28+
lastMessage?: LastMessageType;
29+
};
2830

2931
export const ChannelPreviewMessage = (props: ChannelPreviewMessageProps) => {
30-
const { channel, lastMessage } = props;
32+
const {
33+
channel,
34+
lastMessage,
35+
PreviewTypingIndicator = ChannelPreviewTypingIndicator,
36+
PreviewMessageDeliveryStatus = ChannelMessagePreviewDeliveryStatus,
37+
} = props;
3138
const {
3239
theme: { semantics },
3340
} = useTheme();
@@ -52,7 +59,7 @@ export const ChannelPreviewMessage = (props: ChannelPreviewMessageProps) => {
5259
lastMessage?.status === MessageStatusTypes.FAILED || lastMessage?.type === 'error';
5360

5461
if (usersTyping.length > 0) {
55-
return <ChannelTypingIndicatorPreview channel={channel} usersTyping={usersTyping} />;
62+
return <PreviewTypingIndicator channel={channel} usersTyping={usersTyping} />;
5663
}
5764

5865
if (draftMessage) {
@@ -94,14 +101,14 @@ export const ChannelPreviewMessage = (props: ChannelPreviewMessageProps) => {
94101
if (channel.data?.name || membersWithoutSelf.length > 1) {
95102
return (
96103
<View style={styles.container}>
97-
<ChannelMessagePreviewDeliveryStatus channel={channel} message={lastMessage} />
104+
<PreviewMessageDeliveryStatus channel={channel} message={lastMessage} />
98105
<ChannelMessagePreview message={lastMessage} />
99106
</View>
100107
);
101108
} else {
102109
return (
103110
<View style={styles.container}>
104-
<ChannelMessagePreviewDeliveryStatus channel={channel} message={lastMessage} />
111+
<PreviewMessageDeliveryStatus channel={channel} message={lastMessage} />
105112
<ChannelMessagePreview message={lastMessage} />
106113
</View>
107114
);

package/src/components/ChannelPreview/ChannelTypingIndicatorPreview.tsx renamed to package/src/components/ChannelPreview/ChannelPreviewTypingIndicator.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ const getTypingString = ({
5656
}
5757
};
5858

59-
export type ChannelTypingIndicatorPreviewProps = Pick<ChannelPreviewProps, 'channel'> & {
59+
export type ChannelPreviewTypingIndicatorProps = Pick<ChannelPreviewProps, 'channel'> & {
6060
usersTyping: UserResponse[];
6161
};
6262

63-
export const ChannelTypingIndicatorPreview = ({
63+
export const ChannelPreviewTypingIndicator = ({
6464
usersTyping,
6565
channel,
66-
}: ChannelTypingIndicatorPreviewProps) => {
66+
}: ChannelPreviewTypingIndicatorProps) => {
6767
const styles = useStyles();
6868
const { t } = useTranslationContext();
6969

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export * from './useChannelPreviewData';
2+
export * from './useChannelPreviewDraftMessage';
3+
export * from './useChannelPreviewPollLabel';
4+
export * from './useChannelPreviewDisplayName';
5+
export * from './useChannelPreviewDisplayPresence';
6+
export * from './useIsChannelMuted';
7+
export * from './useChannelTypingState';

package/src/components/ChannelPreview/index.ts

Whitespace-only changes.

package/src/components/Chat/Chat.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { Image, Platform } from 'react-native';
33

44
import { Channel, OfflineDBState } from 'stream-chat';
55

6+
import { useClientMutedUsers } from './hooks';
67
import { useAppSettings } from './hooks/useAppSettings';
78
import { useCreateChatContext } from './hooks/useCreateChatContext';
89
import { useIsOnline } from './hooks/useIsOnline';
9-
import { useMutedUsers } from './hooks/useMutedUsers';
1010

1111
import { ChannelsStateProvider } from '../../contexts/channelsStateContext/ChannelsStateContext';
1212
import { ChatContextValue, ChatProvider } from '../../contexts/chatContext/ChatContext';
@@ -172,7 +172,7 @@ const ChatWithContext = (props: PropsWithChildren<ChatProps>) => {
172172
* Setup muted user listener
173173
* TODO: reimplement
174174
*/
175-
const mutedUsers = useMutedUsers(client);
175+
const mutedUsers = useClientMutedUsers(client);
176176

177177
const debugRef = useDebugContext();
178178
const isDebugModeEnabled = __DEV__ && debugRef && debugRef.current;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export * from './useCreateChatClient';
2+
export * from './useIsOnline';
3+
export * from './useSyncDatabase';
4+
export * from './useAppSettings';
5+
export * from './useClientMutedUsers';

package/src/components/Chat/hooks/useMutedUsers.ts renamed to package/src/components/Chat/hooks/useClientMutedUsers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useEffect, useState } from 'react';
22

33
import type { Event, Mute, StreamChat } from 'stream-chat';
44

5-
export const useMutedUsers = (client: StreamChat) => {
5+
export const useClientMutedUsers = (client: StreamChat) => {
66
const [mutedUsers, setMutedUsers] = useState<Mute[]>(client?.mutedUsers || []);
77

88
useEffect(() => {

0 commit comments

Comments
 (0)