Skip to content

Commit 081376b

Browse files
committed
refactor: make the message composer code runable
1 parent 979ab8b commit 081376b

File tree

2 files changed

+36
-18
lines changed

2 files changed

+36
-18
lines changed

src/components/TextAreaComposer/SuggestionList.tsx

+10-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import { type SearchSourceState } from 'stream-chat';
1313
import { useMessageComposer } from '../MessageInput/hooks/messageComposer/useMessageComposer';
1414
import { useStateStore } from '../../store';
1515
import { InfiniteScrollPaginator } from '../InfiniteScrollPaginator/InfiniteScrollPaginator';
16+
import { EmoticonItem } from '../EmoticonItem';
17+
import { CommandItem } from '../CommandItem';
18+
import { UserItem } from '../UserItem';
1619

1720
type ObjectUnion<T> = T[keyof T];
1821

@@ -21,7 +24,6 @@ export type SuggestionListProps<
2124
EmojiData extends UnknownType = UnknownType,
2225
> = ObjectUnion<{
2326
[key in keyof TriggerSettings<V>]: Partial<{
24-
component: TriggerSettings<V>[key]['component'];
2527
dropdownScroll: (element: HTMLElement) => void;
2628
getSelectedItem:
2729
| ((item: Parameters<TriggerSettings<V>[key]['output']>[0]) => void)
@@ -52,7 +54,6 @@ export const SuggestionList = <
5254
EmojiData extends UnknownType = UnknownType,
5355
>({
5456
className,
55-
component,
5657
value: propValue,
5758
}: SuggestionListProps<V>) => {
5859
const { AutocompleteSuggestionItem = DefaultSuggestionListItem } =
@@ -65,7 +66,13 @@ export const SuggestionList = <
6566
// const [selectedItemIndex, setSelectedItemIndex] = useState<number | undefined>(
6667
// undefined,
6768
// );
68-
69+
const component =
70+
suggestions?.trigger &&
71+
{
72+
'/': CommandItem,
73+
':': EmoticonItem,
74+
'@': UserItem,
75+
}[suggestions?.trigger];
6976
const itemsRef: HTMLElement[] = [];
7077

7178
// const isSelected = (item: SuggestionItem<EmojiData>) =>

src/components/UserItem/UserItem.tsx

+26-15
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,37 @@ export type UserItemProps = {
2727
*/
2828
const UnMemoizedUserItem = ({ Avatar = DefaultAvatar, entity }: UserItemProps) => {
2929
const hasEntity = !!Object.keys(entity).length;
30-
const itemParts = entity?.itemNameParts;
30+
// const itemParts = entity?.itemNameParts;
3131

3232
const renderName = () => {
3333
if (!hasEntity) return null;
3434

35-
return itemParts.parts.map((part, i) => {
36-
const matches = part.toLowerCase() === itemParts.match.toLowerCase();
35+
// return itemParts.parts.map((part, i) => {
36+
// const matches = part.toLowerCase() === itemParts.match.toLowerCase();
37+
//
38+
// return (
39+
// <span
40+
// className={clsx({
41+
// 'str-chat__emoji-item--highlight': matches,
42+
// 'str-chat__emoji-item--part': !matches,
43+
// })}
44+
// key={`part-${i}`}
45+
// >
46+
// {part}
47+
// </span>
48+
// );
49+
// });
3750

38-
return (
39-
<span
40-
className={clsx({
41-
'str-chat__emoji-item--highlight': matches,
42-
'str-chat__emoji-item--part': !matches,
43-
})}
44-
key={`part-${i}`}
45-
>
46-
{part}
47-
</span>
48-
);
49-
});
51+
return (
52+
<span
53+
className={clsx({
54+
'str-chat__emoji-item--part': true,
55+
})}
56+
>
57+
{/* FIXME: temporal adjustment so that the component can be rendered */}
58+
{entity.name ?? entity.id}
59+
</span>
60+
);
5061
};
5162

5263
return (

0 commit comments

Comments
 (0)