From 6d78d9ed643296b6dfa6ab3ffd0ae5295a46243a Mon Sep 17 00:00:00 2001 From: enes Date: Tue, 17 Sep 2024 17:56:53 +0200 Subject: [PATCH] fix(create): uploading file adds to the existing file list, dedupe file list Closes #184 --- src/pages/create/index.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/pages/create/index.tsx b/src/pages/create/index.tsx index dd17450..7f39b11 100644 --- a/src/pages/create/index.tsx +++ b/src/pages/create/index.tsx @@ -301,7 +301,15 @@ export const CreatePage = () => { const handleSelectFiles = (event: React.ChangeEvent) => { if (event.target.files) { - setSelectedFiles(Array.from(event.target.files)) + // Get the uploaded files + const files = Array.from(event.target.files) + + // Remove duplicates based on the file.name + setSelectedFiles((p) => + [...p, ...files].filter( + (file, i, array) => i === array.findIndex((t) => t.name === file.name) + ) + ) } }