This commit is contained in:
Timothy Jaeryang Baek 2025-07-31 16:27:20 +04:00
parent d3547f0f54
commit 1c83f48c45

View file

@ -114,59 +114,66 @@
} else { } else {
// Handle the drag-and-drop data for folders or chats (same as before) // Handle the drag-and-drop data for folders or chats (same as before)
const dataTransfer = e.dataTransfer.getData('text/plain'); const dataTransfer = e.dataTransfer.getData('text/plain');
const data = JSON.parse(dataTransfer);
console.log(data);
const { type, id, item } = data; try {
const data = JSON.parse(dataTransfer);
console.log(data);
if (type === 'folder') { const { type, id, item } = data;
open = true;
if (id === folderId) { if (type === 'folder') {
return; open = true;
} if (id === folderId) {
// Move the folder return;
const res = await updateFolderParentIdById(localStorage.token, id, folderId).catch(
(error) => {
toast.error(`${error}`);
return null;
} }
); // Move the folder
const res = await updateFolderParentIdById(localStorage.token, id, folderId).catch(
(error) => {
toast.error(`${error}`);
return null;
}
);
if (res) { if (res) {
dispatch('update'); dispatch('update');
} }
} else if (type === 'chat') { } else if (type === 'chat') {
open = true; open = true;
let chat = await getChatById(localStorage.token, id).catch((error) => { let chat = await getChatById(localStorage.token, id).catch((error) => {
return null; return null;
}); });
if (!chat && item) { if (!chat && item) {
chat = await importChat( chat = await importChat(
localStorage.token,
item.chat,
item?.meta ?? {},
false,
null,
item?.created_at ?? null,
item?.updated_at ?? null
).catch((error) => {
toast.error(`${error}`);
return null;
});
}
// Move the chat
const res = await updateChatFolderIdById(
localStorage.token, localStorage.token,
item.chat, chat.id,
item?.meta ?? {}, folderId
false,
null,
item?.created_at ?? null,
item?.updated_at ?? null
).catch((error) => { ).catch((error) => {
toast.error(`${error}`); toast.error(`${error}`);
return null; return null;
}); });
}
// Move the chat if (res) {
const res = await updateChatFolderIdById(localStorage.token, chat.id, folderId).catch( dispatch('update');
(error) => {
toast.error(`${error}`);
return null;
} }
);
if (res) {
dispatch('update');
} }
} catch (error) {
console.log('Error parsing dataTransfer:', error);
} }
} }
} }