Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

111 파일 드래그 업로드 #112

Merged
merged 3 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions src/components/common/FileFind/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,24 @@ import * as S from './styled';

type FileFindProps = {
handleChangeFile: any;
handleDrop: any;
handleDragOver: any;
fileProps: any;
};

export const FileFind: React.FC<FileFindProps> = ({ handleChangeFile, fileProps }) => (
export const FileFind: React.FC<FileFindProps> = ({
handleChangeFile,
fileProps,
handleDrop,
handleDragOver,
}) => (
<S.FileFindContainer>
<S.FileFindTextBox>
<S.FileFindLabelBox
id="label-file-upload"
htmlFor="input-file-upload"
onDrop={handleDrop}
onDragOver={handleDragOver}
>
{fileProps.filename != '' && fileProps.size != '' && fileProps.fileType != ''
? '이름:' +
fileProps.filename +
Expand All @@ -18,9 +30,14 @@ export const FileFind: React.FC<FileFindProps> = ({ handleChangeFile, fileProps
' / 타입:' +
fileProps.fileType
: '업로드 할 파일을 선택해주세요....'}
</S.FileFindTextBox>
</S.FileFindLabelBox>

<S.FileFindButton htmlFor="file">찾아보기</S.FileFindButton>
<input type={'file'} id="file" style={{ display: 'none' }} onChange={handleChangeFile} />
<S.FileFindButton htmlFor="input-file-upload">찾아보기</S.FileFindButton>
<input
id="input-file-upload"
type={'file'}
style={{ display: 'none' }}
onChange={handleChangeFile}
/>
</S.FileFindContainer>
);
2 changes: 1 addition & 1 deletion src/components/common/FileFind/styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const FileFindContainer = styled.div`
margin-top: 2rem;
`;

export const FileFindTextBox = styled.div`
export const FileFindLabelBox = styled.label`
border: 0.4rem solid var(--color-border);
border-radius: 1rem;
width: 45rem;
Expand Down
24 changes: 23 additions & 1 deletion src/pages/main/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const MainPage: React.FC = () => {
const { SetDownloadFileProps } = bindActionCreators(actionCreators, dispatch);

const handleChangeFile = (event: any) => {
event.preventDefault();
setFileProps({
filename: event.target.files[0].name,
size: getFileSize(event.target.files[0].size),
Expand All @@ -56,6 +57,22 @@ export const MainPage: React.FC = () => {
});
};

const handleDrop = function (event: any) {
event.preventDefault();
setFileProps({
filename: event.dataTransfer.files[0].name,
size: getFileSize(event.dataTransfer.files[0].size),
fileType:
event.dataTransfer.files[0].type === ''
? 'application/actet-stream'
: event.dataTransfer.files[0].type,
fileData: event.dataTransfer.files[0],
});
};
const dragOver = (event: any) => {
event.preventDefault();
};

const UpLoad = async () => {
if (fileProps.filename != '' && fileProps.size != '') {
const formdata = new FormData();
Expand Down Expand Up @@ -168,7 +185,12 @@ export const MainPage: React.FC = () => {
placeholder="비밀번호를 입력해주세요."
/>
)}
<FileFind handleChangeFile={handleChangeFile} fileProps={fileProps} />
<FileFind
handleDrop={handleDrop}
handleDragOver={dragOver}
handleChangeFile={handleChangeFile}
fileProps={fileProps}
/>
<UpLoadButton type={'button'} value={'업로드'} onClick={UpLoad} />
</>
) : (
Expand Down
2 changes: 1 addition & 1 deletion src/utils/getDate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const getExpireTime = (date: string) => {
const differenceTime = expireTime.getTime() - today.getTime();
const differenceTimeDay =
differenceTime / (1000 * 60 * 60 * 24) >= 0 ? differenceTime / (1000 * 60 * 60 * 24) : 0;
console.log(differenceTimeDay);

let differenceTimeHour = differenceTime / (1000 * 60 * 60);
while (true) {
differenceTimeHour %= 24;
Expand Down