Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
krishokr committed Sep 24, 2024
1 parent 2a5b823 commit 9e53a0b
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions ui/src/components/features/build-panel/components/files-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { Plus, SquarePlus } from "lucide-react";
import MultiSelect from "@/components/ui/multiselect";
import { useFiles, useUploadFile } from "@/data-provider/query-service";
import Spinner from "@/components/ui/spinner";
import { useEffect, useState } from "react";
import { ChangeEvent, ReactEventHandler, useEffect, useState } from "react";
import {
FormControl,
FormField,
Expand Down Expand Up @@ -96,6 +96,26 @@ export default function FilesDialog({ form, classNames }: TFilesDialog) {
}
};

const handleFileChange = (event: ChangeEvent<HTMLInputElement>) => {
if (event.target.files) {
const selectedFiles = Array.from(event.target.files);
const duplicateFiles = selectedFiles.filter((file) =>
files?.some(
(uploadedFile) =>
uploadedFile.filename === file.name &&
uploadedFile.bytes === file.size,
),
);
if (duplicateFiles.length > 0) {
return toast({
variant: "destructive",
title: "Cannot add duplicate files.",
});
}
setFileUpload(event.target.files[0]);
}
};

if (isLoading) return <Spinner />;

return (
Expand Down Expand Up @@ -148,23 +168,7 @@ export default function FilesDialog({ form, classNames }: TFilesDialog) {
type="file"
accept="image/*, application/pdf"
onChange={(event) => {
if (event.target.files) {
const selectedFiles = Array.from(event.target.files);
const duplicateFiles = selectedFiles.filter((file) =>
files?.some(
(uploadedFile) =>
uploadedFile.filename === file.name &&
uploadedFile.bytes === file.size,
),
);
if (duplicateFiles.length > 0) {
return toast({
variant: "destructive",
title: "Cannot add duplicate files."
})
}
setFileUpload(event.target.files[0]);
}
handleFileChange(event)
}}
/>
</div>
Expand Down

0 comments on commit 9e53a0b

Please sign in to comment.