From 2a10438b4d4eb4bf4ed659daec8cea1e271369f9 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sat, 20 Apr 2024 14:40:06 -0500 Subject: [PATCH] feat: share from chat menu --- src/lib/components/chat/ShareChatModal.svelte | 16 +++++++++------- src/lib/components/common/Modal.svelte | 2 +- src/lib/components/icons/Share.svelte | 11 +++++++++++ src/lib/components/layout/Navbar.svelte | 2 +- src/lib/components/layout/Sidebar.svelte | 10 ++++++++++ .../components/layout/Sidebar/ChatMenu.svelte | 14 +++++++++++++- 6 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 src/lib/components/icons/Share.svelte diff --git a/src/lib/components/chat/ShareChatModal.svelte b/src/lib/components/chat/ShareChatModal.svelte index 1ef2d834e..96ff12cdf 100644 --- a/src/lib/components/chat/ShareChatModal.svelte +++ b/src/lib/components/chat/ShareChatModal.svelte @@ -3,12 +3,14 @@ import { toast } from 'svelte-sonner'; import { deleteSharedChatById, getChatById, shareChatById } from '$lib/apis/chats'; - import { chatId, modelfiles } from '$lib/stores'; + import { modelfiles } from '$lib/stores'; import { copyToClipboard } from '$lib/utils'; import Modal from '../common/Modal.svelte'; import Link from '../icons/Link.svelte'; + export let chatId; + let chat = null; let shareUrl = null; const i18n = getContext('i18n'); @@ -16,10 +18,10 @@ const shareLocalChat = async () => { const _chat = chat; - const sharedChat = await shareChatById(localStorage.token, $chatId); + const sharedChat = await shareChatById(localStorage.token, chatId); shareUrl = `${window.location.origin}/s/${sharedChat.id}`; console.log(shareUrl); - chat = await getChatById(localStorage.token, $chatId); + chat = await getChatById(localStorage.token, chatId); return shareUrl; }; @@ -57,8 +59,8 @@ $: if (show) { (async () => { - if ($chatId) { - chat = await getChatById(localStorage.token, $chatId); + if (chatId) { + chat = await getChatById(localStorage.token, chatId); } else { chat = null; console.log(chat); @@ -102,10 +104,10 @@ and create a new shared link. diff --git a/src/lib/components/common/Modal.svelte b/src/lib/components/common/Modal.svelte index 776bfaaf9..d817d67b3 100644 --- a/src/lib/components/common/Modal.svelte +++ b/src/lib/components/common/Modal.svelte @@ -47,7 +47,7 @@
{ show = false; diff --git a/src/lib/components/icons/Share.svelte b/src/lib/components/icons/Share.svelte new file mode 100644 index 000000000..f098995c6 --- /dev/null +++ b/src/lib/components/icons/Share.svelte @@ -0,0 +1,11 @@ + + + + + diff --git a/src/lib/components/layout/Navbar.svelte b/src/lib/components/layout/Navbar.svelte index 2f9a54b54..bce1e5dd6 100644 --- a/src/lib/components/layout/Navbar.svelte +++ b/src/lib/components/layout/Navbar.svelte @@ -25,7 +25,7 @@ let showDownloadChatModal = false; - +