Skip to content

Commit

Permalink
Post-merge fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
arnautov-anton committed Feb 12, 2025
1 parent 144603e commit c9d1e66
Show file tree
Hide file tree
Showing 19 changed files with 99 additions and 155 deletions.
2 changes: 1 addition & 1 deletion src/components/Channel/channelState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export type ChannelStateReducerAction =
type: 'copyStateFromChannelOnEvent';
}
| {
channel: Channel<StreamChatGenerics>;
channel: Channel;
highlightedMessageId: string;
type: 'jumpToMessageFinished';
}
Expand Down
11 changes: 9 additions & 2 deletions src/components/ChannelList/ChannelList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import type {
import { useConnectionRecoveredListener } from './hooks/useConnectionRecoveredListener';
import { useMobileNavigation } from './hooks/useMobileNavigation';
import { usePaginatedChannels } from './hooks/usePaginatedChannels';
import { useChannelListShape, usePrepareShapeHandlers } from './hooks/useChannelListShape';
import {
useChannelListShape,
usePrepareShapeHandlers,
} from './hooks/useChannelListShape';
import { useStateStore } from '../../store';
import { ChannelListMessenger } from './ChannelListMessenger';
import { Avatar as DefaultAvatar } from '../Avatar';
Expand All @@ -21,7 +24,11 @@ import { ChannelSearch as DefaultChannelSearch } from '../ChannelSearch/ChannelS
import { EmptyStateIndicator as DefaultEmptyStateIndicator } from '../EmptyStateIndicator';
import { LoadingChannels } from '../Loading/LoadingChannels';
import { LoadMorePaginator } from '../LoadMore/LoadMorePaginator';
import { ChannelListContextProvider, useChatContext, useComponentContext } from '../../context';
import {
ChannelListContextProvider,
useChatContext,
useComponentContext,
} from '../../context';
import { NullComponent } from '../UtilityComponents';
import { MAX_QUERY_CHANNELS_LIMIT, moveChannelUpwards } from './utils';
import type { CustomQueryChannelsFn } from './hooks/usePaginatedChannels';
Expand Down
2 changes: 0 additions & 2 deletions src/components/ChannelPreview/ChannelPreviewMessenger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import clsx from 'clsx';
import { ChannelPreviewActionButtons as DefaultChannelPreviewActionButtons } from './ChannelPreviewActionButtons';
import { Avatar as DefaultAvatar } from '../Avatar';
import { useComponentContext } from '../../context';

import type { ChannelPreviewUIComponentProps } from './ChannelPreview';
import type { DefaultStreamChatGenerics } from '../../types/types';

const UnMemoizedChannelPreviewMessenger = (props: ChannelPreviewUIComponentProps) => {
const {
Expand Down
8 changes: 3 additions & 5 deletions src/components/MessageList/renderMessages.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import type { ReactNode } from 'react';
import React, { Fragment } from 'react';

import type { ReactNode } from 'react';
import type { UserResponse } from 'stream-chat';

import type { GroupStyle } from './utils';
import { getIsFirstUnreadMessage, isDateSeparatorMessage } from './utils';
import { Message } from '../Message';
import { DateSeparator as DefaultDateSeparator } from '../DateSeparator';
import { EventComponent as DefaultMessageSystem } from '../EventComponent';
import { UnreadMessagesSeparator as DefaultUnreadMessagesSeparator } from './UnreadMessagesSeparator';
import type { ComponentContextValue, CustomClasses } from '../../context';
import { CUSTOM_MESSAGE_TYPE } from '../../constants/messageTypes';

import type { ComponentContextValue, CustomClasses } from '../../context';
import type { GroupStyle } from './utils';
import type { ChannelUnreadUiState } from '../../types';
import type { StreamMessage } from '../../context/ChannelStateContext';
import type { MessageProps } from '../Message';
Expand Down
18 changes: 12 additions & 6 deletions src/context/ChannelStateContext.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type { PropsWithChildren } from 'react';
import React, { useContext } from 'react';

import type { PropsWithChildren } from 'react';
import type {
APIErrorResponse,
Channel,
ChannelConfigWithInfo,
ErrorFromResponse,
MessageResponse,
Mute,
ChannelState as StreamChannelState,
Expand All @@ -24,10 +25,15 @@ export type ChannelNotifications = Array<{
type: 'success' | 'error';
}>;

export type StreamMessage = (
| ReturnType<StreamChannelState['formatMessage']>
| MessageResponse
) & { customType?: string; errorStatusCode?: number; editing?: boolean; date?: Date };
export type StreamMessage =
// FIXME: we should use only one of the two (either formatted or unformatted)
(ReturnType<StreamChannelState['formatMessage']> | MessageResponse) & {
customType?: string;
errorStatusCode?: number;
error?: ErrorFromResponse<APIErrorResponse>;
editing?: boolean;
date?: Date;
};

export type ChannelState = {
suppressAutoscroll: boolean;
Expand Down
13 changes: 6 additions & 7 deletions src/context/ChatContext.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import type { PropsWithChildren } from 'react';
import React, { useContext } from 'react';

import { getDisplayName } from './utils/getDisplayName';

import type { PropsWithChildren } from 'react';
import type {
AppSettingsAPIResponse,
Channel,
Mute,
SearchController,
} from 'stream-chat';

import { getDisplayName } from './utils/getDisplayName';
import type { ChatProps } from '../components/Chat/Chat';
import type { UnknownType } from '../types/types';
import type { ChannelsQueryState } from '../components/Chat/hooks/useChannelsQueryState';
Expand All @@ -27,7 +26,7 @@ type CSSClasses =

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

type ChannelCID = string; // e.g.: "messaging:general"
type ChannelConfId = string; // e.g.: "messaging:general"

export type ChatContextValue = {
/**
Expand All @@ -36,11 +35,11 @@ export type ChatContextValue = {
channelsQueryState: ChannelsQueryState;
closeMobileNav: () => void;
getAppSettings: () => Promise<AppSettingsAPIResponse> | null;
latestMessageDatesByChannels: Record<ChannelCID, Date>;
latestMessageDatesByChannels: Record<ChannelConfId, Date>;
mutes: Array<Mute>;
openMobileNav: () => void;
/** Instance of SearchController class that allows to control all the search operations. */
searchController: SearchController<StreamChatGenerics>;
searchController: SearchController;
/**
* Sets active channel to be rendered within Channel component.
* @param newChannel
Expand Down
3 changes: 1 addition & 2 deletions src/context/ComponentContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ import type {
UnreadMessagesNotificationProps,
UnreadMessagesSeparatorProps,
} from '../components';

import {
import type {
SearchProps,
SearchResultsPresearchProps,
SearchSourceResultListProps,
Expand Down
3 changes: 2 additions & 1 deletion src/context/DialogManagerContext.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { PropsWithChildren } from 'react';
import React, { useContext, useState } from 'react';
import type { PropsWithChildren } from 'react';

import { DialogManager } from '../components/Dialog/DialogManager';
import { DialogPortalDestination } from '../components/Dialog/DialogPortal';

Expand Down
12 changes: 4 additions & 8 deletions src/experimental/Search/Search.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import clsx from 'clsx';
import React from 'react';
import type { SearchControllerState } from 'stream-chat';

import { SearchBar as DefaultSearchBar } from './SearchBar/SearchBar';
import { SearchResults as DefaultSearchResults } from './SearchResults/SearchResults';
import { SearchContextProvider } from './SearchContext';
import { useChatContext, useComponentContext } from '../../context';
import { useStateStore } from '../../store';

import type { SearchControllerState } from 'stream-chat';
import type { DefaultStreamChatGenerics } from '../../types';

type SearchControllerStateSelectorReturnValue = {
isActive: boolean;
};
Expand All @@ -28,9 +26,7 @@ export type SearchProps = {
placeholder?: string;
};

export const Search = <
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
>({
export const Search = ({
directMessagingChannelType = 'messaging',
disabled,
exitSearchOnInputBlur,
Expand All @@ -39,15 +35,15 @@ export const Search = <
const { SearchBar = DefaultSearchBar, SearchResults = DefaultSearchResults } =
useComponentContext();

const { searchController } = useChatContext<StreamChatGenerics>();
const { searchController } = useChatContext();

const { isActive } = useStateStore<
SearchControllerState,
SearchControllerStateSelectorReturnValue
>(searchController.state, searchControllerStateSelector);

return (
<SearchContextProvider<StreamChatGenerics>
<SearchContextProvider
value={{
directMessagingChannelType,
disabled,
Expand Down
22 changes: 8 additions & 14 deletions src/experimental/Search/SearchContext.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import React, { createContext, PropsWithChildren, useContext } from 'react';
import React, { createContext, useContext } from 'react';
import type { PropsWithChildren } from 'react';
import type { SearchController } from 'stream-chat';
import type { DefaultStreamChatGenerics } from '../../types';

export type SearchContextValue<
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
> = {
export type SearchContextValue = {
/** The type of channel to create on user result select, defaults to `messaging` */
directMessagingChannelType: string;
/** Instance of the search controller that handles the data management */
searchController: SearchController<StreamChatGenerics>;
searchController: SearchController;
/** Sets the input element into disabled state */
disabled?: boolean;
/** Clear search state / results on every click outside the search input, defaults to true */
Expand All @@ -22,22 +20,18 @@ export const SearchContext = createContext<SearchContextValue | undefined>(undef
/**
* Context provider for components rendered within the `Search` component
*/
export const SearchContextProvider = <
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
>({
export const SearchContextProvider = ({
children,
value,
}: PropsWithChildren<{
value: SearchContextValue<StreamChatGenerics>;
value: SearchContextValue;
}>) => (
<SearchContext.Provider value={value as unknown as SearchContextValue}>
{children}
</SearchContext.Provider>
);

export const useSearchContext = <
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
>() => {
export const useSearchContext = () => {
const contextValue = useContext(SearchContext);
return contextValue as unknown as SearchContextValue<StreamChatGenerics>;
return contextValue as unknown as SearchContextValue;
};
58 changes: 20 additions & 38 deletions src/experimental/Search/SearchResults/SearchResultItem.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
import React, { useCallback, useMemo } from 'react';
import uniqBy from 'lodash.uniqby';
import React, { ComponentType, useCallback, useMemo } from 'react';
import type { ComponentType } from 'react';
import type { Channel, MessageResponse, User } from 'stream-chat';

import { useSearchContext } from '../SearchContext';
import { Avatar } from '../../../components/Avatar';
import { ChannelPreview } from '../../../components/ChannelPreview';
import { useChannelListContext, useChatContext } from '../../../context';

import { DEFAULT_JUMP_TO_PAGE_SIZE } from '../../../constants/limits';

import type { Channel, MessageResponse, User } from 'stream-chat';
import type { DefaultStreamChatGenerics } from '../../../types';

export type ChannelSearchResultItemProps<
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
> = {
item: Channel<StreamChatGenerics>;
export type ChannelSearchResultItemProps = {
item: Channel;
};

export const ChannelSearchResultItem = <
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
>({
item,
}: ChannelSearchResultItemProps<StreamChatGenerics>) => {
const { setActiveChannel } = useChatContext<StreamChatGenerics>();
const { setChannels } = useChannelListContext<StreamChatGenerics>();
export const ChannelSearchResultItem = ({ item }: ChannelSearchResultItemProps) => {
const { setActiveChannel } = useChatContext();
const { setChannels } = useChannelListContext();

const onSelect = useCallback(() => {
setActiveChannel(item);
Expand All @@ -39,24 +31,20 @@ export const ChannelSearchResultItem = <
);
};

export type ChannelByMessageSearchResultItemProps<
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
> = {
item: MessageResponse<StreamChatGenerics>;
export type ChannelByMessageSearchResultItemProps = {
item: MessageResponse;
};

export const MessageSearchResultItem = <
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
>({
export const MessageSearchResultItem = ({
item,
}: ChannelByMessageSearchResultItemProps<StreamChatGenerics>) => {
}: ChannelByMessageSearchResultItemProps) => {
const {
channel: activeChannel,
client,
searchController,
setActiveChannel,
} = useChatContext<StreamChatGenerics>();
const { setChannels } = useChannelListContext<StreamChatGenerics>();
} = useChatContext();
const { setChannels } = useChannelListContext();

const channel = useMemo(() => {
const { channel: channelData } = item;
Expand Down Expand Up @@ -97,20 +85,14 @@ export const MessageSearchResultItem = <
);
};

export type UserSearchResultItemProps<
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
> = {
item: User<StreamChatGenerics>;
export type UserSearchResultItemProps = {
item: User;
};

export const UserSearchResultItem = <
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
>({
item,
}: UserSearchResultItemProps<StreamChatGenerics>) => {
const { client, setActiveChannel } = useChatContext<StreamChatGenerics>();
const { setChannels } = useChannelListContext<StreamChatGenerics>();
const { directMessagingChannelType } = useSearchContext<StreamChatGenerics>();
export const UserSearchResultItem = ({ item }: UserSearchResultItemProps) => {
const { client, setActiveChannel } = useChatContext();
const { setChannels } = useChannelListContext();
const { directMessagingChannelType } = useSearchContext();

const onClick = useCallback(() => {
const newChannel = client.channel(directMessagingChannelType, {
Expand Down
12 changes: 4 additions & 8 deletions src/experimental/Search/SearchResults/SearchResults.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import type { SearchControllerState } from 'stream-chat';

import { SearchSourceResults as DefaultSourceSearchResults } from './SearchSourceResults';
import { SearchResultsHeader as DefaultSearchResultsHeader } from './SearchResultsHeader';
Expand All @@ -7,25 +8,20 @@ import { useSearchContext } from '../SearchContext';
import { useComponentContext, useTranslationContext } from '../../../context';
import { useStateStore } from '../../../store';

import type { SearchControllerState } from 'stream-chat';
import type { DefaultStreamChatGenerics } from '../../../types';

const searchControllerStateSelector = (nextValue: SearchControllerState) => ({
activeSources: nextValue.sources.filter((s) => s.isActive),
isActive: nextValue.isActive,
searchQuery: nextValue.searchQuery,
});

export const SearchResults = <
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
>() => {
export const SearchResults = () => {
const { t } = useTranslationContext('ResultsContainer');
const {
SearchResultsHeader = DefaultSearchResultsHeader,
SearchResultsPresearch = DefaultSearchResultsPresearch,
SearchSourceResults = DefaultSourceSearchResults,
} = useComponentContext<StreamChatGenerics>();
const { searchController } = useSearchContext<StreamChatGenerics>();
} = useComponentContext();
const { searchController } = useSearchContext();
const { activeSources, isActive, searchQuery } = useStateStore(
searchController.state,
searchControllerStateSelector,
Expand Down
Loading

0 comments on commit c9d1e66

Please sign in to comment.