Skip to content

Commit a48cf67

Browse files
Initial draft
1 parent e81fc69 commit a48cf67

File tree

191 files changed

+1956
-3660
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

191 files changed

+1956
-3660
lines changed

src/components/AIStateIndicator/AIStateIndicator.tsx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,16 @@ import { Channel } from 'stream-chat';
55
import { AIStates, useAIState } from './hooks/useAIState';
66

77
import { useChannelStateContext, useTranslationContext } from '../../context';
8-
import type { DefaultStreamChatGenerics } from '../../types/types';
98

10-
export type AIStateIndicatorProps<
11-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
12-
> = {
13-
channel?: Channel<StreamChatGenerics>;
9+
export type AIStateIndicatorProps = {
10+
channel?: Channel;
1411
};
1512

16-
export const AIStateIndicator = <
17-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
18-
>({
13+
export const AIStateIndicator = ({
1914
channel: channelFromProps,
20-
}: AIStateIndicatorProps<StreamChatGenerics>) => {
15+
}: AIStateIndicatorProps) => {
2116
const { t } = useTranslationContext();
22-
const { channel: channelFromContext } =
23-
useChannelStateContext<StreamChatGenerics>('AIStateIndicator');
17+
const { channel: channelFromContext } = useChannelStateContext('AIStateIndicator');
2418
const channel = channelFromProps || channelFromContext;
2519
const { aiState } = useAIState(channel);
2620
const allowedStates = {

src/components/AIStateIndicator/hooks/useAIState.ts

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import { useEffect, useState } from 'react';
22

33
import { AIState, Channel, Event } from 'stream-chat';
44

5-
import type { DefaultStreamChatGenerics } from '../../../types/types';
6-
75
export const AIStates = {
86
Error: 'AI_STATE_ERROR',
97
ExternalSources: 'AI_STATE_EXTERNAL_SOURCES',
@@ -17,28 +15,21 @@ export const AIStates = {
1715
* @param {Channel} channel - The channel for which we want to know the AI state.
1816
* @returns {{ aiState: AIState }} The current AI state for the given channel.
1917
*/
20-
export const useAIState = <
21-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
22-
>(
23-
channel?: Channel<StreamChatGenerics>,
24-
): { aiState: AIState } => {
18+
export const useAIState = (channel?: Channel): { aiState: AIState } => {
2519
const [aiState, setAiState] = useState<AIState>(AIStates.Idle);
2620

2721
useEffect(() => {
2822
if (!channel) {
2923
return;
3024
}
3125

32-
const indicatorChangedListener = channel.on(
33-
'ai_indicator.update',
34-
(event: Event<StreamChatGenerics>) => {
35-
const { cid } = event;
36-
const state = event.ai_state as AIState;
37-
if (channel.cid === cid) {
38-
setAiState(state);
39-
}
40-
},
41-
);
26+
const indicatorChangedListener = channel.on('ai_indicator.update', (event: Event) => {
27+
const { cid } = event;
28+
const state = event.ai_state as AIState;
29+
if (channel.cid === cid) {
30+
setAiState(state);
31+
}
32+
});
4233

4334
const indicatorClearedListener = channel.on('ai_indicator.clear', (event) => {
4435
const { cid } = event;

src/components/Attachment/Attachment.tsx

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ import type { GalleryProps, ImageProps } from '../Gallery';
3232
import type { UnsupportedAttachmentProps } from './UnsupportedAttachment';
3333
import type { ActionHandlerReturnType } from '../Message/hooks/useActionHandler';
3434

35-
import type { DefaultStreamChatGenerics } from '../../types/types';
36-
3735
const CONTAINER_MAP = {
3836
audio: AudioContainer,
3937
card: CardContainer,
@@ -54,23 +52,21 @@ export const ATTACHMENT_GROUPS_ORDER = [
5452
'unsupported',
5553
] as const;
5654

57-
export type AttachmentProps<
58-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
59-
> = {
55+
export type AttachmentProps = {
6056
/** The message attachments to render, see [attachment structure](https://getstream.io/chat/docs/javascript/message_format/?language=javascript) **/
61-
attachments: StreamAttachment<StreamChatGenerics>[];
57+
attachments: StreamAttachment[];
6258
/** The handler function to call when an action is performed on an attachment, examples include canceling a \/giphy command or shuffling the results. */
6359
actionHandler?: ActionHandlerReturnType;
6460
/** Custom UI component for displaying attachment actions, defaults to and accepts same props as: [AttachmentActions](https://github.com/GetStream/stream-chat-react/blob/master/src/components/Attachment/AttachmentActions.tsx) */
65-
AttachmentActions?: React.ComponentType<AttachmentActionsProps<StreamChatGenerics>>;
61+
AttachmentActions?: React.ComponentType<AttachmentActionsProps>;
6662
/** Custom UI component for displaying an audio type attachment, defaults to and accepts same props as: [Audio](https://github.com/GetStream/stream-chat-react/blob/master/src/components/Attachment/Audio.tsx) */
67-
Audio?: React.ComponentType<AudioProps<StreamChatGenerics>>;
63+
Audio?: React.ComponentType<AudioProps>;
6864
/** Custom UI component for displaying a card type attachment, defaults to and accepts same props as: [Card](https://github.com/GetStream/stream-chat-react/blob/master/src/components/Attachment/Card.tsx) */
6965
Card?: React.ComponentType<CardProps>;
7066
/** Custom UI component for displaying a file type attachment, defaults to and accepts same props as: [File](https://github.com/GetStream/stream-chat-react/blob/master/src/components/Attachment/FileAttachment.tsx) */
71-
File?: React.ComponentType<FileAttachmentProps<StreamChatGenerics>>;
67+
File?: React.ComponentType<FileAttachmentProps>;
7268
/** Custom UI component for displaying a gallery of image type attachments, defaults to and accepts same props as: [Gallery](https://github.com/GetStream/stream-chat-react/blob/master/src/components/Gallery/Gallery.tsx) */
73-
Gallery?: React.ComponentType<GalleryProps<StreamChatGenerics>>;
69+
Gallery?: React.ComponentType<GalleryProps>;
7470
/** Custom UI component for displaying an image type attachment, defaults to and accepts same props as: [Image](https://github.com/GetStream/stream-chat-react/blob/master/src/components/Gallery/Image.tsx) */
7571
Image?: React.ComponentType<ImageProps>;
7672
/** Optional flag to signal that an attachment is a displayed as a part of a quoted message */
@@ -80,17 +76,13 @@ export type AttachmentProps<
8076
/** Custom UI component for displaying unsupported attachment types, defaults to NullComponent */
8177
UnsupportedAttachment?: React.ComponentType<UnsupportedAttachmentProps>;
8278
/** Custom UI component for displaying an audio recording attachment, defaults to and accepts same props as: [VoiceRecording](https://github.com/GetStream/stream-chat-react/blob/master/src/components/Attachment/VoiceRecording.tsx) */
83-
VoiceRecording?: React.ComponentType<VoiceRecordingProps<StreamChatGenerics>>;
79+
VoiceRecording?: React.ComponentType<VoiceRecordingProps>;
8480
};
8581

8682
/**
8783
* A component used for rendering message attachments. By default, the component supports: AttachmentActions, Audio, Card, File, Gallery, Image, and Video
8884
*/
89-
export const Attachment = <
90-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
91-
>(
92-
props: AttachmentProps<StreamChatGenerics>,
93-
) => {
85+
export const Attachment = (props: AttachmentProps) => {
9486
const { attachments } = props;
9587

9688
const groupedAttachments = useMemo(
@@ -109,14 +101,12 @@ export const Attachment = <
109101
);
110102
};
111103

112-
const renderGroupedAttachments = <
113-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
114-
>({
104+
const renderGroupedAttachments = ({
115105
attachments,
116106
...rest
117-
}: AttachmentProps<StreamChatGenerics>): GroupedRenderedAttachment => {
118-
const uploadedImages: StreamAttachment<StreamChatGenerics>[] = attachments.filter(
119-
(attachment) => isUploadedImage(attachment),
107+
}: AttachmentProps): GroupedRenderedAttachment => {
108+
const uploadedImages: StreamAttachment[] = attachments.filter((attachment) =>
109+
isUploadedImage(attachment),
120110
);
121111

122112
const containers = attachments
@@ -171,10 +161,8 @@ const renderGroupedAttachments = <
171161
return containers;
172162
};
173163

174-
const getAttachmentType = <
175-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
176-
>(
177-
attachment: AttachmentProps<StreamChatGenerics>['attachments'][number],
164+
const getAttachmentType = (
165+
attachment: AttachmentProps['attachments'][number],
178166
): keyof typeof CONTAINER_MAP => {
179167
if (isScrapedContent(attachment)) {
180168
return 'card';

src/components/Attachment/AttachmentActions.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@ import type { Action, Attachment } from 'stream-chat';
44
import { useTranslationContext } from '../../context';
55

66
import type { ActionHandlerReturnType } from '../Message/hooks/useActionHandler';
7-
import type { DefaultStreamChatGenerics } from '../../types/types';
87

9-
export type AttachmentActionsProps<
10-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
11-
> = Attachment<StreamChatGenerics> & {
8+
export type AttachmentActionsProps = Attachment & {
129
/** A list of actions */
1310
actions: Action[];
1411
/** Unique id for action button key. Key is generated by concatenating this id with action value - {`${id}-${action.value}`} */
@@ -19,11 +16,7 @@ export type AttachmentActionsProps<
1916
actionHandler?: ActionHandlerReturnType;
2017
};
2118

22-
const UnMemoizedAttachmentActions = <
23-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
24-
>(
25-
props: AttachmentActionsProps<StreamChatGenerics>,
26-
) => {
19+
const UnMemoizedAttachmentActions = (props: AttachmentActionsProps) => {
2720
const { actionHandler, actions, id, text } = props;
2821
const { t } = useTranslationContext('UnMemoizedAttachmentActions');
2922

src/components/Attachment/AttachmentContainer.tsx

Lines changed: 21 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,21 @@ import {
2323
import { useChannelStateContext } from '../../context/ChannelStateContext';
2424

2525
import type {
26-
DefaultStreamChatGenerics,
2726
ImageAttachmentConfiguration,
2827
VideoAttachmentConfiguration,
2928
} from '../../types/types';
3029
import type { Attachment } from 'stream-chat';
30+
import { LocalAttachment } from '../MessageInput';
3131

32-
export type AttachmentContainerProps<
33-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
34-
> = {
35-
attachment: Attachment<StreamChatGenerics> | GalleryAttachment<StreamChatGenerics>;
32+
export type AttachmentContainerProps = {
33+
attachment: Attachment | GalleryAttachment;
3634
componentType: AttachmentComponentType;
3735
};
38-
export const AttachmentWithinContainer = <
39-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
40-
>({
36+
export const AttachmentWithinContainer = ({
4137
attachment,
4238
children,
4339
componentType,
44-
}: PropsWithChildren<AttachmentContainerProps<StreamChatGenerics>>) => {
40+
}: PropsWithChildren<AttachmentContainerProps>) => {
4541
const isGAT = isGalleryAttachmentType(attachment);
4642
let extra = '';
4743

@@ -69,21 +65,19 @@ export const AttachmentWithinContainer = <
6965
return <div className={classNames}>{children}</div>;
7066
};
7167

72-
export const AttachmentActionsContainer = <
73-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
74-
>({
68+
export const AttachmentActionsContainer = ({
7569
actionHandler,
7670
attachment,
7771
AttachmentActions = DefaultAttachmentActions,
78-
}: RenderAttachmentProps<StreamChatGenerics>) => {
72+
}: RenderAttachmentProps) => {
7973
if (!attachment.actions?.length) return null;
8074

8175
return (
8276
<AttachmentActions
8377
{...attachment}
8478
actionHandler={actionHandler}
8579
actions={attachment.actions}
86-
id={attachment.id || ''}
80+
id={(attachment as LocalAttachment).localMetadata?.id || ''}
8781
text={attachment.text || ''}
8882
/>
8983
);
@@ -108,12 +102,10 @@ function getCssDimensionsVariables(url: string) {
108102
return cssVars;
109103
}
110104

111-
export const GalleryContainer = <
112-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
113-
>({
105+
export const GalleryContainer = ({
114106
attachment,
115107
Gallery = DefaultGallery,
116-
}: RenderGalleryProps<StreamChatGenerics>) => {
108+
}: RenderGalleryProps) => {
117109
const imageElements = useRef<HTMLElement[]>([]);
118110
const { imageAttachmentSizeHandler } = useChannelStateContext();
119111
const [attachmentConfigurations, setAttachmentConfigurations] = useState<
@@ -150,11 +142,7 @@ export const GalleryContainer = <
150142
);
151143
};
152144

153-
export const ImageContainer = <
154-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
155-
>(
156-
props: RenderAttachmentProps<StreamChatGenerics>,
157-
) => {
145+
export const ImageContainer = (props: RenderAttachmentProps) => {
158146
const { attachment, Image = DefaultImage } = props;
159147
const componentType = 'image';
160148
const imageElement = useRef<HTMLImageElement>(null);
@@ -194,11 +182,7 @@ export const ImageContainer = <
194182
);
195183
};
196184

197-
export const CardContainer = <
198-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
199-
>(
200-
props: RenderAttachmentProps<StreamChatGenerics>,
201-
) => {
185+
export const CardContainer = (props: RenderAttachmentProps) => {
202186
const { attachment, Card = DefaultCard } = props;
203187
const componentType = 'card';
204188

@@ -220,12 +204,10 @@ export const CardContainer = <
220204
);
221205
};
222206

223-
export const FileContainer = <
224-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
225-
>({
207+
export const FileContainer = ({
226208
attachment,
227209
File = DefaultFile,
228-
}: RenderAttachmentProps<StreamChatGenerics>) => {
210+
}: RenderAttachmentProps) => {
229211
if (!attachment.asset_url) return null;
230212

231213
return (
@@ -234,38 +216,30 @@ export const FileContainer = <
234216
</AttachmentWithinContainer>
235217
);
236218
};
237-
export const AudioContainer = <
238-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
239-
>({
219+
export const AudioContainer = ({
240220
attachment,
241221
Audio = DefaultAudio,
242-
}: RenderAttachmentProps<StreamChatGenerics>) => (
222+
}: RenderAttachmentProps) => (
243223
<AttachmentWithinContainer attachment={attachment} componentType='audio'>
244224
<div className='str-chat__attachment'>
245225
<Audio og={attachment} />
246226
</div>
247227
</AttachmentWithinContainer>
248228
);
249229

250-
export const VoiceRecordingContainer = <
251-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
252-
>({
230+
export const VoiceRecordingContainer = ({
253231
attachment,
254232
isQuoted,
255233
VoiceRecording = DefaultVoiceRecording,
256-
}: RenderAttachmentProps<StreamChatGenerics>) => (
234+
}: RenderAttachmentProps) => (
257235
<AttachmentWithinContainer attachment={attachment} componentType='voiceRecording'>
258236
<div className='str-chat__attachment'>
259237
<VoiceRecording attachment={attachment} isQuoted={isQuoted} />
260238
</div>
261239
</AttachmentWithinContainer>
262240
);
263241

264-
export const MediaContainer = <
265-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
266-
>(
267-
props: RenderAttachmentProps<StreamChatGenerics>,
268-
) => {
242+
export const MediaContainer = (props: RenderAttachmentProps) => {
269243
const { attachment, Media = ReactPlayer } = props;
270244
const componentType = 'media';
271245
const { shouldGenerateVideoThumbnail, videoAttachmentSizeHandler } =
@@ -318,12 +292,10 @@ export const MediaContainer = <
318292
);
319293
};
320294

321-
export const UnsupportedAttachmentContainer = <
322-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
323-
>({
295+
export const UnsupportedAttachmentContainer = ({
324296
attachment,
325297
UnsupportedAttachment = DefaultUnsupportedAttachment,
326-
}: RenderAttachmentProps<StreamChatGenerics>) => (
298+
}: RenderAttachmentProps) => (
327299
<>
328300
<UnsupportedAttachment attachment={attachment} />
329301
</>

src/components/Attachment/Audio.tsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,12 @@ import type { Attachment } from 'stream-chat';
55
import { DownloadButton, FileSizeIndicator, PlayButton, ProgressBar } from './components';
66
import { useAudioController } from './hooks/useAudioController';
77

8-
import type { DefaultStreamChatGenerics } from '../../types/types';
9-
10-
export type AudioProps<
11-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
12-
> = {
8+
export type AudioProps = {
139
// fixme: rename og to attachment
14-
og: Attachment<StreamChatGenerics>;
10+
og: Attachment;
1511
};
1612

17-
const UnMemoizedAudio = <
18-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
19-
>(
20-
props: AudioProps<StreamChatGenerics>,
21-
) => {
13+
const UnMemoizedAudio = (props: AudioProps) => {
2214
const {
2315
og: { asset_url, file_size, mime_type, title },
2416
} = props;

0 commit comments

Comments
 (0)