From 93dab86e8d19c7023b5b72a908b9177f3164d0b9 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Mon, 14 Oct 2024 21:03:55 -0700 Subject: [PATCH] refac: dragged overlay behaviour to only activate for files --- src/lib/components/chat/MessageInput.svelte | 10 +++++-- src/lib/components/layout/Sidebar.svelte | 30 +++++++++---------- .../components/layout/Sidebar/ChatItem.svelte | 2 +- .../components/layout/Sidebar/ChatMenu.svelte | 1 - 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/lib/components/chat/MessageInput.svelte b/src/lib/components/chat/MessageInput.svelte index dc4fcdf55..50b8f1a72 100644 --- a/src/lib/components/chat/MessageInput.svelte +++ b/src/lib/components/chat/MessageInput.svelte @@ -184,7 +184,13 @@ const onDragOver = (e) => { e.preventDefault(); - dragged = true; + + // Check if a file is being dragged. + if (e.dataTransfer?.types?.includes('Files')) { + dragged = true; + } else { + dragged = false; + } }; const onDragLeave = () => { @@ -200,8 +206,6 @@ if (inputFiles && inputFiles.length > 0) { console.log(inputFiles); inputFilesHandler(inputFiles); - } else { - toast.error($i18n.t(`File not found.`)); } } diff --git a/src/lib/components/layout/Sidebar.svelte b/src/lib/components/layout/Sidebar.svelte index 0caadd649..e8588ced8 100644 --- a/src/lib/components/layout/Sidebar.svelte +++ b/src/lib/components/layout/Sidebar.svelte @@ -177,14 +177,8 @@ const tagEventHandler = async (type, tagName, chatId) => { console.log(type, tagName, chatId); if (type === 'delete') { - if (selectedTagName === tagName) { - if ($tags.map((t) => t.name).includes(tagName)) { - await chats.set(await getChatListByTagName(localStorage.token, tagName)); - } else { - selectedTagName = null; - await initChatList(); - } - } + currentChatPage.set(1); + await chats.set(await getChatListBySearchText(localStorage.token, search)); } }; @@ -192,7 +186,13 @@ const onDragOver = (e) => { e.preventDefault(); - dragged = true; + + // Check if a file is being dragged. + if (e.dataTransfer?.types?.includes('Files')) { + dragged = true; + } else { + dragged = false; + } }; const onDragLeave = () => { @@ -201,19 +201,19 @@ const onDrop = async (e) => { e.preventDefault(); - console.log(e); + console.log(e); // Log the drop event + // Perform file drop check and handle it accordingly if (e.dataTransfer?.files) { const inputFiles = Array.from(e.dataTransfer?.files); + if (inputFiles && inputFiles.length > 0) { - console.log(inputFiles); - inputFilesHandler(inputFiles); - } else { - toast.error($i18n.t(`File not found.`)); + console.log(inputFiles); // Log the dropped files + inputFilesHandler(inputFiles); // Handle the dropped files } } - dragged = false; + dragged = false; // Reset dragged status after drop }; let touchstart; diff --git a/src/lib/components/layout/Sidebar/ChatItem.svelte b/src/lib/components/layout/Sidebar/ChatItem.svelte index 23a168ed3..8356b24cc 100644 --- a/src/lib/components/layout/Sidebar/ChatItem.svelte +++ b/src/lib/components/layout/Sidebar/ChatItem.svelte @@ -90,7 +90,7 @@ -
+
{#if confirmEdit}