Skip to content

Commit

Permalink
[FIX] File upload (Avatars, Emoji, Sounds) (#18841)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo authored Sep 9, 2020
1 parent 0df9b91 commit 87237f1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions client/contexts/ServerContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type ServerContextValue = {
absoluteUrl: (path: string) => string;
callMethod: (methodName: string, ...args: any[]) => Promise<any>;
callEndpoint: (httpMethod: 'GET' | 'POST' | 'DELETE', endpoint: string, ...args: any[]) => Promise<any>;
uploadToEndpoint: (endpoint: string) => Promise<void>;
uploadToEndpoint: (endpoint: string, params: any, formData: any) => Promise<void>;
getStream: (streamName: string, options?: {}) => IServerStream;
};

Expand Down Expand Up @@ -40,9 +40,9 @@ export const useEndpoint = (httpMethod: 'GET' | 'POST' | 'DELETE', endpoint: str
return useCallback((...args: any[]) => callEndpoint(httpMethod, endpoint, ...args), [callEndpoint, httpMethod, endpoint]);
};

export const useUpload = (endpoint: string): () => Promise<void> => {
export const useUpload = (endpoint: string): (params: any, formData: any) => Promise<void> => {
const { uploadToEndpoint } = useContext(ServerContext);
return useCallback(() => uploadToEndpoint(endpoint), [endpoint, uploadToEndpoint]);
return useCallback((params, formData: any) => uploadToEndpoint(endpoint, params, formData), [endpoint, uploadToEndpoint]);
};

export const useStream = (streamName: string, options?: {}): IServerStream => {
Expand Down
4 changes: 2 additions & 2 deletions client/hooks/useFileInput.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useMutableCallback } from '@rocket.chat/fuselage-hooks';
import { useRef, useEffect } from 'react';

export const useFileInput = (onSetFile, fileType = 'image/*') => {
export const useFileInput = (onSetFile, fileType = 'image/*', fileField = 'image') => {
const ref = useRef();

useEffect(() => {
Expand All @@ -14,7 +14,7 @@ export const useFileInput = (onSetFile, fileType = 'image/*') => {

ref.current = fileInput;
const handleFiles = () => {
formData.append(fileType, fileInput.files[0]);
formData.append(fileField, fileInput.files[0]);
onSetFile(fileInput.files[0], formData);
};
fileInput.addEventListener('change', handleFiles, false);
Expand Down
2 changes: 1 addition & 1 deletion client/hooks/useUpdateAvatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const useUpdateAvatar = (avatarObj, userId) => {

const saveAvatarQuery = useMemo(() => ({
userId,
avatarUrl,
...avatarUrl && { avatarUrl },
}), [avatarUrl, userId]);

const resetAvatarQuery = useMemo(() => ({
Expand Down

0 comments on commit 87237f1

Please sign in to comment.