Skip to content

Commit

Permalink
fix :: 파일 업로드 버그 픽스
Browse files Browse the repository at this point in the history
  • Loading branch information
KANGYONGSU23 committed Apr 9, 2024
1 parent d91b05a commit ad39387
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/components/recruitments/apply/FileUploader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,24 @@ export default function FileUploader({

const addFileList = () => {
if (fileRef.current?.files?.length) {
const files = Array.from(fileRef.current?.files);
setFileList(prev => [...prev, ...files]);
const files = removeOverlap([...fileList, ...(Array.from(fileRef.current?.files))]);
setFileList(files);
}
};

const removeOverlap = (array: any[]) => {
let uniqueObjects:{[key:string]:File} = {}
array.forEach(obj => {
const { name, lastModified,} = obj
const key = JSON.stringify({...name, ...lastModified});
console.log(key)
uniqueObjects[key] = obj;
});
console.log(array);
console.log(uniqueObjects);
return Object.values(uniqueObjects);
}

const prependFileItem = (fileName: string) => {
setFileList(prev => prev.filter(file => file.name !== fileName));
};
Expand All @@ -42,7 +55,10 @@ export default function FileUploader({
ref={fileRef}
type="file"
multiple={multiple}
onChange={addFileList}
onChange={(e)=>{
addFileList();
e.target.value = "";
}}
/>
<div
onMouseEnter={() => {
Expand Down

0 comments on commit ad39387

Please sign in to comment.