Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
5beff6d5
"git@developer.sourcefind.cn:OpenDAS/ollama.git" did not exist on "f84537e0e05f091736c6be2dff8622b01a8c973d"
Commit
5beff6d5
authored
Feb 07, 2024
by
Timothy J. Baek
Browse files
refac: optimisation
parent
3fa7718f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
30 deletions
+24
-30
src/lib/components/layout/Sidebar.svelte
src/lib/components/layout/Sidebar.svelte
+24
-30
No files found.
src/lib/components/layout/Sidebar.svelte
View file @
5beff6d5
...
@@ -29,34 +29,26 @@
...
@@ -29,34 +29,26 @@
let showDropdown = false;
let showDropdown = false;
onMount(async () => {
onMount(async () => {
if
(
window
.
innerWidth
>
1280
)
{
if (window.innerWidth > 1280) {
show
=
true
;
show = true;
}
}
await chats.set(await getChatList(localStorage.token));
const
chatList
=
await
getChatList
(
localStorage
.
token
);
});
await
enrichChatsWithContent
(
chatList
);
});
// Helper function to fetch and add chat content to each chat
const enrichChatsWithContent = async (chatList) => {
tags
.
subscribe
(
async
(
value
)
=>
{
const enrichedChats = await Promise.all(
if
(
value
.
length
===
0
)
{
chatList.map(async (chat) => {
const
chatList
=
await
getChatList
(
localStorage
.
token
);
const chatDetails = await getChatById(localStorage.token, chat.id).catch((error) => null); // Handle error or non-existent chat gracefully
await
enrichChatsWithContent
(
chatList
);
if (chatDetails) {
}
chat.chat = chatDetails.chat; // Assuming chatDetails.chat contains the chat content
});
}
return chat;
// Helper function to fetch and add chat content to each chat
})
async
function
enrichChatsWithContent
(
chatList
)
{
);
const
enrichedChats
=
await
Promise
.
all
(
chatList
.
map
(
async
(
chat
)
=>
{
const
chatDetails
=
await
getChatById
(
localStorage
.
token
,
chat
.
id
).
catch
(
error
=>
null
);
// Handle error or non-existent chat gracefully
await chats.set(enrichedChats);
if
(
chatDetails
)
{
};
chat
.
chat
=
chatDetails
.
chat
;
// Assuming chatDetails.chat contains the chat content
}
return
chat
;
}));
await
chats
.
set
(
enrichedChats
);
}
const loadChat = async (id) => {
const loadChat = async (id) => {
goto(`/c/${id}`);
goto(`/c/${id}`);
...
@@ -288,6 +280,9 @@
...
@@ -288,6 +280,9 @@
class="w-full rounded-r py-1.5 pl-2.5 pr-4 text-sm text-gray-300 bg-gray-950 outline-none"
class="w-full rounded-r py-1.5 pl-2.5 pr-4 text-sm text-gray-300 bg-gray-950 outline-none"
placeholder="Search"
placeholder="Search"
bind:value={search}
bind:value={search}
on:focus={() => {
enrichChatsWithContent($chats);
}}
/>
/>
<!-- <div class="self-center pr-3 py-2 bg-gray-900">
<!-- <div class="self-center pr-3 py-2 bg-gray-900">
...
@@ -343,7 +338,7 @@
...
@@ -343,7 +338,7 @@
let contentMatches = false;
let contentMatches = false;
// Access the messages within chat.chat.messages
// Access the messages within chat.chat.messages
if (chat.chat && chat.chat.messages && Array.isArray(chat.chat.messages)) {
if (chat.chat && chat.chat.messages && Array.isArray(chat.chat.messages)) {
contentMatches = chat.chat.messages.some(message => {
contentMatches = chat.chat.messages.some(
(
message
)
=> {
// Check if message.content exists and includes the search query
// Check if message.content exists and includes the search query
return message.content && message.content.toLowerCase().includes(query);
return message.content && message.content.toLowerCase().includes(query);
});
});
...
@@ -352,7 +347,6 @@
...
@@ -352,7 +347,6 @@
return title.includes(query) || contentMatches;
return title.includes(query) || contentMatches;
}
}
}) as chat, i}
}) as chat, i}
<div class=" w-full pr-2 relative">
<div class=" w-full pr-2 relative">
<button
<button
class=" w-full flex justify-between rounded-md px-3 py-2 hover:bg-gray-900 {chat.id ===
class=" w-full flex justify-between rounded-md px-3 py-2 hover:bg-gray-900 {chat.id ===
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment