Skip to content

Commit b954535

Browse files
Post-merge fixes
1 parent 29017df commit b954535

21 files changed

+108
-167
lines changed

src/components/Channel/channelState.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export type ChannelStateReducerAction =
2323
type: 'copyStateFromChannelOnEvent';
2424
}
2525
| {
26-
channel: Channel<StreamChatGenerics>;
26+
channel: Channel;
2727
highlightedMessageId: string;
2828
type: 'jumpToMessageFinished';
2929
}

src/components/ChannelList/ChannelList.tsx

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import React, { ReactNode, useCallback, useEffect, useRef, useState } from 'react';
1+
import React, { useCallback, useEffect, useRef, useState } from 'react';
22
import clsx from 'clsx';
3+
import type { ReactNode} from 'react';
34
import type {
45
Channel,
56
ChannelFilters,
@@ -12,7 +13,10 @@ import type {
1213
import { useConnectionRecoveredListener } from './hooks/useConnectionRecoveredListener';
1314
import { useMobileNavigation } from './hooks/useMobileNavigation';
1415
import { usePaginatedChannels } from './hooks/usePaginatedChannels';
15-
import { useChannelListShape, usePrepareShapeHandlers } from './hooks/useChannelListShape';
16+
import {
17+
useChannelListShape,
18+
usePrepareShapeHandlers,
19+
} from './hooks/useChannelListShape';
1620
import { useStateStore } from '../../store';
1721
import { ChannelListMessenger } from './ChannelListMessenger';
1822
import { Avatar as DefaultAvatar } from '../Avatar';
@@ -21,7 +25,11 @@ import { ChannelSearch as DefaultChannelSearch } from '../ChannelSearch/ChannelS
2125
import { EmptyStateIndicator as DefaultEmptyStateIndicator } from '../EmptyStateIndicator';
2226
import { LoadingChannels } from '../Loading/LoadingChannels';
2327
import { LoadMorePaginator } from '../LoadMore/LoadMorePaginator';
24-
import { ChannelListContextProvider, useChatContext, useComponentContext } from '../../context';
28+
import {
29+
ChannelListContextProvider,
30+
useChatContext,
31+
useComponentContext,
32+
} from '../../context';
2533
import { NullComponent } from '../UtilityComponents';
2634
import { MAX_QUERY_CHANNELS_LIMIT, moveChannelUpwards } from './utils';
2735
import type { CustomQueryChannelsFn } from './hooks/usePaginatedChannels';

src/components/ChannelPreview/ChannelPreview.tsx

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
import throttle from 'lodash.throttle';
2-
import React, { ReactNode, useEffect, useMemo, useState } from 'react';
2+
import React, { useEffect, useMemo, useState } from 'react';
3+
import type { ReactNode} from 'react';
4+
import type { Channel, Event } from 'stream-chat';
35

46
import { ChannelPreviewMessenger } from './ChannelPreviewMessenger';
57
import { useIsChannelMuted } from './hooks/useIsChannelMuted';
68
import { useChannelPreviewInfo } from './hooks/useChannelPreviewInfo';
79
import { getLatestMessagePreview as defaultGetLatestMessagePreview } from './utils';
8-
9-
import type { ChatContextValue } from '../../context/ChatContext';
1010
import { useChatContext } from '../../context/ChatContext';
1111
import { useTranslationContext } from '../../context/TranslationContext';
12-
import type { MessageDeliveryStatus } from './hooks/useMessageDeliveryStatus';
1312
import { useMessageDeliveryStatus } from './hooks/useMessageDeliveryStatus';
14-
15-
import type { Channel, Event } from 'stream-chat';
16-
13+
import type { MessageDeliveryStatus } from './hooks/useMessageDeliveryStatus';
14+
import type { ChatContextValue } from '../../context/ChatContext';
1715
import type { ChannelAvatarProps } from '../Avatar/ChannelAvatar';
1816
import type { GroupChannelDisplayInfo } from './utils';
1917
import type { StreamMessage } from '../../context/ChannelStateContext';

src/components/ChannelPreview/ChannelPreviewMessenger.tsx

-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import clsx from 'clsx';
44
import { ChannelPreviewActionButtons as DefaultChannelPreviewActionButtons } from './ChannelPreviewActionButtons';
55
import { Avatar as DefaultAvatar } from '../Avatar';
66
import { useComponentContext } from '../../context';
7-
87
import type { ChannelPreviewUIComponentProps } from './ChannelPreview';
9-
import type { DefaultStreamChatGenerics } from '../../types/types';
108

119
const UnMemoizedChannelPreviewMessenger = (props: ChannelPreviewUIComponentProps) => {
1210
const {

src/components/ChannelPreview/utils.tsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import React, { ReactNode } from 'react';
2-
1+
import React from 'react';
32
import ReactMarkdown from 'react-markdown';
4-
3+
import type { ReactNode } from 'react';
54
import type { Channel, PollVote, TranslationLanguages, UserResponse } from 'stream-chat';
65

76
import type { TranslationContextValue } from '../../context/TranslationContext';
8-
97
import type { ChatContextValue } from '../../context';
108

119
export const renderPreviewText = (text: string) => (

src/components/MessageList/renderMessages.tsx

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
import type { ReactNode } from 'react';
21
import React, { Fragment } from 'react';
3-
2+
import type { ReactNode } from 'react';
43
import type { UserResponse } from 'stream-chat';
54

6-
import type { GroupStyle } from './utils';
75
import { getIsFirstUnreadMessage, isDateSeparatorMessage } from './utils';
86
import { Message } from '../Message';
97
import { DateSeparator as DefaultDateSeparator } from '../DateSeparator';
108
import { EventComponent as DefaultMessageSystem } from '../EventComponent';
119
import { UnreadMessagesSeparator as DefaultUnreadMessagesSeparator } from './UnreadMessagesSeparator';
12-
import type { ComponentContextValue, CustomClasses } from '../../context';
1310
import { CUSTOM_MESSAGE_TYPE } from '../../constants/messageTypes';
14-
11+
import type { ComponentContextValue, CustomClasses } from '../../context';
12+
import type { GroupStyle } from './utils';
1513
import type { ChannelUnreadUiState } from '../../types';
1614
import type { StreamMessage } from '../../context/ChannelStateContext';
1715
import type { MessageProps } from '../Message';

src/context/ChannelStateContext.tsx

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import type { PropsWithChildren } from 'react';
21
import React, { useContext } from 'react';
3-
2+
import type { PropsWithChildren } from 'react';
43
import type {
4+
APIErrorResponse,
55
Channel,
66
ChannelConfigWithInfo,
7+
ErrorFromResponse,
78
MessageResponse,
89
Mute,
910
ChannelState as StreamChannelState,
@@ -24,10 +25,15 @@ export type ChannelNotifications = Array<{
2425
type: 'success' | 'error';
2526
}>;
2627

27-
export type StreamMessage = (
28-
| ReturnType<StreamChannelState['formatMessage']>
29-
| MessageResponse
30-
) & { customType?: string; errorStatusCode?: number; editing?: boolean; date?: Date };
28+
export type StreamMessage =
29+
// FIXME: we should use only one of the two (either formatted or unformatted)
30+
(ReturnType<StreamChannelState['formatMessage']> | MessageResponse) & {
31+
customType?: string;
32+
errorStatusCode?: number;
33+
error?: ErrorFromResponse<APIErrorResponse>;
34+
editing?: boolean;
35+
date?: Date;
36+
};
3137

3238
export type ChannelState = {
3339
suppressAutoscroll: boolean;

src/context/ChatContext.tsx

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
import type { PropsWithChildren } from 'react';
21
import React, { useContext } from 'react';
3-
4-
import { getDisplayName } from './utils/getDisplayName';
5-
2+
import type { PropsWithChildren } from 'react';
63
import type {
74
AppSettingsAPIResponse,
85
Channel,
96
Mute,
107
SearchController,
118
} from 'stream-chat';
9+
10+
import { getDisplayName } from './utils/getDisplayName';
1211
import type { ChatProps } from '../components/Chat/Chat';
1312
import type { UnknownType } from '../types/types';
1413
import type { ChannelsQueryState } from '../components/Chat/hooks/useChannelsQueryState';
@@ -27,7 +26,7 @@ type CSSClasses =
2726

2827
export type CustomClasses = Partial<Record<CSSClasses, string>>;
2928

30-
type ChannelCID = string; // e.g.: "messaging:general"
29+
type ChannelConfId = string; // e.g.: "messaging:general"
3130

3231
export type ChatContextValue = {
3332
/**
@@ -36,11 +35,11 @@ export type ChatContextValue = {
3635
channelsQueryState: ChannelsQueryState;
3736
closeMobileNav: () => void;
3837
getAppSettings: () => Promise<AppSettingsAPIResponse> | null;
39-
latestMessageDatesByChannels: Record<ChannelCID, Date>;
38+
latestMessageDatesByChannels: Record<ChannelConfId, Date>;
4039
mutes: Array<Mute>;
4140
openMobileNav: () => void;
4241
/** Instance of SearchController class that allows to control all the search operations. */
43-
searchController: SearchController<StreamChatGenerics>;
42+
searchController: SearchController;
4443
/**
4544
* Sets active channel to be rendered within Channel component.
4645
* @param newChannel

src/context/ComponentContext.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ import type {
5151
UnreadMessagesNotificationProps,
5252
UnreadMessagesSeparatorProps,
5353
} from '../components';
54-
55-
import {
54+
import type {
5655
SearchProps,
5756
SearchResultsPresearchProps,
5857
SearchSourceResultListProps,

src/context/DialogManagerContext.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import type { PropsWithChildren } from 'react';
21
import React, { useContext, useState } from 'react';
2+
import type { PropsWithChildren } from 'react';
3+
34
import { DialogManager } from '../components/Dialog/DialogManager';
45
import { DialogPortalDestination } from '../components/Dialog/DialogPortal';
56

src/experimental/Search/Search.tsx

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import clsx from 'clsx';
22
import React from 'react';
3+
import type { SearchControllerState } from 'stream-chat';
34

45
import { SearchBar as DefaultSearchBar } from './SearchBar/SearchBar';
56
import { SearchResults as DefaultSearchResults } from './SearchResults/SearchResults';
67
import { SearchContextProvider } from './SearchContext';
78
import { useChatContext, useComponentContext } from '../../context';
89
import { useStateStore } from '../../store';
910

10-
import type { SearchControllerState } from 'stream-chat';
11-
import type { DefaultStreamChatGenerics } from '../../types';
12-
1311
type SearchControllerStateSelectorReturnValue = {
1412
isActive: boolean;
1513
};
@@ -28,9 +26,7 @@ export type SearchProps = {
2826
placeholder?: string;
2927
};
3028

31-
export const Search = <
32-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
33-
>({
29+
export const Search = ({
3430
directMessagingChannelType = 'messaging',
3531
disabled,
3632
exitSearchOnInputBlur,
@@ -39,15 +35,15 @@ export const Search = <
3935
const { SearchBar = DefaultSearchBar, SearchResults = DefaultSearchResults } =
4036
useComponentContext();
4137

42-
const { searchController } = useChatContext<StreamChatGenerics>();
38+
const { searchController } = useChatContext();
4339

4440
const { isActive } = useStateStore<
4541
SearchControllerState,
4642
SearchControllerStateSelectorReturnValue
4743
>(searchController.state, searchControllerStateSelector);
4844

4945
return (
50-
<SearchContextProvider<StreamChatGenerics>
46+
<SearchContextProvider
5147
value={{
5248
directMessagingChannelType,
5349
disabled,
+8-14
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
import React, { createContext, PropsWithChildren, useContext } from 'react';
1+
import React, { createContext, useContext } from 'react';
2+
import type { PropsWithChildren } from 'react';
23
import type { SearchController } from 'stream-chat';
3-
import type { DefaultStreamChatGenerics } from '../../types';
44

5-
export type SearchContextValue<
6-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
7-
> = {
5+
export type SearchContextValue = {
86
/** The type of channel to create on user result select, defaults to `messaging` */
97
directMessagingChannelType: string;
108
/** Instance of the search controller that handles the data management */
11-
searchController: SearchController<StreamChatGenerics>;
9+
searchController: SearchController;
1210
/** Sets the input element into disabled state */
1311
disabled?: boolean;
1412
/** Clear search state / results on every click outside the search input, defaults to true */
@@ -22,22 +20,18 @@ export const SearchContext = createContext<SearchContextValue | undefined>(undef
2220
/**
2321
* Context provider for components rendered within the `Search` component
2422
*/
25-
export const SearchContextProvider = <
26-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
27-
>({
23+
export const SearchContextProvider = ({
2824
children,
2925
value,
3026
}: PropsWithChildren<{
31-
value: SearchContextValue<StreamChatGenerics>;
27+
value: SearchContextValue;
3228
}>) => (
3329
<SearchContext.Provider value={value as unknown as SearchContextValue}>
3430
{children}
3531
</SearchContext.Provider>
3632
);
3733

38-
export const useSearchContext = <
39-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
40-
>() => {
34+
export const useSearchContext = () => {
4135
const contextValue = useContext(SearchContext);
42-
return contextValue as unknown as SearchContextValue<StreamChatGenerics>;
36+
return contextValue as unknown as SearchContextValue;
4337
};

src/experimental/Search/SearchResults/SearchResultItem.tsx

+20-38
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,21 @@
1+
import React, { useCallback, useMemo } from 'react';
12
import uniqBy from 'lodash.uniqby';
2-
import React, { ComponentType, useCallback, useMemo } from 'react';
3+
import type { ComponentType } from 'react';
4+
import type { Channel, MessageResponse, User } from 'stream-chat';
35

46
import { useSearchContext } from '../SearchContext';
57
import { Avatar } from '../../../components/Avatar';
68
import { ChannelPreview } from '../../../components/ChannelPreview';
79
import { useChannelListContext, useChatContext } from '../../../context';
8-
910
import { DEFAULT_JUMP_TO_PAGE_SIZE } from '../../../constants/limits';
1011

11-
import type { Channel, MessageResponse, User } from 'stream-chat';
12-
import type { DefaultStreamChatGenerics } from '../../../types';
13-
14-
export type ChannelSearchResultItemProps<
15-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
16-
> = {
17-
item: Channel<StreamChatGenerics>;
12+
export type ChannelSearchResultItemProps = {
13+
item: Channel;
1814
};
1915

20-
export const ChannelSearchResultItem = <
21-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
22-
>({
23-
item,
24-
}: ChannelSearchResultItemProps<StreamChatGenerics>) => {
25-
const { setActiveChannel } = useChatContext<StreamChatGenerics>();
26-
const { setChannels } = useChannelListContext<StreamChatGenerics>();
16+
export const ChannelSearchResultItem = ({ item }: ChannelSearchResultItemProps) => {
17+
const { setActiveChannel } = useChatContext();
18+
const { setChannels } = useChannelListContext();
2719

2820
const onSelect = useCallback(() => {
2921
setActiveChannel(item);
@@ -39,24 +31,20 @@ export const ChannelSearchResultItem = <
3931
);
4032
};
4133

42-
export type ChannelByMessageSearchResultItemProps<
43-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
44-
> = {
45-
item: MessageResponse<StreamChatGenerics>;
34+
export type ChannelByMessageSearchResultItemProps = {
35+
item: MessageResponse;
4636
};
4737

48-
export const MessageSearchResultItem = <
49-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
50-
>({
38+
export const MessageSearchResultItem = ({
5139
item,
52-
}: ChannelByMessageSearchResultItemProps<StreamChatGenerics>) => {
40+
}: ChannelByMessageSearchResultItemProps) => {
5341
const {
5442
channel: activeChannel,
5543
client,
5644
searchController,
5745
setActiveChannel,
58-
} = useChatContext<StreamChatGenerics>();
59-
const { setChannels } = useChannelListContext<StreamChatGenerics>();
46+
} = useChatContext();
47+
const { setChannels } = useChannelListContext();
6048

6149
const channel = useMemo(() => {
6250
const { channel: channelData } = item;
@@ -97,20 +85,14 @@ export const MessageSearchResultItem = <
9785
);
9886
};
9987

100-
export type UserSearchResultItemProps<
101-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
102-
> = {
103-
item: User<StreamChatGenerics>;
88+
export type UserSearchResultItemProps = {
89+
item: User;
10490
};
10591

106-
export const UserSearchResultItem = <
107-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
108-
>({
109-
item,
110-
}: UserSearchResultItemProps<StreamChatGenerics>) => {
111-
const { client, setActiveChannel } = useChatContext<StreamChatGenerics>();
112-
const { setChannels } = useChannelListContext<StreamChatGenerics>();
113-
const { directMessagingChannelType } = useSearchContext<StreamChatGenerics>();
92+
export const UserSearchResultItem = ({ item }: UserSearchResultItemProps) => {
93+
const { client, setActiveChannel } = useChatContext();
94+
const { setChannels } = useChannelListContext();
95+
const { directMessagingChannelType } = useSearchContext();
11496

11597
const onClick = useCallback(() => {
11698
const newChannel = client.channel(directMessagingChannelType, {

0 commit comments

Comments
 (0)