Skip to content

Commit

Permalink
chore: Rename useFileInput to useSingleFileInput (#31186)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriellsh authored Dec 7, 2023
1 parent a271587 commit f1013a3
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions apps/meteor/client/components/avatar/RoomAvatarEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { ReactElement } from 'react';
import React, { useEffect } from 'react';

import { getAvatarURL } from '../../../app/utils/client/getAvatarURL';
import { useFileInput } from '../../hooks/useFileInput';
import { useSingleFileInput } from '../../hooks/useSingleFileInput';
import { isValidImageFormat } from '../../lib/utils/isValidImageFormat';
import RoomAvatar from './RoomAvatar';

Expand Down Expand Up @@ -36,7 +36,7 @@ const RoomAvatarEditor = ({ disabled = false, room, roomAvatar, onChangeAvatar }
};
});

const [clickUpload, reset] = useFileInput(handleChangeAvatar);
const [clickUpload, reset] = useSingleFileInput(handleChangeAvatar);
const clickReset = useMutableCallback(() => {
reset();
onChangeAvatar(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useToastMessageDispatch, useSetting, useTranslation } from '@rocket.cha
import type { ReactElement, ChangeEvent } from 'react';
import React, { useState, useCallback } from 'react';

import { useFileInput } from '../../../hooks/useFileInput';
import { useSingleFileInput } from '../../../hooks/useSingleFileInput';
import { isValidImageFormat } from '../../../lib/utils/isValidImageFormat';
import UserAvatar from '../UserAvatar';
import UserAvatarSuggestions from './UserAvatarSuggestions';
Expand Down Expand Up @@ -47,7 +47,7 @@ function UserAvatarEditor({ currentUsername, username, setAvatarObj, disabled, e
[setAvatarObj, t, dispatchToastMessage],
);

const [clickUpload] = useFileInput(setUploadedPreview);
const [clickUpload] = useSingleFileInput(setUploadedPreview);

const clickUrl = (): void => {
setNewAvatarSource(avatarFromUrl);
Expand Down
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 = (
export const useSingleFileInput = (
onSetFile: (file: FileList[number], formData: FormData) => void,
fileType = 'image/*',
fileField = 'image',
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/client/views/admin/customEmoji/AddCustomEmoji.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import React, { useCallback, useState } from 'react';

import { ContextualbarScrollableContent, ContextualbarFooter } from '../../../components/Contextualbar';
import { useEndpointUpload } from '../../../hooks/useEndpointUpload';
import { useFileInput } from '../../../hooks/useFileInput';
import { useSingleFileInput } from '../../../hooks/useSingleFileInput';

type AddCustomEmojiProps = {
close: () => void;
Expand Down Expand Up @@ -56,7 +56,7 @@ const AddCustomEmoji = ({ close, onChange, ...props }: AddCustomEmojiProps): Rea
}
}, [emojiFile, name, aliases, saveAction, onChange, close]);

const [clickUpload] = useFileInput(setEmojiPreview, 'emoji');
const [clickUpload] = useSingleFileInput(setEmojiPreview, 'emoji');

const handleChangeName = (e: ChangeEvent<HTMLInputElement>): void => {
if (e.currentTarget.value !== '') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { ContextualbarScrollableContent, ContextualbarFooter } from '../../../co
import GenericModal from '../../../components/GenericModal';
import { useEndpointAction } from '../../../hooks/useEndpointAction';
import { useEndpointUpload } from '../../../hooks/useEndpointUpload';
import { useFileInput } from '../../../hooks/useFileInput';
import { useSingleFileInput } from '../../../hooks/useSingleFileInput';

type EditCustomEmojiProps = {
close: () => void;
Expand Down Expand Up @@ -131,7 +131,7 @@ const EditCustomEmoji: FC<EditCustomEmojiProps> = ({ close, onChange, data, ...p
[setAliases, name],
);

const [clickUpload] = useFileInput(setEmojiFile, 'emoji');
const [clickUpload] = useSingleFileInput(setEmojiFile, 'emoji');

const handleChangeName = (e: ChangeEvent<HTMLInputElement>): void => {
if (e.currentTarget.value !== '') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { ReactElement, FormEvent } from 'react';
import React, { useState, useCallback } from 'react';

import { ContextualbarScrollableContent, ContextualbarFooter } from '../../../components/Contextualbar';
import { useFileInput } from '../../../hooks/useFileInput';
import { useSingleFileInput } from '../../../hooks/useSingleFileInput';
import { validate, createSoundData } from './lib';

type AddCustomSoundProps = {
Expand All @@ -27,7 +27,7 @@ const AddCustomSound = ({ goToNew, close, onChange, ...props }: AddCustomSoundPr
setSound(soundFile);
}, []);

const [clickUpload] = useFileInput(handleChangeFile, 'audio/mp3');
const [clickUpload] = useSingleFileInput(handleChangeFile, 'audio/mp3');

const saveAction = useCallback(
async (name, soundFile): Promise<string | undefined> => {
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/client/views/admin/customSounds/EditSound.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import React, { useCallback, useState, useMemo, useEffect } from 'react';

import { ContextualbarScrollableContent, ContextualbarFooter } from '../../../components/Contextualbar';
import GenericModal from '../../../components/GenericModal';
import { useFileInput } from '../../../hooks/useFileInput';
import { useSingleFileInput } from '../../../hooks/useSingleFileInput';
import { validate, createSoundData } from './lib';

type EditSoundProps = {
Expand Down Expand Up @@ -114,7 +114,7 @@ function EditSound({ close, onChange, data, ...props }: EditSoundProps): ReactEl
));
}, [_id, close, deleteCustomSound, dispatchToastMessage, onChange, setModal, t]);

const [clickUpload] = useFileInput(handleChangeFile, 'audio/mp3');
const [clickUpload] = useSingleFileInput(handleChangeFile, 'audio/mp3');

return (
<>
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/client/views/marketplace/AppInstallPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { AppClientOrchestratorInstance } from '../../../ee/client/apps/orchestra
import { Page, PageHeader, PageScrollableContent } from '../../components/Page';
import { useAppsReload } from '../../contexts/hooks/useAppsReload';
import { useExternalLink } from '../../hooks/useExternalLink';
import { useFileInput } from '../../hooks/useFileInput';
import { useSingleFileInput } from '../../hooks/useSingleFileInput';
import { useCheckoutUrl } from '../admin/subscription/hooks/useCheckoutUrl';
import AppPermissionsReviewModal from './AppPermissionsReviewModal';
import AppUpdateModal from './AppUpdateModal';
Expand Down Expand Up @@ -59,7 +59,7 @@ function AppInstallPage() {

const canSave = !!url || !!file?.name;

const [handleUploadButtonClick] = useFileInput((value) => setValue('file', value), 'app');
const [handleUploadButtonClick] = useSingleFileInput((value) => setValue('file', value), 'app');

const sendFile = async (permissionsGranted, appFile, appId) => {
let app;
Expand Down

0 comments on commit f1013a3

Please sign in to comment.