From d069d1264d658adc5c2d9a80e9785a5c86559652 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Mon, 19 May 2025 01:39:33 +0400 Subject: [PATCH] feat: search modal --- src/lib/components/layout/SearchModal.svelte | 180 ++++++++++++++++++ src/lib/components/layout/Sidebar.svelte | 56 ++---- .../layout/Sidebar/SearchInput.svelte | 4 +- src/lib/stores/index.ts | 1 + src/routes/(app)/+layout.svelte | 10 +- 5 files changed, 212 insertions(+), 39 deletions(-) create mode 100644 src/lib/components/layout/SearchModal.svelte diff --git a/src/lib/components/layout/SearchModal.svelte b/src/lib/components/layout/SearchModal.svelte new file mode 100644 index 000000000..6ae2f2694 --- /dev/null +++ b/src/lib/components/layout/SearchModal.svelte @@ -0,0 +1,180 @@ + + + +
+
+ +
+ + + +
+ {#if chatList} + {#if chatList.length === 0} +
+ {$i18n.t('No results found')} +
+ {/if} + + {#each chatList as chat, idx} + {#if idx === 0 || (idx > 0 && chat.time_range !== chatList[idx - 1].time_range)} +
+ {$i18n.t(chat.time_range)} + +
+ {/if} + + { + show = false; + }} + > +
+
+ {chat?.title} +
+
+ +
+ {dayjs(chat?.updated_at * 1000).calendar()} +
+
+ {/each} + + {#if !allChatsLoaded} + { + if (!chatListLoading) { + loadMoreChats(); + } + }} + > +
+ +
Loading...
+
+
+ {/if} + {:else} +
+ +
+ {/if} +
+
+
diff --git a/src/lib/components/layout/Sidebar.svelte b/src/lib/components/layout/Sidebar.svelte index e9158a396..74b349c21 100644 --- a/src/lib/components/layout/Sidebar.svelte +++ b/src/lib/components/layout/Sidebar.svelte @@ -11,6 +11,7 @@ chatId, tags, showSidebar, + showSearch, mobile, showArchivedChats, pinnedChats, @@ -58,6 +59,8 @@ import ChannelItem from './Sidebar/ChannelItem.svelte'; import PencilSquare from '../icons/PencilSquare.svelte'; import Home from '../icons/Home.svelte'; + import MagnifyingGlass from '../icons/MagnifyingGlass.svelte'; + import SearchModal from './SearchModal.svelte'; const BREAKPOINT = 768; @@ -204,32 +207,6 @@ chatListLoading = false; }; - let searchDebounceTimeout; - - const searchDebounceHandler = async () => { - console.log('search', search); - chats.set(null); - - if (searchDebounceTimeout) { - clearTimeout(searchDebounceTimeout); - } - - if (search === '') { - await initChatList(); - return; - } else { - searchDebounceTimeout = setTimeout(async () => { - allChatsLoaded = false; - currentChatPage.set(1); - await chats.set(await getChatListBySearchText(localStorage.token, search)); - - if ($chats.length === 0) { - tags.set(await getAllTags(localStorage.token)); - } - }, 1000); - } - }; - const importChatHandler = async (items, pinned = false, folderId = null) => { console.log('importChatHandler', items, pinned, folderId); for (const item of items) { @@ -466,6 +443,8 @@ /> {/if} + +