Skip to content

Commit a24b42e

Browse files
committed
fix: set draft config from app
1 parent 71024ac commit a24b42e

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

examples/SampleApp/App.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,14 @@ const DrawerNavigatorWrapper: React.FC<{
172172
const { bottom } = useSafeAreaInsets();
173173
const streamChatTheme = useStreamChatTheme();
174174

175+
chatClient.setMessageComposerSetupFunction(({ composer }) => {
176+
composer.updateConfig({
177+
drafts: {
178+
enabled: true,
179+
},
180+
});
181+
});
182+
175183
return (
176184
<GestureHandlerRootView style={{ flex: 1 }}>
177185
<OverlayProvider bottomInset={bottom} value={{ style: streamChatTheme }}>

examples/SampleApp/src/components/ChannelPreview.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ const CustomChannelPreviewStatus = (
7171
);
7272
};
7373

74-
export const ChannelPreview: React.FC<ChannelPreviewMessengerProps> = (
75-
props,
76-
) => {
74+
export const ChannelPreview: React.FC<ChannelPreviewMessengerProps> = (props) => {
7775
const { channel } = props;
7876

7977
const { setOverlay } = useAppOverlayContext();

examples/SampleApp/src/screens/ChannelScreen.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export const ChannelScreen: React.FC<ChannelScreenProps> = ({
135135
if (!newChannel?.initialized) {
136136
await newChannel?.watch();
137137
}
138-
} catch(error) {
138+
} catch (error) {
139139
console.log('An error has occurred while watching the channel: ', error);
140140
}
141141
setChannel(newChannel);

package/src/components/MessageInput/MessageInput.tsx

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import Animated, {
1919
import {
2020
FileReference,
2121
isLocalImageAttachment,
22-
MessageComposerConfig,
2322
type MessageComposerState,
2423
type TextComposerState,
2524
type UserResponse,
@@ -165,10 +164,6 @@ const messageComposerStateStoreSelector = (state: MessageComposerState) => ({
165164
quotedMessage: state.quotedMessage,
166165
});
167166

168-
const configStateSelector = (state: MessageComposerConfig) => ({
169-
draftsEnabled: state.drafts.enabled,
170-
});
171-
172167
const MessageInputWithContext = (props: MessageInputPropsWithContext) => {
173168
const {
174169
additionalTextInputProps,
@@ -224,7 +219,6 @@ const MessageInputWithContext = (props: MessageInputPropsWithContext) => {
224219
const { quotedMessage } = useStateStore(messageComposer.state, messageComposerStateStoreSelector);
225220
const { attachments } = useAttachmentManagerState();
226221
const hasSendableData = useMessageComposerHasSendableData();
227-
const { draftsEnabled } = useStateStore(messageComposer.configState, configStateSelector);
228222

229223
const imageUploads = attachments.filter((attachment) => isLocalImageAttachment(attachment));
230224
const fileUploads = attachments.filter((attachment) => !isLocalImageAttachment(attachment));
@@ -265,7 +259,6 @@ const MessageInputWithContext = (props: MessageInputPropsWithContext) => {
265259
const { seconds: cooldownRemainingSeconds } = useCountdown(cooldownEndsAt);
266260

267261
useEffect(() => {
268-
messageComposer.updateConfig({ drafts: { enabled: true } });
269262
attachmentManager.maxNumberOfFilesPerMessage = maxNumberOfFiles;
270263
if (doFileUploadRequest) {
271264
attachmentManager.setCustomUploadFn(doFileUploadRequest);
@@ -316,13 +309,12 @@ const MessageInputWithContext = (props: MessageInputPropsWithContext) => {
316309
}, [messageComposer, inputBoxRef]);
317310

318311
// Effect to create draft whenever we un-mount the component.
319-
useEffect(() => {
320-
return () => {
321-
if (draftsEnabled) {
322-
messageComposer.createDraft();
323-
}
324-
};
325-
}, [draftsEnabled, messageComposer]);
312+
useEffect(
313+
() => () => {
314+
messageComposer.createDraft();
315+
},
316+
[messageComposer],
317+
);
326318

327319
const uploadImagesHandler = async () => {
328320
const imageToUpload = selectedImages.find((selectedImage) => {

0 commit comments

Comments
 (0)