diff --git a/src/lib/apis/chats/index.ts b/src/lib/apis/chats/index.ts index 05a707cd4..a72b51939 100644 --- a/src/lib/apis/chats/index.ts +++ b/src/lib/apis/chats/index.ts @@ -1,4 +1,5 @@ import { WEBUI_API_BASE_URL } from '$lib/constants'; +import { getTimeRange } from '$lib/utils'; export const createNewChat = async (token: string, chat: object) => { let error = null; @@ -59,7 +60,10 @@ export const getChatList = async (token: string = '') => { throw error; } - return res; + return res.map((chat) => ({ + ...chat, + time_range: getTimeRange(chat.updated_at) + })); }; export const getChatListByUserId = async (token: string = '', userId: string) => { @@ -90,7 +94,10 @@ export const getChatListByUserId = async (token: string = '', userId: string) => throw error; } - return res; + return res.map((chat) => ({ + ...chat, + time_range: getTimeRange(chat.updated_at) + })); }; export const getArchivedChatList = async (token: string = '') => { @@ -248,7 +255,10 @@ export const getChatListByTagName = async (token: string = '', tagName: string) throw error; } - return res; + return res.map((chat) => ({ + ...chat, + time_range: getTimeRange(chat.updated_at) + })); }; export const getChatById = async (token: string, id: string) => { diff --git a/src/lib/components/layout/Sidebar.svelte b/src/lib/components/layout/Sidebar.svelte index 8c15cf516..dcafd527f 100644 --- a/src/lib/components/layout/Sidebar.svelte +++ b/src/lib/components/layout/Sidebar.svelte @@ -44,6 +44,28 @@ let showDropdown = false; let isEditing = false; + let filteredChatList = []; + + $: filteredChatList = $chats.filter((chat) => { + if (search === '') { + return true; + } else { + let title = chat.title.toLowerCase(); + const query = search.toLowerCase(); + + let contentMatches = false; + // Access the messages within chat.chat.messages + if (chat.chat && chat.chat.messages && Array.isArray(chat.chat.messages)) { + contentMatches = chat.chat.messages.some((message) => { + // Check if message.content exists and includes the search query + return message.content && message.content.toLowerCase().includes(query); + }); + } + + return title.includes(query) || contentMatches; + } + }); + onMount(async () => { showSidebar.set(window.innerWidth > BREAKPOINT); await chats.set(await getChatList(localStorage.token)); @@ -418,25 +440,17 @@ {/if}