Skip to content

Commit a51df85

Browse files
committed
fix: show message overlay for gallery and files when message errors out
1 parent b22cd85 commit a51df85

File tree

5 files changed

+14
-36
lines changed

5 files changed

+14
-36
lines changed

package/src/components/Attachment/FileAttachment.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { useTheme } from '../../contexts/themeContext/ThemeContext';
1919

2020
export type FileAttachmentPropsWithContext = Pick<
2121
MessageContextValue,
22-
'onLongPress' | 'onPress' | 'onPressIn' | 'preventPress' | 'isMessageErrorType'
22+
'onLongPress' | 'onPress' | 'onPressIn' | 'preventPress'
2323
> &
2424
Pick<MessagesContextValue, 'additionalPressableProps'> & {
2525
/** The attachment to render */
@@ -46,12 +46,9 @@ const FileAttachmentWithContext = (props: FileAttachmentPropsWithContext) => {
4646
onPressIn,
4747
preventPress,
4848
styles: stylesProp = styles,
49-
isMessageErrorType,
5049
} = props;
5150

52-
const defaultOnPress = () => {
53-
openUrlSafely(attachment.asset_url);
54-
};
51+
const defaultOnPress = () => openUrlSafely(attachment.asset_url);
5552

5653
return (
5754
<Pressable
@@ -69,7 +66,7 @@ const FileAttachmentWithContext = (props: FileAttachmentPropsWithContext) => {
6966
if (onPress) {
7067
onPress({
7168
additionalInfo: { attachment },
72-
defaultHandler: isMessageErrorType ? undefined : defaultOnPress,
69+
defaultHandler: defaultOnPress,
7370
emitter: 'fileAttachment',
7471
event,
7572
});
@@ -79,7 +76,7 @@ const FileAttachmentWithContext = (props: FileAttachmentPropsWithContext) => {
7976
if (onPressIn) {
8077
onPressIn({
8178
additionalInfo: { attachment },
82-
defaultHandler: isMessageErrorType ? undefined : defaultOnPress,
79+
defaultHandler: defaultOnPress,
8380
emitter: 'fileAttachment',
8481
event,
8582
});
@@ -101,7 +98,7 @@ export type FileAttachmentProps = Partial<Omit<FileAttachmentPropsWithContext, '
10198
Pick<FileAttachmentPropsWithContext, 'attachment'>;
10299

103100
export const FileAttachment = (props: FileAttachmentProps) => {
104-
const { onLongPress, onPress, onPressIn, preventPress, isMessageErrorType } = useMessageContext();
101+
const { onLongPress, onPress, onPressIn, preventPress } = useMessageContext();
105102
const { additionalPressableProps, FileAttachmentIcon = FileIconDefault } = useMessagesContext();
106103

107104
return (
@@ -113,7 +110,6 @@ export const FileAttachment = (props: FileAttachmentProps) => {
113110
onPress,
114111
onPressIn,
115112
preventPress,
116-
isMessageErrorType,
117113
}}
118114
{...props}
119115
/>

package/src/components/Attachment/Gallery.tsx

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ export type GalleryPropsWithContext = Pick<ImageGalleryContextValue, 'imageGalle
5252
| 'preventPress'
5353
| 'message'
5454
| 'messageContentOrder'
55-
| 'isMessageErrorType'
5655
> &
5756
Pick<
5857
MessagesContextValue,
@@ -86,7 +85,6 @@ const GalleryWithContext = (props: GalleryPropsWithContext) => {
8685
videos,
8786
VideoThumbnail,
8887
messageHasOnlyOneImage = false,
89-
isMessageErrorType,
9088
} = props;
9189

9290
const { resizableCDNHosts } = useChatConfigContext();
@@ -211,7 +209,6 @@ const GalleryWithContext = (props: GalleryPropsWithContext) => {
211209
setOverlay={setOverlay}
212210
thumbnail={thumbnail}
213211
VideoThumbnail={VideoThumbnail}
214-
isMessageErrorType={isMessageErrorType}
215212
/>
216213
);
217214
})}
@@ -241,10 +238,7 @@ type GalleryThumbnailProps = {
241238
| 'ImageReloadIndicator'
242239
> &
243240
Pick<ImageGalleryContextValue, 'imageGalleryStateStore'> &
244-
Pick<
245-
MessageContextValue,
246-
'onLongPress' | 'onPress' | 'onPressIn' | 'preventPress' | 'isMessageErrorType'
247-
> &
241+
Pick<MessageContextValue, 'onLongPress' | 'onPress' | 'onPressIn' | 'preventPress'> &
248242
Pick<OverlayContextValue, 'setOverlay'>;
249243

250244
const GalleryThumbnail = ({
@@ -268,7 +262,6 @@ const GalleryThumbnail = ({
268262
setOverlay,
269263
thumbnail,
270264
VideoThumbnail,
271-
isMessageErrorType,
272265
}: GalleryThumbnailProps) => {
273266
const {
274267
theme: {
@@ -322,7 +315,7 @@ const GalleryThumbnail = ({
322315
if (onPress) {
323316
onPress({
324317
additionalInfo: { thumbnail },
325-
defaultHandler: isMessageErrorType ? undefined : defaultOnPress,
318+
defaultHandler: defaultOnPress,
326319
emitter: 'gallery',
327320
event,
328321
});
@@ -332,7 +325,7 @@ const GalleryThumbnail = ({
332325
if (onPressIn) {
333326
onPressIn({
334327
additionalInfo: { thumbnail },
335-
defaultHandler: isMessageErrorType ? undefined : defaultOnPress,
328+
defaultHandler: defaultOnPress,
336329
emitter: 'gallery',
337330
event,
338331
});
@@ -454,27 +447,20 @@ const areEqual = (prevProps: GalleryPropsWithContext, nextProps: GalleryPropsWit
454447
message: prevMessage,
455448
myMessageTheme: prevMyMessageTheme,
456449
videos: prevVideos,
457-
isMessageErrorType: prevIsMessageErrorType,
458450
} = prevProps;
459451
const {
460452
alignment: nextAlignment,
461453
images: nextImages,
462454
message: nextMessage,
463455
myMessageTheme: nextMyMessageTheme,
464456
videos: nextVideos,
465-
isMessageErrorType: nextIsMessageErrorType,
466457
} = nextProps;
467458

468459
const alignmentEqual = prevAlignment === nextAlignment;
469460
if (!alignmentEqual) {
470461
return false;
471462
}
472463

473-
const isMessageErrorTypeEqual = prevIsMessageErrorType === nextIsMessageErrorType;
474-
if (!isMessageErrorTypeEqual) {
475-
return false;
476-
}
477-
478464
const messageEqual =
479465
prevMessage?.id === nextMessage?.id &&
480466
`${prevMessage?.updated_at}` === `${nextMessage?.updated_at}`;
@@ -538,7 +524,6 @@ export const Gallery = (props: GalleryProps) => {
538524
videos: propVideos,
539525
VideoThumbnail: PropVideoThumbnail,
540526
messageContentOrder: propMessageContentOrder,
541-
isMessageErrorType: propIsMessageErrorType,
542527
} = props;
543528

544529
const { imageGalleryStateStore } = useImageGalleryContext();
@@ -552,7 +537,6 @@ export const Gallery = (props: GalleryProps) => {
552537
preventPress: contextPreventPress,
553538
videos: contextVideos,
554539
messageContentOrder: contextMessageContentOrder,
555-
isMessageErrorType: contextIsMessageErrorType,
556540
} = useMessageContext();
557541
const {
558542
additionalPressableProps: contextAdditionalPressableProps,
@@ -586,7 +570,6 @@ export const Gallery = (props: GalleryProps) => {
586570
const ImageReloadIndicator = PropImageReloadIndicator || ContextImageReloadIndicator;
587571
const myMessageTheme = propMyMessageTheme || contextMyMessageTheme;
588572
const messageContentOrder = propMessageContentOrder || contextMessageContentOrder;
589-
const isMessageErrorType = propIsMessageErrorType || contextIsMessageErrorType;
590573

591574
const messageHasOnlyOneImage =
592575
messageContentOrder?.length === 1 &&
@@ -615,7 +598,6 @@ export const Gallery = (props: GalleryProps) => {
615598
VideoThumbnail,
616599
messageHasOnlyOneImage,
617600
messageContentOrder,
618-
isMessageErrorType,
619601
}}
620602
/>
621603
);

package/src/components/Message/Message.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,9 +745,15 @@ const MessageWithContext = (props: MessagePropsWithContext) => {
745745
};
746746

747747
const handleOnPress = () => {
748+
if (errorOrFailed) {
749+
onPress(true);
750+
return;
751+
}
752+
748753
if (onPressMessageProp) {
749754
return onPressMessageProp(onPressArgs);
750755
}
756+
751757
if (payload.defaultHandler) {
752758
return payload.defaultHandler();
753759
}
@@ -782,7 +788,6 @@ const MessageWithContext = (props: MessagePropsWithContext) => {
782788
showMessageStatus: typeof showMessageStatus === 'boolean' ? showMessageStatus : isMyMessage,
783789
threadList,
784790
videos: attachments.videos,
785-
isMessageErrorType: errorOrFailed,
786791
});
787792

788793
const prevActive = useRef<boolean>(overlayActive);

package/src/components/Message/hooks/useCreateMessageContext.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ export const useCreateMessageContext = ({
5353
threadList,
5454
videos,
5555
setQuotedMessage,
56-
isMessageErrorType,
5756
}: MessageContextValue) => {
5857
const stableGroupStyles = useStableRefValue(groupStyles);
5958
const reactionsValue = reactions.map(({ count, own, type }) => `${own}${type}${count}`).join();
@@ -106,7 +105,6 @@ export const useCreateMessageContext = ({
106105
showMessageStatus,
107106
threadList,
108107
videos,
109-
isMessageErrorType,
110108
}),
111109
// eslint-disable-next-line react-hooks/exhaustive-deps
112110
[
@@ -128,7 +126,6 @@ export const useCreateMessageContext = ({
128126
showMessageStatus,
129127
threadList,
130128
preventPress,
131-
isMessageErrorType,
132129
],
133130
);
134131

package/src/contexts/messageContext/MessageContext.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ import { DEFAULT_BASE_CONTEXT_VALUE } from '../utils/defaultBaseContextValue';
2020
export type Alignment = 'right' | 'left';
2121

2222
export type MessageContextValue = {
23-
/** Whether or not the message is an error */
24-
isMessageErrorType: boolean;
2523
/** Whether or not actions can be performed on message */
2624
actionsEnabled: boolean;
2725
/** Position of the message, either 'right' or 'left' */

0 commit comments

Comments
 (0)