refac: dragged overlay behaviour to only activate for files

This commit is contained in:
Timothy J. Baek 2024-10-14 21:03:55 -07:00
parent f8bb77324d
commit 93dab86e8d
4 changed files with 23 additions and 20 deletions

View File

@ -184,7 +184,13 @@
const onDragOver = (e) => { const onDragOver = (e) => {
e.preventDefault(); e.preventDefault();
// Check if a file is being dragged.
if (e.dataTransfer?.types?.includes('Files')) {
dragged = true; dragged = true;
} else {
dragged = false;
}
}; };
const onDragLeave = () => { const onDragLeave = () => {
@ -200,8 +206,6 @@
if (inputFiles && inputFiles.length > 0) { if (inputFiles && inputFiles.length > 0) {
console.log(inputFiles); console.log(inputFiles);
inputFilesHandler(inputFiles); inputFilesHandler(inputFiles);
} else {
toast.error($i18n.t(`File not found.`));
} }
} }

View File

@ -177,14 +177,8 @@
const tagEventHandler = async (type, tagName, chatId) => { const tagEventHandler = async (type, tagName, chatId) => {
console.log(type, tagName, chatId); console.log(type, tagName, chatId);
if (type === 'delete') { if (type === 'delete') {
if (selectedTagName === tagName) { currentChatPage.set(1);
if ($tags.map((t) => t.name).includes(tagName)) { await chats.set(await getChatListBySearchText(localStorage.token, search));
await chats.set(await getChatListByTagName(localStorage.token, tagName));
} else {
selectedTagName = null;
await initChatList();
}
}
} }
}; };
@ -192,7 +186,13 @@
const onDragOver = (e) => { const onDragOver = (e) => {
e.preventDefault(); e.preventDefault();
// Check if a file is being dragged.
if (e.dataTransfer?.types?.includes('Files')) {
dragged = true; dragged = true;
} else {
dragged = false;
}
}; };
const onDragLeave = () => { const onDragLeave = () => {
@ -201,19 +201,19 @@
const onDrop = async (e) => { const onDrop = async (e) => {
e.preventDefault(); e.preventDefault();
console.log(e); console.log(e); // Log the drop event
// Perform file drop check and handle it accordingly
if (e.dataTransfer?.files) { if (e.dataTransfer?.files) {
const inputFiles = Array.from(e.dataTransfer?.files); const inputFiles = Array.from(e.dataTransfer?.files);
if (inputFiles && inputFiles.length > 0) { if (inputFiles && inputFiles.length > 0) {
console.log(inputFiles); console.log(inputFiles); // Log the dropped files
inputFilesHandler(inputFiles); inputFilesHandler(inputFiles); // Handle the dropped files
} else {
toast.error($i18n.t(`File not found.`));
} }
} }
dragged = false; dragged = false; // Reset dragged status after drop
}; };
let touchstart; let touchstart;

View File

@ -90,7 +90,7 @@
<ShareChatModal bind:show={showShareChatModal} chatId={chat.id} /> <ShareChatModal bind:show={showShareChatModal} chatId={chat.id} />
<div class=" w-full pr-2 relative group"> <div class=" w-full pr-2 relative group" draggable="true">
{#if confirmEdit} {#if confirmEdit}
<div <div
class=" w-full flex justify-between rounded-xl px-3 py-2 {chat.id === $chatId || confirmEdit class=" w-full flex justify-between rounded-xl px-3 py-2 {chat.id === $chatId || confirmEdit

View File

@ -146,7 +146,6 @@
type: 'delete', type: 'delete',
name: e.detail.name name: e.detail.name
}); });
show = false;
}} }}
on:close={() => { on:close={() => {
show = false; show = false;