feat: airdrop chats between windows

This commit is contained in:
Timothy J. Baek
2024-10-26 21:25:48 -07:00
parent e6ca994c92
commit effcbd6301
4 changed files with 70 additions and 44 deletions

View File

@@ -11,6 +11,7 @@
cloneChatById,
deleteChatById,
getAllTags,
getChatById,
getChatList,
getChatListByTagName,
getPinnedChatList,
@@ -46,7 +47,21 @@
export let selected = false;
export let shiftKey = false;
let chat = null;
let mouseOver = false;
let draggable = false;
$: if (mouseOver) {
loadChat();
}
const loadChat = async () => {
if (!chat) {
draggable = false;
chat = await getChatById(localStorage.token, id);
draggable = true;
}
};
let showShareChatModal = false;
let confirmEdit = false;
@@ -133,7 +148,8 @@
'text/plain',
JSON.stringify({
type: 'chat',
id: id
id: id,
item: chat
})
);
@@ -204,7 +220,7 @@
</DragGhost>
{/if}
<div bind:this={itemElement} class=" w-full {className} relative group" draggable="true">
<div bind:this={itemElement} class=" w-full {className} relative group" {draggable}>
{#if confirmEdit}
<div
class=" w-full flex justify-between rounded-lg px-[11px] py-[6px] {id === $chatId ||

View File

@@ -22,7 +22,12 @@
updateFolderParentIdById
} from '$lib/apis/folders';
import { toast } from 'svelte-sonner';
import { getChatsByFolderId, updateChatFolderIdById } from '$lib/apis/chats';
import {
getChatById,
getChatsByFolderId,
importChat,
updateChatFolderIdById
} from '$lib/apis/chats';
import ChatItem from './ChatItem.svelte';
import FolderMenu from './Folders/FolderMenu.svelte';
import DeleteConfirmDialog from '$lib/components/common/ConfirmDialog.svelte';
@@ -101,7 +106,7 @@
const data = JSON.parse(dataTransfer);
console.log(data);
const { type, id } = data;
const { type, id, item } = data;
if (type === 'folder') {
open = true;
@@ -122,8 +127,15 @@
} else if (type === 'chat') {
open = true;
let chat = await getChatById(localStorage.token, id).catch((error) => {
return null;
});
if (!chat && item) {
chat = await importChat(localStorage.token, item.chat, item?.meta ?? {});
}
// Move the chat
const res = await updateChatFolderIdById(localStorage.token, id, folderId).catch(
const res = await updateChatFolderIdById(localStorage.token, chat.id, folderId).catch(
(error) => {
toast.error(error);
return null;