Skip to content

Commit

Permalink
Merge branch 'develop' into issues/8691-add-better-serchui
Browse files Browse the repository at this point in the history
  • Loading branch information
gigincg authored Oct 25, 2024
2 parents 67c8fcf + c62b36d commit 49ae4dd
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/components/Common/AvatarEditModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const VideoConstraints = {
},
} as const;

const isImageFile = (file?: File) => file?.type.split("/")[0] === "image";

type IVideoConstraint =
(typeof VideoConstraints)[keyof typeof VideoConstraints];

Expand Down Expand Up @@ -87,19 +89,20 @@ const AvatarEditModal = ({
};

useEffect(() => {
if (selectedFile) {
const objectUrl = URL.createObjectURL(selectedFile);
setPreview(objectUrl);
return () => URL.revokeObjectURL(objectUrl);
if (!isImageFile(selectedFile)) {
return;
}
const objectUrl = URL.createObjectURL(selectedFile!);
setPreview(objectUrl);
return () => URL.revokeObjectURL(objectUrl);
}, [selectedFile]);

const onSelectFile: ChangeEventHandler<HTMLInputElement> = (e) => {
if (!e.target.files || e.target.files.length === 0) {
setSelectedFile(undefined);
return;
}
if (e.target.files[0]?.type.split("/")[0] !== "image") {
if (!isImageFile(e.target.files[0])) {
Warn({ msg: "Please upload an image file!" });
return;
}
Expand Down Expand Up @@ -134,7 +137,7 @@ const AvatarEditModal = ({
dragProps.setDragOver(false);
setIsDragging(false);
const droppedFile = e?.dataTransfer?.files[0];
if (droppedFile.type.split("/")[0] !== "image")
if (!isImageFile(droppedFile))
return dragProps.setFileDropError("Please drop an image file to upload!");
setSelectedFile(droppedFile);
};
Expand Down

0 comments on commit 49ae4dd

Please sign in to comment.