Skip to content

Commit f4136f0

Browse files
committed
refactor: access message composer configuration
1 parent 91996b5 commit f4136f0

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

src/components/MessageInput/LinkPreviewList.tsx

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
import clsx from 'clsx';
22
import React, { useState } from 'react';
3-
import { LinkPreviewStatus } from 'stream-chat';
4-
import { useStateStore } from '../../store';
5-
import { PopperTooltip } from '../Tooltip';
6-
import { useEnterLeaveHandlers } from '../Tooltip/hooks';
7-
import { useMessageComposer } from './hooks/messageComposer/useMessageComposer';
8-
import { CloseIcon, LinkIcon } from './icons';
9-
103
import type {
114
LinkPreview,
12-
LinkPreviewsManagerConfig,
135
LinkPreviewsManagerState,
146
MessageComposerState,
157
} from 'stream-chat';
8+
import { LinkPreviewStatus, type MessageComposerConfig } from 'stream-chat';
9+
import { useStateStore } from '../../store';
10+
import { PopperTooltip } from '../Tooltip';
11+
import { useEnterLeaveHandlers } from '../Tooltip/hooks';
12+
import { useMessageComposer } from './hooks/messageComposer/useMessageComposer';
13+
import { CloseIcon, LinkIcon } from './icons';
1614

1715
const linkPreviewsManagerStateSelector = (state: LinkPreviewsManagerState) => ({
1816
linkPreviews: Array.from(state.previews.values()),
1917
});
2018

21-
const linkPreviewsManagerConfigStateSelector = (state: LinkPreviewsManagerConfig) => ({
22-
linkPreviewsEnabled: state.enabled,
19+
const linkPreviewsManagerConfigStateSelector = (state: MessageComposerConfig) => ({
20+
linkPreviewsEnabled: state.linkPreviews.enabled,
2321
});
2422

2523
const messageComposerStateSelector = (state: MessageComposerState) => ({
@@ -38,7 +36,7 @@ export const LinkPreviewList = () => {
3836
linkPreviewsManagerStateSelector,
3937
);
4038
const { linkPreviewsEnabled } = useStateStore(
41-
linkPreviewsManager.configState,
39+
messageComposer.configState,
4240
linkPreviewsManagerConfigStateSelector,
4341
);
4442
const showLinkPreviews =

src/components/MessageInput/MessageInputFlat.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ import { useTranslationContext } from '../../context/TranslationContext';
3131
import { useMessageInputContext } from '../../context/MessageInputContext';
3232
import { useComponentContext } from '../../context/ComponentContext';
3333
import { useStateStore } from '../../store';
34-
import type { AttachmentManagerConfig } from 'stream-chat';
3534
import { useAttachmentManagerState } from './hooks/messageComposer/useAttachmentManagerState';
3635
import { useMessageContext } from '../../context';
36+
import type { MessageComposerConfig } from 'stream-chat';
3737

38-
const attachmentManagerConfigStateSelector = (state: AttachmentManagerConfig) => ({
39-
maxNumberOfFilesPerMessage: state.maxNumberOfFilesPerMessage,
38+
const attachmentManagerConfigStateSelector = (state: MessageComposerConfig) => ({
39+
maxNumberOfFilesPerMessage: state.attachments.maxNumberOfFilesPerMessage,
4040
});
4141

4242
export const MessageInputFlat = () => {
@@ -66,7 +66,8 @@ export const MessageInputFlat = () => {
6666
} = useComponentContext('MessageInputFlat');
6767
const { acceptedFiles = [] } = useChannelStateContext('MessageInputFlat');
6868
const { channel } = useChatContext('MessageInputFlat');
69-
const { attachmentManager } = useMessageComposer();
69+
const messageComposer = useMessageComposer();
70+
const { attachmentManager } = messageComposer;
7071
const { aiState } = useAIState(channel);
7172

7273
const stopGenerating = useCallback(() => channel?.stopAIResponse(), [channel]);
@@ -90,7 +91,7 @@ export const MessageInputFlat = () => {
9091

9192
const { attachments, isUploadEnabled } = useAttachmentManagerState();
9293
const { maxNumberOfFilesPerMessage } = useStateStore(
93-
attachmentManager.configState,
94+
messageComposer.configState,
9495
attachmentManagerConfigStateSelector,
9596
);
9697

src/components/MessageInput/hooks/useSubmitHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const useSubmitHandler = (props: MessageInputProps) => {
4242
await sendMessage({ localMessage, message, options: sendOptions });
4343
}
4444
messageComposer.clear();
45-
if (messageComposer.config.publishTypingEvents)
45+
if (messageComposer.config.text.publishTypingEvents)
4646
await messageComposer.channel.stopTyping();
4747
} catch (err) {
4848
addNotification(t('Send message request failed'), 'error');

src/components/ReactFileUtilities/UploadButton.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import clsx from 'clsx';
22
import { nanoid } from 'nanoid';
3+
import type { ComponentProps } from 'react';
34
import React, { forwardRef, useCallback, useMemo } from 'react';
45

56
import { useHandleFileChangeWrapper } from './utils';
@@ -11,12 +12,11 @@ import {
1112
import { useMessageComposer } from '../MessageInput/hooks/messageComposer/useMessageComposer';
1213
import { useAttachmentManagerState } from '../MessageInput/hooks/messageComposer/useAttachmentManagerState';
1314
import { useStateStore } from '../../store';
14-
import type { ComponentProps } from 'react';
15-
import type { AttachmentManagerConfig } from 'stream-chat';
15+
import type { MessageComposerConfig } from 'stream-chat';
1616
import type { PartialSelected } from '../../types/types';
1717

18-
const attachmentManagerConfigStateSelector = (state: AttachmentManagerConfig) => ({
19-
maxNumberOfFilesPerMessage: state.maxNumberOfFilesPerMessage,
18+
const attachmentManagerConfigStateSelector = (state: MessageComposerConfig) => ({
19+
maxNumberOfFilesPerMessage: state.attachments.maxNumberOfFilesPerMessage,
2020
});
2121

2222
/**
@@ -55,10 +55,11 @@ export const UploadFileInput = forwardRef(function UploadFileInput(
5555
const { t } = useTranslationContext('UploadFileInput');
5656
const { cooldownRemaining } = useMessageInputContext();
5757
const { acceptedFiles = [] } = useChannelStateContext('UploadFileInput');
58-
const { attachmentManager } = useMessageComposer();
58+
const messageComposer = useMessageComposer();
59+
const { attachmentManager } = messageComposer;
5960
const { isUploadEnabled } = useAttachmentManagerState();
6061
const { maxNumberOfFilesPerMessage } = useStateStore(
61-
attachmentManager.configState,
62+
messageComposer.configState,
6263
attachmentManagerConfigStateSelector,
6364
);
6465
const id = useMemo(() => nanoid(), []);

0 commit comments

Comments
 (0)