From ad393878ad9b314f8f7bf5f95c93e52a26a8ef1c Mon Sep 17 00:00:00 2001 From: KANGYONGSU23 Date: Tue, 9 Apr 2024 09:05:11 +0900 Subject: [PATCH] =?UTF-8?q?fix=20::=20=ED=8C=8C=EC=9D=BC=20=EC=97=85?= =?UTF-8?q?=EB=A1=9C=EB=93=9C=20=EB=B2=84=EA=B7=B8=20=ED=94=BD=EC=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recruitments/apply/FileUploader.tsx | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/components/recruitments/apply/FileUploader.tsx b/src/components/recruitments/apply/FileUploader.tsx index f233c8e..c61da13 100644 --- a/src/components/recruitments/apply/FileUploader.tsx +++ b/src/components/recruitments/apply/FileUploader.tsx @@ -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)); }; @@ -42,7 +55,10 @@ export default function FileUploader({ ref={fileRef} type="file" multiple={multiple} - onChange={addFileList} + onChange={(e)=>{ + addFileList(); + e.target.value = ""; + }} />
{