Skip to content

Commit

Permalink
Revert "feat : 이미지 업로드하면 먼저 유저에게 보여주기"
Browse files Browse the repository at this point in the history
This reverts commit 7898e1f.
  • Loading branch information
guesung committed Nov 24, 2023
1 parent f3c2ba0 commit ab96340
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ export default function MainStep({ onSelectMeetDate, onCreateSubmit }: MainStepP
});

const handleCreateClick = () => {
if (watch('imageUrl').includes('http')) {
openToast(() => <Toast>{t('create.error.image')}</Toast>);
return;
}
if (!validateDate(watch('meetDate'), watch('time'), browser)) {
openToast(() => <Toast>{t('create.error.time')}</Toast>);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Flex } from '@/components/Layout';
import { Loading } from '@/components/Loading';
import { useFileUpload } from '@/hooks/useFileUpload';
import Image from 'next/image';
import { memo, useEffect } from 'react';
import { memo } from 'react';
import { Control, useController } from 'react-hook-form';

import type { CreateGroupContextValue } from '../../type';
Expand All @@ -19,33 +19,24 @@ export default function UploadSection({ control }: ImageThumbnailProps) {
control,
});

const { handleFileUploadClick, fileList } = useFileUpload((files) => {
const { handleFileUploadClick, isLoading } = useFileUpload((files) => {
field.onChange(files[0]);
});

useEffect(() => {
const reader = new FileReader();
if (!fileList) return;
reader.readAsDataURL(fileList[0]);
reader.onload = () => {
field.onChange(reader.result);
};
}, [fileList]);

return (
<Flex
justify="center"
align="center"
className="relative mx-20 aspect-[8/5] overflow-hidden rounded-8 bg-sub"
onClick={handleFileUploadClick}
>
<RenderImage imageUrl={field.value} />
<RenderImage isLoading={isLoading} imageUrl={field.value} />
</Flex>
);
}

interface RenderImageProps {
isLoading?: boolean;
isLoading: boolean;
imageUrl: string;
}

Expand Down
3 changes: 1 addition & 2 deletions src/app/i18n/locales/en/grouping.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
"label": "Number of Participants"
},
"error": {
"time": "Please set a time later than the current time.",
"image": "An error occurred during image upload. Please try uploading again."
"time": "Please set a time later than the current time."
},
"continue": "Continue",
"submit": {
Expand Down
3 changes: 1 addition & 2 deletions src/app/i18n/locales/ko/grouping.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
"label": "모임 인원"
},
"error": {
"time": "현재 시간 이후로 설정해주세요.",
"image": "An error occurred during image upload. Please try uploading again"
"time": "현재 시간 이후로 설정해주세요."
},
"continue": "완료",
"submit": {
Expand Down
5 changes: 1 addition & 4 deletions src/hooks/useFileUpload.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { usePostFiles } from '@/apis/common';
import { useCallback, useState } from 'react';
import { useCallback } from 'react';

interface UseImageUploadProps {
/**
Expand All @@ -23,15 +23,13 @@ export function useFileUpload(
options?: UseImageUploadProps['options']
) {
const { mutate, isLoading } = usePostFiles();
const [fileList, setFileList] = useState<FileList | null>(null);

const handleFileUploadClick = useCallback(() => {
const input = document.createElement('input');
input.type = 'file';
input.accept = options?.accept || 'image/*';
input.multiple = options?.multiple || false;
input.onchange = (event) => {
setFileList((event.target as HTMLInputElement).files);
const { files } = event.target as HTMLInputElement;
if (!files) return;

Expand All @@ -50,6 +48,5 @@ export function useFileUpload(
return {
handleFileUploadClick,
isLoading,
fileList,
};
}

0 comments on commit ab96340

Please sign in to comment.