Skip to content

Commit e0c0732

Browse files
committed
fix: make uploads depend solely on allowSendBeforeAttachmentsUpload
1 parent 603ca1d commit e0c0732

7 files changed

Lines changed: 24 additions & 15 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import {
1313

1414
import { AudioAttachment } from '../../../../components/Attachment/Audio';
1515
import { useTheme } from '../../../../contexts';
16-
import { useChatContext } from '../../../../contexts/chatContext/ChatContext';
1716
import { useMessageComposer } from '../../../../contexts/messageInputContext/hooks/useMessageComposer';
17+
import { useMessageInputContext } from '../../../../contexts/messageInputContext/MessageInputContext';
1818
import { primitives } from '../../../../theme';
1919
import { UploadAttachmentPreviewProps } from '../../../../types/types';
2020
import { getIndicatorTypeForFileState, ProgressIndicatorTypes } from '../../../../utils/utils';
@@ -30,10 +30,10 @@ export const AudioAttachmentUploadPreview = ({
3030
removeAttachments,
3131
}: AudioAttachmentUploadPreviewProps) => {
3232
const styles = useStyles();
33-
const { enableOfflineSupport } = useChatContext();
33+
const { allowSendBeforeAttachmentsUpload } = useMessageInputContext();
3434
const indicatorType = getIndicatorTypeForFileState(
3535
attachment.localMetadata.uploadState,
36-
enableOfflineSupport,
36+
!!allowSendBeforeAttachmentsUpload,
3737
);
3838
const messageComposer = useMessageComposer();
3939
const isDraft = messageComposer.draftId;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import {
1212
import { AttachmentRemoveControl } from './AttachmentRemoveControl';
1313

1414
import { FilePreview } from '../../../../components/Attachment/FilePreview';
15-
import { useChatContext } from '../../../../contexts/chatContext/ChatContext';
1615
import { useComponentsContext } from '../../../../contexts/componentsContext/ComponentsContext';
16+
import { useMessageInputContext } from '../../../../contexts/messageInputContext/MessageInputContext';
1717
import { useTheme } from '../../../../contexts/themeContext/ThemeContext';
1818
import { primitives } from '../../../../theme';
1919
import { UploadAttachmentPreviewProps } from '../../../../types/types';
@@ -39,10 +39,10 @@ export const FileAttachmentUploadPreview = ({
3939
FileUploadRetryIndicator,
4040
FileUploadNotSupportedIndicator,
4141
} = useComponentsContext();
42-
const { enableOfflineSupport } = useChatContext();
42+
const { allowSendBeforeAttachmentsUpload } = useMessageInputContext();
4343
const indicatorType = getIndicatorTypeForFileState(
4444
attachment.localMetadata.uploadState,
45-
enableOfflineSupport,
45+
!!allowSendBeforeAttachmentsUpload,
4646
);
4747

4848
const {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { LocalImageAttachment } from 'stream-chat';
66

77
import { AttachmentRemoveControl } from './AttachmentRemoveControl';
88

9-
import { useChatContext } from '../../../../contexts/chatContext/ChatContext';
109
import { useComponentsContext } from '../../../../contexts/componentsContext/ComponentsContext';
10+
import { useMessageInputContext } from '../../../../contexts/messageInputContext/MessageInputContext';
1111
import { useTheme } from '../../../../contexts/themeContext/ThemeContext';
1212
import { primitives } from '../../../../theme';
1313
import { UploadAttachmentPreviewProps } from '../../../../types/types';
@@ -24,7 +24,7 @@ export const ImageAttachmentUploadPreview = ({
2424
removeAttachments,
2525
}: ImageAttachmentUploadPreviewProps) => {
2626
const [loading, setLoading] = useState(true);
27-
const { enableOfflineSupport } = useChatContext();
27+
const { allowSendBeforeAttachmentsUpload } = useMessageInputContext();
2828
const {
2929
ImageLoadingIndicator,
3030
ImageUploadInProgressIndicator,
@@ -33,7 +33,7 @@ export const ImageAttachmentUploadPreview = ({
3333
} = useComponentsContext();
3434
const indicatorType = getIndicatorTypeForFileState(
3535
attachment.localMetadata.uploadState,
36-
enableOfflineSupport,
36+
!!allowSendBeforeAttachmentsUpload,
3737
);
3838
const previewUri = attachment.localMetadata.previewUri ?? attachment.image_url;
3939
const shouldShowImageLoadingIndicator =

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { Recorder } from '../../../../icons';
1212
import { primitives } from '../../../../theme';
1313
import { UploadAttachmentPreviewProps } from '../../../../types/types';
1414
import { formatMsToMinSec, getDurationLabelFromDuration } from '../../../../utils/utils';
15+
import { useMessageInputContext } from '../../../../contexts';
1516

1617
export type VideoAttachmentUploadPreviewProps<CustomLocalMetadata = Record<string, unknown>> =
1718
UploadAttachmentPreviewProps<LocalVideoAttachment<CustomLocalMetadata>>;
@@ -22,7 +23,9 @@ export const VideoAttachmentUploadPreview = ({
2223
removeAttachments,
2324
}: VideoAttachmentUploadPreviewProps) => {
2425
const previewUri = attachment.thumb_url ?? attachment.localMetadata.previewUri;
25-
const shouldShowMetadataPill = attachment.localMetadata.uploadState !== 'uploading';
26+
const { allowSendBeforeAttachmentsUpload } = useMessageInputContext();
27+
const shouldShowMetadataPill =
28+
allowSendBeforeAttachmentsUpload || attachment.localMetadata.uploadState !== 'uploading';
2629

2730
return previewUri ? (
2831
<>

package/src/contexts/messageInputContext/hooks/useCreateMessageInputContext.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { MessageInputContextValue } from '../MessageInputContext';
55

66
export const useCreateMessageInputContext = ({
77
additionalTextInputProps,
8+
allowSendBeforeAttachmentsUpload,
89
asyncMessagesLockDistance,
910
asyncMessagesMinimumPressDuration,
1011
asyncMessagesSlideToCancelDistance,
@@ -47,6 +48,7 @@ export const useCreateMessageInputContext = ({
4748
const messageInputContext: MessageInputContextValue = useMemo(
4849
() => ({
4950
additionalTextInputProps,
51+
allowSendBeforeAttachmentsUpload,
5052
asyncMessagesLockDistance,
5153
asyncMessagesMinimumPressDuration,
5254
asyncMessagesSlideToCancelDistance,
@@ -84,7 +86,7 @@ export const useCreateMessageInputContext = ({
8486
stopVoiceRecording,
8587
}),
8688
// eslint-disable-next-line react-hooks/exhaustive-deps
87-
[threadId, showPollCreationDialog],
89+
[threadId, showPollCreationDialog, allowSendBeforeAttachmentsUpload],
8890
);
8991

9092
return messageInputContext;

package/src/contexts/messageInputContext/hooks/useMessageComposerHasSendableData.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ import type { EditingAuditState } from 'stream-chat';
33
import { useMessageComposer } from './useMessageComposer';
44

55
import { useStateStore } from '../../../hooks/useStateStore';
6+
import { useMessageInputContext } from '../MessageInputContext';
67

78
const editingAuditStateStateSelector = (state: EditingAuditState) => state;
89

910
export const useMessageComposerHasSendableData = () => {
11+
const { allowSendBeforeAttachmentsUpload } = useMessageInputContext();
1012
const messageComposer = useMessageComposer();
1113
useStateStore(messageComposer.editingAuditState, editingAuditStateStateSelector);
12-
return messageComposer.hasSendableData;
14+
return allowSendBeforeAttachmentsUpload
15+
? !messageComposer.contentIsEmpty
16+
: messageComposer.hasSendableData;
1317
};

package/src/utils/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ type IndicatorStatesMap = Record<AttachmentLoadingState, Progress | undefined>;
5757

5858
export const getIndicatorTypeForFileState = (
5959
fileState: AttachmentLoadingState,
60-
enableOfflineSupport: boolean,
60+
allowSendBeforeAttachmentsUpload: boolean,
6161
): Progress | undefined => {
6262
const indicatorMap: IndicatorStatesMap = {
63-
[FileState.UPLOADING]: enableOfflineSupport
63+
[FileState.UPLOADING]: allowSendBeforeAttachmentsUpload
6464
? ProgressIndicatorTypes.INACTIVE
6565
: ProgressIndicatorTypes.IN_PROGRESS,
6666
[FileState.BLOCKED]: ProgressIndicatorTypes.NOT_SUPPORTED,
67-
[FileState.FAILED]: enableOfflineSupport
67+
[FileState.FAILED]: allowSendBeforeAttachmentsUpload
6868
? ProgressIndicatorTypes.INACTIVE
6969
: ProgressIndicatorTypes.RETRY,
7070
[FileState.PENDING]: ProgressIndicatorTypes.PENDING,

0 commit comments

Comments
 (0)