Skip to content

Commit f7151ac

Browse files
committed
fix: file unsupported types
1 parent 05629c0 commit f7151ac

File tree

9 files changed

+75
-173
lines changed

9 files changed

+75
-173
lines changed

package/src/components/Channel/Channel.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ import { AttachmentUploadProgressIndicator as AttachmentUploadProgressIndicatorD
150150
import { AudioAttachmentUploadPreview as AudioAttachmentUploadPreviewDefault } from '../MessageInput/components/AttachmentPreview/AudioAttachmentUploadPreview';
151151
import { FileAttachmentUploadPreview as FileAttachmentUploadPreviewDefault } from '../MessageInput/components/AttachmentPreview/FileAttachmentUploadPreview';
152152
import { ImageAttachmentUploadPreview as ImageAttachmentUploadPreviewDefault } from '../MessageInput/components/AttachmentPreview/ImageAttachmentUploadPreview';
153-
import { VideoAttachmentUploadPreview as VideoAttachmentUploadPreviewDefault } from '../MessageInput/components/AttachmentPreview/VideoAttachmentUploadPreview';
154153
import { AudioRecorder as AudioRecorderDefault } from '../MessageInput/components/AudioRecorder/AudioRecorder';
155154
import { AudioRecordingButton as AudioRecordingButtonDefault } from '../MessageInput/components/AudioRecorder/AudioRecordingButton';
156155
import { AudioRecordingInProgress as AudioRecordingInProgressDefault } from '../MessageInput/components/AudioRecorder/AudioRecordingInProgress';
@@ -652,7 +651,7 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
652651
UnreadMessagesNotification = UnreadMessagesNotificationDefault,
653652
AttachmentUploadProgressIndicator = AttachmentUploadProgressIndicatorDefault,
654653
UrlPreview = CardDefault,
655-
VideoAttachmentUploadPreview = VideoAttachmentUploadPreviewDefault,
654+
VideoAttachmentUploadPreview = FileAttachmentUploadPreviewDefault,
656655
VideoThumbnail = VideoThumbnailDefault,
657656
} = props;
658657

package/src/components/MessageInput/FileUploadPreview.tsx

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ import {
88
isLocalImageAttachment,
99
isLocalVideoAttachment,
1010
isLocalVoiceRecordingAttachment,
11+
isVideoAttachment,
1112
isVoiceRecordingAttachment,
1213
LocalAudioAttachment,
1314
LocalFileAttachment,
15+
LocalVideoAttachment,
1416
LocalVoiceRecordingAttachment,
1517
} from 'stream-chat';
1618

@@ -28,20 +30,25 @@ const FILE_PREVIEW_HEIGHT = 60;
2830

2931
export type FileUploadPreviewPropsWithContext = Pick<
3032
MessageInputContextValue,
31-
'AudioAttachmentUploadPreview' | 'FileAttachmentUploadPreview'
33+
'AudioAttachmentUploadPreview' | 'FileAttachmentUploadPreview' | 'VideoAttachmentUploadPreview'
3234
>;
3335

3436
type FileAttachmentType<CustomLocalMetadata = Record<string, unknown>> =
3537
| LocalFileAttachment<CustomLocalMetadata>
3638
| LocalAudioAttachment<CustomLocalMetadata>
37-
| LocalVoiceRecordingAttachment<CustomLocalMetadata>;
39+
| LocalVoiceRecordingAttachment<CustomLocalMetadata>
40+
| LocalVideoAttachment<CustomLocalMetadata>;
3841

3942
/**
4043
* FileUploadPreview
4144
* UI Component to preview the files set for upload
4245
*/
4346
const UnMemoizedFileUploadPreview = (props: FileUploadPreviewPropsWithContext) => {
44-
const { AudioAttachmentUploadPreview, FileAttachmentUploadPreview } = props;
47+
const {
48+
AudioAttachmentUploadPreview,
49+
FileAttachmentUploadPreview,
50+
VideoAttachmentUploadPreview,
51+
} = props;
4552
const { attachmentManager } = useMessageComposer();
4653
const { attachments } = useAttachmentManagerState();
4754
const [audioAttachmentsStateMap, setAudioAttachmentsStateMap] = useState<
@@ -54,8 +61,9 @@ const UnMemoizedFileUploadPreview = (props: FileUploadPreviewPropsWithContext) =
5461
return attachments.filter(
5562
(attachment) =>
5663
isLocalFileAttachment(attachment) ||
57-
isAudioAttachment(attachment) ||
58-
isVoiceRecordingAttachment(attachment),
64+
isLocalFileAttachment(attachment) ||
65+
isLocalVoiceRecordingAttachment(attachment) ||
66+
isLocalVideoAttachment(attachment),
5967
);
6068
}, [attachments]);
6169

@@ -143,7 +151,7 @@ const UnMemoizedFileUploadPreview = (props: FileUploadPreviewPropsWithContext) =
143151

144152
const renderItem = useCallback(
145153
({ item }: { item: FileAttachmentType }) => {
146-
if (isLocalImageAttachment(item) || isLocalVideoAttachment(item)) {
154+
if (isLocalImageAttachment(item)) {
147155
// This is already handled in the `ImageUploadPreview` component
148156
return null;
149157
} else if (isLocalVoiceRecordingAttachment(item)) {
@@ -181,6 +189,15 @@ const UnMemoizedFileUploadPreview = (props: FileUploadPreviewPropsWithContext) =
181189
/>
182190
);
183191
}
192+
} else if (isVideoAttachment(item)) {
193+
return (
194+
<VideoAttachmentUploadPreview
195+
attachment={item}
196+
flatListWidth={flatListWidth}
197+
handleRetry={attachmentManager.uploadAttachment}
198+
removeAttachments={attachmentManager.removeAttachments}
199+
/>
200+
);
184201
} else if (isLocalFileAttachment(item)) {
185202
return (
186203
<FileAttachmentUploadPreview
@@ -195,6 +212,7 @@ const UnMemoizedFileUploadPreview = (props: FileUploadPreviewPropsWithContext) =
195212
[
196213
AudioAttachmentUploadPreview,
197214
FileAttachmentUploadPreview,
215+
VideoAttachmentUploadPreview,
198216
attachmentManager.removeAttachments,
199217
attachmentManager.uploadAttachment,
200218
audioAttachmentsStateMap,
@@ -250,12 +268,17 @@ const MemoizedFileUploadPreviewWithContext = React.memo(UnMemoizedFileUploadPrev
250268
* UI Component to preview the files set for upload
251269
*/
252270
export const FileUploadPreview = (props: FileUploadPreviewProps) => {
253-
const { AudioAttachmentUploadPreview, FileAttachmentUploadPreview } = useMessageInputContext();
271+
const {
272+
AudioAttachmentUploadPreview,
273+
FileAttachmentUploadPreview,
274+
VideoAttachmentUploadPreview,
275+
} = useMessageInputContext();
254276
return (
255277
<MemoizedFileUploadPreviewWithContext
256278
{...{
257279
AudioAttachmentUploadPreview,
258280
FileAttachmentUploadPreview,
281+
VideoAttachmentUploadPreview,
259282
}}
260283
{...props}
261284
/>

package/src/components/MessageInput/ImageUploadPreview.tsx

Lines changed: 15 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
import React, { useCallback } from 'react';
22
import { FlatList, StyleSheet } from 'react-native';
33

4-
import {
5-
isLocalImageAttachment,
6-
isLocalVideoAttachment,
7-
LocalImageAttachment,
8-
LocalVideoAttachment,
9-
} from 'stream-chat';
4+
import { isLocalImageAttachment, LocalImageAttachment } from 'stream-chat';
105

116
import {
127
MessageInputContextValue,
@@ -20,25 +15,24 @@ const IMAGE_PREVIEW_SIZE = 100;
2015

2116
export type ImageUploadPreviewPropsWithContext = Pick<
2217
MessageInputContextValue,
23-
'ImageAttachmentUploadPreview' | 'VideoAttachmentUploadPreview'
18+
'ImageAttachmentUploadPreview'
2419
>;
2520

2621
export type ImageAttachmentPreview<CustomLocalMetadata = Record<string, unknown>> =
27-
| LocalImageAttachment<CustomLocalMetadata>
28-
| LocalVideoAttachment<CustomLocalMetadata>;
22+
LocalImageAttachment<CustomLocalMetadata>;
2923

3024
type ImageUploadPreviewItem = { index: number; item: ImageAttachmentPreview };
3125

3226
/**
3327
* UI Component to preview the images set for upload
3428
*/
3529
const UnmemoizedImageUploadPreview = (props: ImageUploadPreviewPropsWithContext) => {
36-
const { ImageAttachmentUploadPreview, VideoAttachmentUploadPreview } = props;
30+
const { ImageAttachmentUploadPreview } = props;
3731
const { attachmentManager } = useMessageComposer();
3832
const { attachments } = useAttachmentManagerState();
3933

40-
const imageOrVideoUploads = attachments.filter(
41-
(attachment) => isLocalImageAttachment(attachment) || isLocalVideoAttachment(attachment),
34+
const imageOrVideoUploads = attachments.filter((attachment) =>
35+
isLocalImageAttachment(attachment),
4236
);
4337

4438
const {
@@ -51,27 +45,16 @@ const UnmemoizedImageUploadPreview = (props: ImageUploadPreviewPropsWithContext)
5145

5246
const renderItem = useCallback(
5347
({ item }: ImageUploadPreviewItem) => {
54-
if (isLocalImageAttachment(item)) {
55-
return (
56-
<ImageAttachmentUploadPreview
57-
attachment={item}
58-
handleRetry={attachmentManager.uploadAttachment}
59-
removeAttachments={attachmentManager.removeAttachments}
60-
/>
61-
);
62-
} else {
63-
return (
64-
<VideoAttachmentUploadPreview
65-
attachment={item}
66-
handleRetry={attachmentManager.uploadAttachment}
67-
removeAttachments={attachmentManager.removeAttachments}
68-
/>
69-
);
70-
}
48+
return (
49+
<ImageAttachmentUploadPreview
50+
attachment={item}
51+
handleRetry={attachmentManager.uploadAttachment}
52+
removeAttachments={attachmentManager.removeAttachments}
53+
/>
54+
);
7155
},
7256
[
7357
ImageAttachmentUploadPreview,
74-
VideoAttachmentUploadPreview,
7558
attachmentManager.removeAttachments,
7659
attachmentManager.uploadAttachment,
7760
],
@@ -105,13 +88,8 @@ export type ImageUploadPreviewProps = Partial<ImageUploadPreviewPropsWithContext
10588
* UI Component to preview the images set for upload
10689
*/
10790
export const ImageUploadPreview = (props: ImageUploadPreviewProps) => {
108-
const { ImageAttachmentUploadPreview, VideoAttachmentUploadPreview } = useMessageInputContext();
109-
return (
110-
<MemoizedImageUploadPreviewWithContext
111-
{...{ ImageAttachmentUploadPreview, VideoAttachmentUploadPreview }}
112-
{...props}
113-
/>
114-
);
91+
const { ImageAttachmentUploadPreview } = useMessageInputContext();
92+
return <MemoizedImageUploadPreviewWithContext {...{ ImageAttachmentUploadPreview }} {...props} />;
11593
};
11694

11795
const styles = StyleSheet.create({

package/src/components/MessageInput/components/AttachmentPreview/AttachmentUnsupportedIndicator.tsx

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,19 @@ const WARNING_ICON_SIZE = 16;
1111
export type AttachmentUnsupportedIndicatorProps = {
1212
/** Type of active indicator */
1313
indicatorType?: Progress;
14+
/** Boolean to determine whether the attachment is an image */
15+
isImage?: boolean;
1416
};
1517

1618
export const AttachmentUnsupportedIndicator = ({
1719
indicatorType,
20+
isImage = false,
1821
}: AttachmentUnsupportedIndicatorProps) => {
1922
const {
2023
theme: {
21-
colors: { accent_red, overlay, white },
24+
colors: { accent_red, grey_dark, overlay, white },
2225
messageInput: {
23-
attachmentUnsupportedIndicator: { container, text, warningIcon, wrapper },
26+
attachmentUnsupportedIndicator: { container, text, warningIcon },
2427
},
2528
},
2629
} = useTheme();
@@ -32,34 +35,37 @@ export const AttachmentUnsupportedIndicator = ({
3235
}
3336

3437
return (
35-
<View style={[styles.unsupportedImageWrapper, { backgroundColor: overlay }, wrapper]}>
36-
<View style={[styles.iconContainer, container]}>
37-
<Warning
38-
height={WARNING_ICON_SIZE}
39-
pathFill={accent_red}
40-
style={styles.warningIconStyle}
41-
width={WARNING_ICON_SIZE}
42-
{...warningIcon}
43-
/>
44-
<Text style={[styles.warningText, { color: white }, text]}>
45-
{t<string>('Not supported')}
46-
</Text>
47-
</View>
38+
<View
39+
style={[
40+
styles.container,
41+
isImage ? [styles.imageStyle, { backgroundColor: overlay }] : null,
42+
container,
43+
]}
44+
>
45+
<Warning
46+
height={WARNING_ICON_SIZE}
47+
pathFill={accent_red}
48+
style={styles.warningIconStyle}
49+
width={WARNING_ICON_SIZE}
50+
{...warningIcon}
51+
/>
52+
<Text style={[styles.warningText, { color: isImage ? white : grey_dark }, text]}>
53+
{t<string>('Not supported')}
54+
</Text>
4855
</View>
4956
);
5057
};
5158

5259
const styles = StyleSheet.create({
53-
iconContainer: {
60+
container: {
5461
alignItems: 'center',
5562
flexDirection: 'row',
56-
justifyContent: 'center',
63+
marginTop: 4,
64+
paddingHorizontal: 4,
5765
},
58-
unsupportedImageWrapper: {
59-
borderRadius: 20,
66+
imageStyle: {
67+
borderRadius: 16,
6068
bottom: 8,
61-
flexDirection: 'row',
62-
marginHorizontal: 3,
6369
position: 'absolute',
6470
},
6571
warningIconStyle: {

package/src/components/MessageInput/components/AttachmentPreview/ImageAttachmentUploadPreview.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export const ImageAttachmentUploadPreview = ({
6060
</AttachmentUploadProgressIndicator>
6161
<DismissAttachmentUpload onPress={onDismissHandler} />
6262
{indicatorType === ProgressIndicatorTypes.NOT_SUPPORTED ? (
63-
<AttachmentUnsupportedIndicator indicatorType={indicatorType} />
63+
<AttachmentUnsupportedIndicator indicatorType={indicatorType} isImage={true} />
6464
) : null}
6565
</View>
6666
);

0 commit comments

Comments
 (0)