Skip to content

Commit 80f908c

Browse files
committed
refactor: remove unused code related to useMessageInputState
1 parent 1f4cdd5 commit 80f908c

30 files changed

+179
-1251
lines changed

src/components/Attachment/AttachmentContainer.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React, { useLayoutEffect, useRef, useState } from 'react';
33
import ReactPlayer from 'react-player';
44
import clsx from 'clsx';
55
import * as linkify from 'linkifyjs';
6-
import type { Attachment } from 'stream-chat';
6+
import type { Attachment, LocalAttachment } from 'stream-chat';
77

88
import { AttachmentActions as DefaultAttachmentActions } from './AttachmentActions';
99
import { Audio as DefaultAudio } from './Audio';
@@ -20,7 +20,6 @@ import type {
2020
} from './utils';
2121
import { isGalleryAttachmentType, isSvgAttachment } from './utils';
2222
import { useChannelStateContext } from '../../context/ChannelStateContext';
23-
import type { LocalAttachment } from '../MessageInput';
2423
import type {
2524
ImageAttachmentConfiguration,
2625
VideoAttachmentConfiguration,

src/components/Attachment/utils.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import type {
88
VoiceRecordingAttachment,
99
} from 'stream-chat';
1010

11+
import type { LocalFileAttachment, LocalVideoAttachment } from 'stream-chat';
1112
import type { ATTACHMENT_GROUPS_ORDER, AttachmentProps } from './Attachment';
12-
import type { LocalFileAttachment, LocalVideoAttachment } from '../MessageInput';
1313

1414
export const SUPPORTED_VIDEO_FORMATS = [
1515
'video/mp4',

src/components/Channel/Channel.tsx

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ import {
9090
getImageAttachmentConfiguration,
9191
getVideoAttachmentConfiguration,
9292
} from '../Attachment/attachment-sizing';
93-
import type { URLEnrichmentConfig } from '../MessageInput/hooks/useLinkPreviews';
9493
import { useSearchFocusedMessage } from '../../experimental/Search/hooks';
9594

9695
type ChannelPropsForwardedToComponentContext = Pick<
@@ -195,14 +194,6 @@ export type ChannelProps = ChannelPropsForwardedToComponentContext & {
195194
dragAndDropWindow?: boolean;
196195
/** Custom UI component to be shown if no active channel is set, defaults to null and skips rendering the Channel component */
197196
EmptyPlaceholder?: React.ReactElement;
198-
/**
199-
* A global flag to toggle the URL enrichment and link previews in `MessageInput` components.
200-
* By default, the feature is disabled. Can be overridden on Thread, MessageList level through additionalMessageInputProps
201-
* or directly on MessageInput level through urlEnrichmentConfig.
202-
*/
203-
enrichURLForPreview?: URLEnrichmentConfig['enrichURLForPreview'];
204-
/** Global configuration for link preview generation in all the MessageInput components */
205-
enrichURLForPreviewConfig?: Omit<URLEnrichmentConfig, 'enrichURLForPreview'>;
206197
/** The giphy version to render - check the keys of the [Image Object](https://developers.giphy.com/docs/api/schema#image-object) for possible values. Uses 'fixed_height' by default */
207198
giphyVersion?: GiphyVersions;
208199
/** A custom function to provide size configuration for image attachments */
@@ -309,7 +300,6 @@ const ChannelInner = (
309300
doSendMessageRequest,
310301
doUpdateMessageRequest,
311302
dragAndDropWindow = false,
312-
enrichURLForPreviewConfig,
313303
initializeOnMount = true,
314304
LoadingErrorIndicator = DefaultLoadingErrorIndicator,
315305
LoadingIndicator = DefaultLoadingIndicator,
@@ -566,7 +556,8 @@ const ChannelInner = (
566556
}
567557

568558
if (maxNumberOfFiles) {
569-
channel.messageComposer.attachmentManager.maxNumberOfFilesPerMessage =
559+
// todo: this has to be configured via a template
560+
channel.messageComposer.attachmentManager.config.maxNumberOfFilesPerMessage =
570561
maxNumberOfFiles;
571562
}
572563
done = true;
@@ -1166,10 +1157,7 @@ const ChannelInner = (
11661157
channelCapabilitiesArray,
11671158
channelConfig,
11681159
channelUnreadUiState,
1169-
debounceURLEnrichmentMs: enrichURLForPreviewConfig?.debounceURLEnrichmentMs,
11701160
dragAndDropWindow,
1171-
enrichURLForPreview: props.enrichURLForPreview,
1172-
findURLFn: enrichURLForPreviewConfig?.findURLFn,
11731161
giphyVersion: props.giphyVersion || 'fixed_height',
11741162
imageAttachmentSizeHandler:
11751163
props.imageAttachmentSizeHandler || getImageAttachmentConfiguration,
@@ -1178,7 +1166,6 @@ const ChannelInner = (
11781166
multipleUploads,
11791167
mutes,
11801168
notifications,
1181-
onLinkPreviewDismissed: enrichURLForPreviewConfig?.onLinkPreviewDismissed,
11821169
shouldGenerateVideoThumbnail: props.shouldGenerateVideoThumbnail || true,
11831170
videoAttachmentSizeHandler:
11841171
props.videoAttachmentSizeHandler || getVideoAttachmentConfiguration,
@@ -1213,8 +1200,6 @@ const ChannelInner = (
12131200
[
12141201
channel.cid,
12151202
deleteMessage,
1216-
enrichURLForPreviewConfig?.findURLFn,
1217-
enrichURLForPreviewConfig?.onLinkPreviewDismissed,
12181203
loadMore,
12191204
loadMoreNewer,
12201205
markRead,

src/components/Channel/hooks/useCreateChannelStateContext.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,8 @@ export const useCreateChannelStateContext = (
1616
channelCapabilitiesArray = [],
1717
channelConfig,
1818
channelUnreadUiState,
19-
debounceURLEnrichmentMs,
2019
dragAndDropWindow,
21-
enrichURLForPreview,
2220
error,
23-
findURLFn,
2421
giphyVersion,
2522
hasMore,
2623
hasMoreNewer,
@@ -36,7 +33,6 @@ export const useCreateChannelStateContext = (
3633
multipleUploads,
3734
mutes,
3835
notifications,
39-
onLinkPreviewDismissed,
4036
pinnedMessages,
4137
read = {},
4238
shouldGenerateVideoThumbnail,
@@ -112,11 +108,8 @@ export const useCreateChannelStateContext = (
112108
channelCapabilities,
113109
channelConfig,
114110
channelUnreadUiState,
115-
debounceURLEnrichmentMs,
116111
dragAndDropWindow,
117-
enrichURLForPreview,
118112
error,
119-
findURLFn,
120113
giphyVersion,
121114
hasMore,
122115
hasMoreNewer,
@@ -132,7 +125,6 @@ export const useCreateChannelStateContext = (
132125
multipleUploads,
133126
mutes,
134127
notifications,
135-
onLinkPreviewDismissed,
136128
pinnedMessages,
137129
read,
138130
shouldGenerateVideoThumbnail,
@@ -151,10 +143,7 @@ export const useCreateChannelStateContext = (
151143
channel.data?.name, // otherwise ChannelHeader will not be updated
152144
channelId,
153145
channelUnreadUiState,
154-
debounceURLEnrichmentMs,
155-
enrichURLForPreview,
156146
error,
157-
findURLFn,
158147
hasMore,
159148
hasMoreNewer,
160149
highlightedMessageId,
@@ -167,7 +156,6 @@ export const useCreateChannelStateContext = (
167156
messageDraft,
168157
messageDraftsEnabled,
169158
notificationsLength,
170-
onLinkPreviewDismissed,
171159
readUsersLength,
172160
readUsersLastReads,
173161
shouldGenerateVideoThumbnail,

src/components/MediaRecorder/AudioRecorder/AudioRecordingInProgress.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useEffect, useState } from 'react';
2-
import { useTimeElapsed } from '../../MessageInput/hooks/useTimeElapsed';
2+
import { useTimeElapsed } from './hooks/useTimeElapsed';
33
import { useMessageInputContext } from '../../../context';
44
import { RecordingTimer } from './RecordingTimer';
55

src/components/MessageInput/hooks/useTimeElapsed.ts renamed to src/components/MediaRecorder/AudioRecorder/hooks/useTimeElapsed.ts

File renamed without changes.

src/components/MessageInput/AttachmentPreviewList/AttachmentPreviewList.tsx

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,17 @@ import {
99
isLocalVoiceRecordingAttachment,
1010
isScrapedContent,
1111
} from 'stream-chat';
12+
import type { UnsupportedAttachmentPreviewProps } from './UnsupportedAttachmentPreview';
1213
import { UnsupportedAttachmentPreview as DefaultUnknownAttachmentPreview } from './UnsupportedAttachmentPreview';
1314
import { VoiceRecordingPreview as DefaultVoiceRecordingPreview } from './VoiceRecordingPreview';
1415
import { FileAttachmentPreview as DefaultFilePreview } from './FileAttachmentPreview';
1516
import { ImageAttachmentPreview as DefaultImagePreview } from './ImageAttachmentPreview';
1617
import { useMessageComposer } from '../hooks/messageComposer/useMessageComposer';
17-
import { useStateStore } from '../../../store';
18-
19-
import type { AttachmentManagerState } from 'stream-chat';
20-
import type { UnsupportedAttachmentPreviewProps } from './UnsupportedAttachmentPreview';
18+
import { useAttachmentManagerState } from '../hooks/messageComposer/useAttachmentManagerState';
2119
import type { VoiceRecordingPreviewProps } from './VoiceRecordingPreview';
2220
import type { FileAttachmentPreviewProps } from './FileAttachmentPreview';
2321
import type { ImageAttachmentPreviewProps } from './ImageAttachmentPreview';
2422

25-
const attachmentManagerStateSelector = (state: AttachmentManagerState) => ({
26-
attachments: state.attachments,
27-
});
28-
2923
export type AttachmentPreviewListProps = {
3024
AudioAttachmentPreview?: ComponentType<FileAttachmentPreviewProps>;
3125
FileAttachmentPreview?: ComponentType<FileAttachmentPreviewProps>;
@@ -45,10 +39,9 @@ export const AttachmentPreviewList = ({
4539
}: AttachmentPreviewListProps) => {
4640
const messageComposer = useMessageComposer();
4741

48-
const { attachments } = useStateStore(
49-
messageComposer.attachmentManager.state,
50-
attachmentManagerStateSelector,
51-
);
42+
const { attachments, isUploadEnabled } = useAttachmentManagerState();
43+
44+
if (!isUploadEnabled || !attachments.length) return null;
5245

5346
return (
5447
<div className='str-chat__attachment-preview-list'>

src/components/MessageInput/AttachmentSelector.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
useAttachmentSelectorContext,
2121
} from '../../context/AttachmentSelectorContext';
2222

23-
import { useIsUploadEnabled } from './hooks/messageComposer/useIsUploadEnabled';
23+
import { useAttachmentManagerState } from './hooks/messageComposer/useAttachmentManagerState';
2424

2525
export const SimpleAttachmentSelector = () => {
2626
const {
@@ -94,7 +94,7 @@ export const DefaultAttachmentSelectorComponents = {
9494
File({ closeMenu }: AttachmentSelectorActionProps) {
9595
const { t } = useTranslationContext();
9696
const { fileInput } = useAttachmentSelectorContext();
97-
const { isUploadEnabled } = useIsUploadEnabled();
97+
const { isUploadEnabled } = useAttachmentManagerState();
9898

9999
return (
100100
<DialogMenuButton

src/components/MessageInput/DropzoneProvider.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import type { MessageInputProps } from './MessageInput';
1616

1717
import type { UnknownType } from '../../types/types';
1818
import { useMessageComposer } from './hooks/messageComposer/useMessageComposer';
19-
import { useIsUploadEnabled } from './hooks/messageComposer/useIsUploadEnabled';
19+
import { useAttachmentManagerState } from './hooks/messageComposer/useAttachmentManagerState';
2020

2121
// const attachmentManagerStateSelector = <
2222
//
@@ -29,7 +29,7 @@ const DropzoneInner = ({ children }: PropsWithChildren<UnknownType>) => {
2929

3030
const { cooldownRemaining } = useMessageInputContext('DropzoneProvider');
3131
const messageComposer = useMessageComposer();
32-
const { availableUploadSlots, isUploadEnabled } = useIsUploadEnabled();
32+
const { availableUploadSlots, isUploadEnabled } = useAttachmentManagerState();
3333

3434
return (
3535
<ImageDropzone

src/components/MessageInput/LinkPreviewList.tsx

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,55 @@
11
import clsx from 'clsx';
22
import React, { useState } from 'react';
3-
import { useMessageInputContext } from '../../context';
4-
import type { LinkPreview } from './types';
5-
import { LinkPreviewState } from './types';
6-
import { CloseIcon, LinkIcon } from './icons';
3+
import { LinkPreviewStatus } from 'stream-chat';
4+
import { useStateStore } from '../../store';
75
import { PopperTooltip } from '../Tooltip';
86
import { useEnterLeaveHandlers } from '../Tooltip/hooks';
97
import { useMessageComposer } from './hooks/messageComposer/useMessageComposer';
10-
import { useStateStore } from '../../store';
8+
import { CloseIcon, LinkIcon } from './icons';
119

12-
import type { MessageComposerState } from 'stream-chat';
10+
import type {
11+
LinkPreview,
12+
LinkPreviewsManagerConfig,
13+
LinkPreviewsManagerState,
14+
MessageComposerState,
15+
} from 'stream-chat';
1316

14-
export type LinkPreviewListProps = {
15-
linkPreviews: LinkPreview[];
16-
};
17+
const linkPreviewsManagerStateSelector = (state: LinkPreviewsManagerState) => ({
18+
linkPreviews: Array.from(state.previews.values()),
19+
});
20+
21+
const linkPreviewsManagerConfigStateSelector = (state: LinkPreviewsManagerConfig) => ({
22+
linkPreviewsEnabled: state.enabled,
23+
});
1724

1825
const messageComposerStateSelector = (state: MessageComposerState) => ({
1926
quotedMessage: state.quotedMessage,
2027
});
2128

22-
export const LinkPreviewList = ({ linkPreviews }: LinkPreviewListProps) => {
29+
export const LinkPreviewList = () => {
2330
const messageComposer = useMessageComposer();
31+
const { linkPreviewsManager } = messageComposer;
2432
const { quotedMessage } = useStateStore(
2533
messageComposer.state,
2634
messageComposerStateSelector,
2735
);
28-
const showLinkPreviews = linkPreviews.length > 0 && !quotedMessage;
36+
const { linkPreviews } = useStateStore(
37+
linkPreviewsManager.state,
38+
linkPreviewsManagerStateSelector,
39+
);
40+
const { linkPreviewsEnabled } = useStateStore(
41+
linkPreviewsManager.configState,
42+
linkPreviewsManagerConfigStateSelector,
43+
);
44+
const showLinkPreviews =
45+
linkPreviewsEnabled && linkPreviews.length > 0 && !quotedMessage;
2946

3047
if (!showLinkPreviews) return null;
3148

3249
return (
3350
<div className='str-chat__link-preview-list'>
34-
{Array.from(linkPreviews.values()).map((linkPreview) =>
35-
linkPreview.state === LinkPreviewState.LOADED ? (
51+
{linkPreviews.map((linkPreview) =>
52+
linkPreview.status === LinkPreviewStatus.LOADED ? (
3653
<LinkPreviewCard key={linkPreview.og_scrape_url} linkPreview={linkPreview} />
3754
) : null,
3855
)}
@@ -45,15 +62,14 @@ type LinkPreviewProps = {
4562
};
4663

4764
const LinkPreviewCard = ({ linkPreview }: LinkPreviewProps) => {
48-
const { dismissLinkPreview } = useMessageInputContext();
4965
const { handleEnter, handleLeave, tooltipVisible } =
5066
useEnterLeaveHandlers<HTMLDivElement>();
5167
const [referenceElement, setReferenceElement] = useState<HTMLDivElement | null>(null);
5268
return (
5369
<div
5470
className={clsx('str-chat__link-preview-card', {
5571
'str-chat__link-preview-card--loading':
56-
linkPreview.state === LinkPreviewState.LOADING,
72+
linkPreview.status === LinkPreviewStatus.LOADING,
5773
})}
5874
data-testid='link-preview-card'
5975
>
@@ -83,7 +99,7 @@ const LinkPreviewCard = ({ linkPreview }: LinkPreviewProps) => {
8399
<button
84100
className='str-chat__link-preview-card__dismiss-button'
85101
data-testid='link-preview-card-dismiss-btn'
86-
onClick={() => dismissLinkPreview(linkPreview)}
102+
onClick={linkPreview.dismiss}
87103
>
88104
<CloseIcon />
89105
</button>

0 commit comments

Comments
 (0)