From 9feb127201b8563bc35b5cc20f5d654e1801bab0 Mon Sep 17 00:00:00 2001 From: Nayam Amarshe <25067102+NayamAmarshe@users.noreply.github.com> Date: Fri, 4 Oct 2024 14:44:54 +0530 Subject: [PATCH] Update handlePaste --- renderer/components/main-content/index.tsx | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/renderer/components/main-content/index.tsx b/renderer/components/main-content/index.tsx index 5a6ac25..44298b9 100644 --- a/renderer/components/main-content/index.tsx +++ b/renderer/components/main-content/index.tsx @@ -165,9 +165,18 @@ const MainContent = ({ const handlePaste = (e: React.ClipboardEvent) => { resetImagePaths(); e.preventDefault(); - const type = e.clipboardData.items[0].type; - const filePath = e.clipboardData.files[0].path; - const extension = e.clipboardData.files[0].name.split(".").at(-1); + const items = e.clipboardData.items; + const files = e.clipboardData.files; + if (items.length === 0 || files.length === 0) { + toast({ + title: t("ERRORS.INVALID_IMAGE_ERROR.TITLE"), + description: t("ERRORS.INVALID_IMAGE_ERROR.ADDITIONAL_DESCRIPTION"), + }); + return; + } + const type = items[0].type; + const filePath = files[0].path; + const extension = files[0].name.split(".").at(-1); logit("📋 Pasted file: ", JSON.stringify({ type, filePath, extension })); if ( !type.includes("image") &&