Skip to content

Commit

Permalink
Merge branch 'develop' into fix/autotranslate-e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusbsilva137 authored Oct 10, 2023
2 parents afc95a5 + 2124868 commit a1e6e4a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/eleven-gorillas-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Fix trying to upload same file again and again.
2 changes: 1 addition & 1 deletion apps/meteor/client/lib/chats/ChatAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export type ChatAPI = {
ActionManager: any;

readonly flows: {
readonly uploadFiles: (files: readonly File[]) => Promise<void>;
readonly uploadFiles: (files: readonly File[], resetFileInput?: () => void) => Promise<void>;
readonly sendMessage: ({ text, tshow }: { text: string; tshow?: boolean; previewUrls?: string[] }) => Promise<boolean>;
readonly processSlashCommand: (message: IMessage, userId: string | null) => Promise<boolean>;
readonly processTooLongMessage: (message: IMessage) => Promise<boolean>;
Expand Down
3 changes: 2 additions & 1 deletion apps/meteor/client/lib/chats/flows/uploadFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { imperativeModal } from '../../imperativeModal';
import { prependReplies } from '../../utils/prependReplies';
import type { ChatAPI } from '../ChatAPI';

export const uploadFiles = async (chat: ChatAPI, files: readonly File[]): Promise<void> => {
export const uploadFiles = async (chat: ChatAPI, files: readonly File[], resetFileInput?: () => void): Promise<void> => {
const replies = chat.composer?.quotedMessages.get() ?? [];

const msg = await prependReplies('', replies);
Expand Down Expand Up @@ -52,4 +52,5 @@ export const uploadFiles = async (chat: ChatAPI, files: readonly File[]): Promis
};

uploadNextFile();
resetFileInput?.();
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ const FileUploadAction = ({ collapsed, chatContext, disabled, ...props }: FileUp
const fileInputRef = useRef<HTMLInputElement>(null);
const chat = useChat() ?? chatContext;

const resetFileInput = () => {
if (!fileInputRef.current) {
return;
}

fileInputRef.current.value = '';
};

const handleUploadChange = async (e: ChangeEvent<HTMLInputElement>) => {
const { mime } = await import('../../../../../../../app/utils/lib/mimeTypes');
const filesToUpload = Array.from(e.target.files ?? []).map((file) => {
Expand All @@ -26,8 +34,7 @@ const FileUploadAction = ({ collapsed, chatContext, disabled, ...props }: FileUp
});
return file;
});

chat?.flows.uploadFiles(filesToUpload);
chat?.flows.uploadFiles(filesToUpload, resetFileInput);
};

const handleUpload = () => {
Expand Down

0 comments on commit a1e6e4a

Please sign in to comment.