Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
"emoji-mart": "^5.4.0",
"react": "^19.0.0 || ^18.0.0 || ^17.0.0 || ^16.14.0",
"react-dom": "^19.0.0 || ^18.0.0 || ^17.0.0 || ^16.14.0",
"stream-chat": "^9.0.0-rc.13"
"stream-chat": "^9.0.0-rc.15"
},
"peerDependenciesMeta": {
"@breezystack/lamejs": {
Expand Down Expand Up @@ -239,7 +239,7 @@
"react": "^19.0.0",
"react-dom": "^19.0.0",
"semantic-release": "^24.2.3",
"stream-chat": "^9.0.0-rc.13",
"stream-chat": "^9.0.0-rc.15",
"ts-jest": "^29.2.5",
"typescript": "^5.4.5",
"typescript-eslint": "^8.17.0"
Expand Down
4 changes: 2 additions & 2 deletions src/components/MessageInput/__tests__/EditMessageForm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ describe(`EditMessageForm`, () => {
const CustomStateSetter = () => {
const composer = useMessageComposerMock();
useEffect(() => {
composer.customDataManager.setData(customMessageData);
composer.customDataManager.setMessageData(customMessageData);
}, [composer]);
};
const { container, submit } = await renderComponent({
Expand Down Expand Up @@ -954,7 +954,7 @@ describe(`EditMessageForm`, () => {
const CustomStateSetter = () => {
const composer = useMessageComposerMock();
useEffect(() => {
composer.customDataManager.setData(customMessageData);
composer.customDataManager.setMessageData(customMessageData);
}, [composer]);
};
const { container, submit } = await renderComponent({
Expand Down
4 changes: 2 additions & 2 deletions src/components/MessageInput/__tests__/MessageInput.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ describe(`MessageInputFlat`, () => {
const customMessageData = { customX: 'customX' };
const CustomStateSetter = null;

customChannel.messageComposer.customDataManager.setData(customMessageData);
customChannel.messageComposer.customDataManager.setMessageData(customMessageData);
const { container, submit } = await renderComponent({
customChannel,
customClient,
Expand Down Expand Up @@ -823,7 +823,7 @@ describe(`MessageInputFlat`, () => {
const overrideMock = jest.fn().mockImplementation(() => Promise.resolve());
const { customChannel, customClient } = await setup();
const customMessageData = { customX: 'customX' };
customChannel.messageComposer.customDataManager.setData(customMessageData);
customChannel.messageComposer.customDataManager.setMessageData(customMessageData);
const { container, submit } = await renderComponent({
customChannel,
customClient,
Expand Down
10 changes: 2 additions & 8 deletions src/components/TextareaComposer/SuggestionList/CommandItem.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import type { PropsWithChildren } from 'react';
import React from 'react';
import type { CommandResponse } from 'stream-chat';

export type CommandItemProps = {
entity: {
/** Arguments of command */
args?: string;
/** Description of command */
description?: string;
/** Name of the command */
name?: string;
};
entity: CommandResponse;
};

export const CommandItem = (props: PropsWithChildren<CommandItemProps>) => {
Expand Down
37 changes: 28 additions & 9 deletions src/components/TextareaComposer/SuggestionList/SuggestionList.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import clsx from 'clsx';
import React, { useEffect, useState } from 'react';
import type { CommandItemProps } from './CommandItem';
import { CommandItem } from './CommandItem';
import type { EmoticonItemProps } from './EmoticonItem';
import { EmoticonItem } from './EmoticonItem';
import type { SuggestionListItemComponentProps } from './SuggestionListItem';
import { SuggestionListItem as DefaultSuggestionListItem } from './SuggestionListItem';
import { UserItem } from './UserItem';
import { useComponentContext } from '../../../context/ComponentContext';
Expand All @@ -13,10 +16,15 @@
TextComposerState,
TextComposerSuggestion,
} from 'stream-chat';
import type { SuggestionItemProps } from './SuggestionListItem';
import type { UserItemProps } from './UserItem';

type SuggestionTrigger = '/' | ':' | '@' | string;

export type SuggestionListProps = Partial<{
SuggestionItem: React.ComponentType<SuggestionItemProps>;
suggestionItemComponents: Record<
SuggestionTrigger,
React.ComponentType<SuggestionListItemComponentProps>
>;
className?: string;
closeOnClickOutside?: boolean;
containerClassName?: string;
Expand All @@ -34,18 +42,28 @@
items: nextValue.items ?? [],
});

export const defaultComponents = {
'/': CommandItem,
':': EmoticonItem,
'@': UserItem,
};
export const defaultComponents: Record<
SuggestionTrigger,
React.ComponentType<SuggestionListItemComponentProps>
> = {
'/': (props: SuggestionListItemComponentProps) => (
<CommandItem entity={props.entity as CommandItemProps['entity']} />

Check warning on line 50 in src/components/TextareaComposer/SuggestionList/SuggestionList.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/TextareaComposer/SuggestionList/SuggestionList.tsx#L50

Added line #L50 was not covered by tests
),
':': (props: SuggestionListItemComponentProps) => (
<EmoticonItem entity={props.entity as EmoticonItemProps['entity']} />

Check warning on line 53 in src/components/TextareaComposer/SuggestionList/SuggestionList.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/TextareaComposer/SuggestionList/SuggestionList.tsx#L53

Added line #L53 was not covered by tests
),
'@': (props: SuggestionListItemComponentProps) => (
<UserItem entity={props.entity as UserItemProps['entity']} />
),
} as const;

export const SuggestionList = ({
className,
closeOnClickOutside = true,
containerClassName,
focusedItemIndex,
setFocusedItemIndex,
suggestionItemComponents = defaultComponents,
}: SuggestionListProps) => {
const { AutocompleteSuggestionItem = DefaultSuggestionListItem } =
useComponentContext();
Expand All @@ -56,8 +74,9 @@
useStateStore(suggestions?.searchSource.state, searchSourceStateSelector) ?? {};
const [container, setContainer] = useState<HTMLDivElement | null>(null);

// @ts-expect-error component type mismatch
const component = suggestions?.trigger && defaultComponents[suggestions?.trigger];
const component = suggestions?.trigger
? suggestionItemComponents[suggestions?.trigger]
: undefined;

useEffect(() => {
if (!closeOnClickOutside || !suggestions || !container) return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import clsx from 'clsx';
import type { Ref } from 'react';
import { useLayoutEffect } from 'react';
import React, { useCallback, useRef } from 'react';
import React, { useCallback, useLayoutEffect, useRef } from 'react';
import { useMessageComposer } from '../../MessageInput';
import type { CommandResponse, TextComposerSuggestion, UserResponse } from 'stream-chat';
import type { EmojiSearchIndexResult } from '../../MessageInput';
import type { TextComposerSuggestion } from 'stream-chat';
import type { UserItemProps } from './UserItem';
import type { CommandItemProps } from './CommandItem';
import type { EmoticonItemProps } from './EmoticonItem';

export type SuggestionCommand = CommandResponse;
export type SuggestionUser = UserResponse;
export type SuggestionEmoji = EmojiSearchIndexResult;
export type SuggestionItem = SuggestionUser | SuggestionCommand | SuggestionEmoji;
export type DefaultSuggestionListItemEntity =
| UserItemProps['entity']
| CommandItemProps['entity']
| EmoticonItemProps['entity'];

export type SuggestionListItemComponentProps = {
entity: DefaultSuggestionListItemEntity | unknown;
focused: boolean;
};

export type SuggestionItemProps = {
component: React.ComponentType<{
entity: SuggestionItem;
focused: boolean;
}>;
component: React.ComponentType<SuggestionListItemComponentProps>;
item: TextComposerSuggestion;
focused: boolean;
className?: string;
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12155,10 +12155,10 @@ [email protected]:
resolved "https://registry.yarnpkg.com/statuses/-/statuses-2.0.1.tgz#55cb000ccf1d48728bd23c685a063998cf1a1b63"
integrity sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==

stream-chat@^9.0.0-rc.13:
version "9.0.0-rc.13"
resolved "https://registry.yarnpkg.com/stream-chat/-/stream-chat-9.0.0-rc.13.tgz#90396d724bd5f81e2d8eb051c9c56b075892305f"
integrity sha512-qJPcHsQUfu0qMb7p7Bv9OnL6qID/qxYLKOIsG6KbUNEQHwkKSw/aDwExpvgJR7dXsUOLyLZFhVtYnFkAPDdJ3A==
stream-chat@^9.0.0-rc.15:
version "9.0.0-rc.15"
resolved "https://registry.yarnpkg.com/stream-chat/-/stream-chat-9.0.0-rc.15.tgz#6a35f27c38be2e021a3e62abcffa40aaef84fc0a"
integrity sha512-n8IftP103jp8IVOUZA4mnOvEIbyzGTVjoL3rDm42apk8DRHz2/vdvgyTYUJysDNYh+Oxu5HwWObToKv1c/Bxdw==
dependencies:
"@types/jsonwebtoken" "^9.0.8"
"@types/ws" "^8.5.14"
Expand Down