From 056709c8a53101c67a87fdfd698826458ccad813 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Wed, 22 Feb 2023 20:29:33 +0800 Subject: [PATCH] fix: fix bug if cannt get file then will throw error --- client/web/src/components/AvatarPicker.tsx | 3 +++ .../web/src/components/ChatBox/ChatInputBox/ChatDropArea.tsx | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/client/web/src/components/AvatarPicker.tsx b/client/web/src/components/AvatarPicker.tsx index 81ed343b..3fb75183 100644 --- a/client/web/src/components/AvatarPicker.tsx +++ b/client/web/src/components/AvatarPicker.tsx @@ -30,6 +30,9 @@ export const AvatarPicker: React.FC = React.memo((props) => { const handleSelectFile = (e: React.ChangeEvent) => { if (e.target.files && e.target.files.length > 0) { const pickedFile = e.target.files[0]; + if (!pickedFile) { + return; + } if (isGIF(pickedFile)) { updateAvatar(URL.createObjectURL(pickedFile)); diff --git a/client/web/src/components/ChatBox/ChatInputBox/ChatDropArea.tsx b/client/web/src/components/ChatBox/ChatInputBox/ChatDropArea.tsx index 1fe1bfce..3060217e 100644 --- a/client/web/src/components/ChatBox/ChatInputBox/ChatDropArea.tsx +++ b/client/web/src/components/ChatBox/ChatInputBox/ChatDropArea.tsx @@ -12,6 +12,10 @@ export const ChatDropArea: React.FC = React.memo(() => { const handleDrop = useMemoizedFn((files: File[]) => { const file = files[0]; + if (!file) { + return; + } + if (file.type.startsWith('image/')) { // 发送图片 uploadMessageImage(file).then(({ url, width, height }) => {