From 7ba98ad49853f3cbf8c3339b0a8ea303eb93dadd Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Fri, 14 Jun 2024 13:02:07 -0700 Subject: [PATCH] feat: chat item shift shorcut --- src/lib/components/chat/Chat.svelte | 9 +- src/lib/components/layout/Sidebar.svelte | 22 +++ .../components/layout/Sidebar/ChatItem.svelte | 136 ++++++++++++------ 3 files changed, 119 insertions(+), 48 deletions(-) diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index c9ee74aa2..73b480796 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -111,7 +111,8 @@ $: if (chatIdProp) { (async () => { - if (await loadChat()) { + console.log(chatIdProp); + if (chatIdProp && (await loadChat())) { await tick(); loaded = true; @@ -126,7 +127,11 @@ onMount(async () => { if (!$chatId) { - await initNewChat(); + chatId.subscribe(async (value) => { + if (!value) { + await initNewChat(); + } + }); } else { if (!($settings.saveChatHistory ?? true)) { await goto('/'); diff --git a/src/lib/components/layout/Sidebar.svelte b/src/lib/components/layout/Sidebar.svelte index 8d13c7efb..3b32e6016 100644 --- a/src/lib/components/layout/Sidebar.svelte +++ b/src/lib/components/layout/Sidebar.svelte @@ -38,7 +38,10 @@ let navElement; let search = ''; + let shiftKey = false; + let selectedChatId = null; + let showDropdown = false; let filteredChatList = []; @@ -102,10 +105,28 @@ checkDirection(); }; + const onKeyDown = (e) => { + if (e.key === 'Shift') { + shiftKey = true; + } + }; + + const onKeyUp = (e) => { + if (e.key === 'Shift') { + shiftKey = false; + } + }; + + document.addEventListener('keydown', onKeyDown); + document.addEventListener('keyup', onKeyUp); + window.addEventListener('touchstart', onTouchStart); window.addEventListener('touchend', onTouchEnd); return () => { + window.removeEventListener('keydown', onKeyDown); + window.removeEventListener('keyup', onKeyUp); + window.removeEventListener('touchstart', onTouchStart); window.removeEventListener('touchend', onTouchEnd); }; @@ -407,6 +428,7 @@ { selectedChatId = chat.id; diff --git a/src/lib/components/layout/Sidebar/ChatItem.svelte b/src/lib/components/layout/Sidebar/ChatItem.svelte index 6a5c5b3ba..1273def18 100644 --- a/src/lib/components/layout/Sidebar/ChatItem.svelte +++ b/src/lib/components/layout/Sidebar/ChatItem.svelte @@ -1,7 +1,7 @@