forked from open-webui/open-webui
		
	refac: optimisation
This commit is contained in:
		
							parent
							
								
									3fa7718fa1
								
							
						
					
					
						commit
						5beff6d5f7
					
				
					 1 changed files with 22 additions and 28 deletions
				
			
		|  | @ -29,34 +29,26 @@ | |||
| 	let showDropdown = false; | ||||
| 
 | ||||
| 	onMount(async () => { | ||||
|         if (window.innerWidth > 1280) { | ||||
|             show = true; | ||||
|         } | ||||
| 		if (window.innerWidth > 1280) { | ||||
| 			show = true; | ||||
| 		} | ||||
| 		await chats.set(await getChatList(localStorage.token)); | ||||
| 	}); | ||||
| 
 | ||||
|         const chatList = await getChatList(localStorage.token); | ||||
|         await enrichChatsWithContent(chatList); | ||||
|     }); | ||||
| 
 | ||||
|     tags.subscribe(async (value) => { | ||||
|         if (value.length === 0) { | ||||
|             const chatList = await getChatList(localStorage.token); | ||||
|             await enrichChatsWithContent(chatList); | ||||
|         } | ||||
|     }); | ||||
| 
 | ||||
|     // 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 | ||||
|             if (chatDetails) { | ||||
|                 chat.chat = chatDetails.chat; // Assuming chatDetails.chat contains the chat content | ||||
|             } | ||||
|             return chat; | ||||
|         })); | ||||
| 
 | ||||
|         await chats.set(enrichedChats); | ||||
|     } | ||||
| 	// Helper function to fetch and add chat content to each chat | ||||
| 	const enrichChatsWithContent = async (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 | ||||
| 				if (chatDetails) { | ||||
| 					chat.chat = chatDetails.chat; // Assuming chatDetails.chat contains the chat content | ||||
| 				} | ||||
| 				return chat; | ||||
| 			}) | ||||
| 		); | ||||
| 
 | ||||
| 		await chats.set(enrichedChats); | ||||
| 	}; | ||||
| 
 | ||||
| 	const loadChat = async (id) => { | ||||
| 		goto(`/c/${id}`); | ||||
|  | @ -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" | ||||
| 						placeholder="Search" | ||||
| 						bind:value={search} | ||||
| 						on:focus={() => { | ||||
| 							enrichChatsWithContent($chats); | ||||
| 						}} | ||||
| 					/> | ||||
| 
 | ||||
| 					<!-- <div class="self-center pr-3 py-2  bg-gray-900"> | ||||
|  | @ -343,7 +338,7 @@ | |||
| 						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 => { | ||||
| 							contentMatches = chat.chat.messages.some((message) => { | ||||
| 								// Check if message.content exists and includes the search query | ||||
| 								return message.content && message.content.toLowerCase().includes(query); | ||||
| 							}); | ||||
|  | @ -352,7 +347,6 @@ | |||
| 						return title.includes(query) || contentMatches; | ||||
| 					} | ||||
| 				}) as chat, i} | ||||
| 
 | ||||
| 					<div class=" w-full pr-2 relative"> | ||||
| 						<button | ||||
| 							class=" w-full flex justify-between rounded-md px-3 py-2 hover:bg-gray-900 {chat.id === | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Timothy J. Baek
						Timothy J. Baek