Skip to content

Commit 68c0acb

Browse files
Fixing message edit issue
1 parent 97e879e commit 68c0acb

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/components/MessageInput/MessageInput.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,10 @@ export const MessageInput = <
734734
}
735735
}
736736

737-
if (image.state === FileState.UPLOADED) {
737+
if (
738+
image.state === FileState.UPLOADED ||
739+
image.state === FileState.FINISHED
740+
) {
738741
attachments.push({
739742
fallback: image.file.name,
740743
image_url: image.url,
@@ -752,7 +755,10 @@ export const MessageInput = <
752755
sending.current = false;
753756
return;
754757
}
755-
if (file.state === FileState.UPLOADED) {
758+
if (
759+
file.state === FileState.UPLOADED ||
760+
file.state === FileState.FINISHED
761+
) {
756762
attachments.push({
757763
asset_url: file.url,
758764
file_size: file.file.size,
@@ -779,10 +785,17 @@ export const MessageInput = <
779785

780786
// TODO: Remove this line and show an error when submit fails
781787
clearEditingState();
782-
783788
const updateMessagePromise = editMessage(updatedMessage).then(
784789
clearEditingState,
785790
);
791+
setFileUploads([]);
792+
setImageUploads([]);
793+
setMentionedUsers([]);
794+
setNumberOfUploads(
795+
(prevNumberOfUploads) =>
796+
prevNumberOfUploads - (attachments?.length || 0),
797+
);
798+
setText('');
786799
logChatPromiseExecution(updateMessagePromise, 'update message');
787800

788801
sending.current = false;

src/utils/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ export const emojiData = [
5353
];
5454

5555
export const FileState = Object.freeze({
56+
// finished and uploaded state are the same thing. First is set on frontend,
57+
// while later is set on backend side
58+
// TODO: Unify both of them
59+
FINISHED: 'finished',
5660
NO_FILE: 'no_file',
5761
UPLOAD_FAILED: 'upload_failed',
5862
UPLOADED: 'uploaded',

0 commit comments

Comments
 (0)