Browse Source

fix: bug in chat deletion pagination interact

change 1: when selecting a tag to filter the `tagView` store is set to disable paginated loading. This is so all tagged items can be loaded at once.  deleting a tag when in the filtered view returns to the unfiltered view. this change now sets the `tagView` store to `false` so pagination can continue

change 2: formatting
Aryan Kothari 9 months ago
parent
commit
f9e1a933a9

+ 4 - 4
src/lib/components/chat/Chat.svelte

@@ -424,7 +424,7 @@
 					files: chatFiles
 				});
 				await chats.set(
-					await getChatList(localStorage.token, 0, ($pageSkip * $pageLimit) || $pageLimit)
+					await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit)
 				);
 			}
 		}
@@ -472,7 +472,7 @@
 					files: chatFiles
 				});
 				await chats.set(
-					await getChatList(localStorage.token, 0, ($pageSkip * $pageLimit) || $pageLimit)
+					await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit)
 				);
 			}
 		}
@@ -634,7 +634,7 @@
 					timestamp: Date.now()
 				});
 				await chats.set(
-					await getChatList(localStorage.token, 0, ($pageSkip * $pageLimit) || $pageLimit)
+					await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit)
 				);
 				await chatId.set(chat.id);
 			} else {
@@ -711,7 +711,7 @@
 			})
 		);
 
-		await chats.set(await getChatList(localStorage.token, 0, ($pageSkip * $pageLimit) || $pageLimit));
+		await chats.set(await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit));
 
 		return _responses;
 	};

+ 1 - 1
src/lib/components/chat/Messages.svelte

@@ -90,7 +90,7 @@
 			history: history
 		});
 
-		await chats.set(await getChatList(localStorage.token, 0, ($pageSkip * $pageLimit) || $pageLimit));
+		await chats.set(await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit));
 	};
 
 	const confirmEditResponseMessage = async (messageId, content) => {

+ 4 - 9
src/lib/components/chat/Tags.svelte

@@ -8,7 +8,7 @@
 		getTagsById,
 		updateChatById
 	} from '$lib/apis/chats';
-	import { tags as _tags, chats, pinnedChats, pageSkip, pageLimit } from '$lib/stores';
+	import { tags as _tags, chats, pinnedChats, pageSkip, pageLimit, tagView } from '$lib/stores';
 	import { createEventDispatcher, onMount } from 'svelte';
 
 	const dispatch = createEventDispatcher();
@@ -46,20 +46,14 @@
 			tags: tags
 		});
 
-		console.log($_tags);
-
 		await _tags.set(await getAllChatTags(localStorage.token));
 
-		console.log($_tags);
-		console.log('this run !!!!!');
-		console.log($_tags);
-
 		if ($_tags.map((t) => t.name).includes(tagName)) {
 			if (tagName === 'pinned') {
 				await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
 			} else {
 				await chats.set(
-					await getChatList(localStorage.token, 0, ($pageSkip * $pageLimit) || $pageLimit)
+					await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit)
 				);
 			}
 
@@ -68,10 +62,11 @@
 			}
 		} else {
 			await chats.set(
-				await getChatList(localStorage.token, 0, ($pageSkip * $pageLimit) || $pageLimit)
+				await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit)
 			);
 			await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
 		}
+		tagView.set(false);
 	};
 
 	onMount(async () => {

+ 11 - 4
src/lib/components/layout/Sidebar.svelte

@@ -14,7 +14,8 @@
 		pinnedChats,
 		pageSkip,
 		pageLimit,
-		scrollPaginationEnabled
+		scrollPaginationEnabled,
+		tagView
 	} from '$lib/stores';
 	import { onMount, getContext, tick } from 'svelte';
 
@@ -54,7 +55,6 @@
 	let filteredChatList = [];
 	let paginationScrollThreashold = 0.6;
 	let nextPageLoading = false;
-	let tagView = false;
 	let chatPagniationComplete = false;
 	// number of chats per page depends on screen size.
 	// 35px is the height of each chat item.
@@ -251,6 +251,13 @@
 		<h1 class="text-red-400 text-bold text-xl">
 			Chats loaded: {$chats.length}
 		</h1>
+
+		<h1 class="text-red-400 text-bold text-xl">
+			Pagination Enabled: {$scrollPaginationEnabled}
+		</h1>
+		<h1 class="text-red-400 text-bold text-xl">
+			Final Page Reached: {chatPagniationComplete}
+		</h1>
 		<div class="px-2.5 flex justify-between space-x-1 text-gray-600 dark:text-gray-400">
 			<a
 				id="sidebar-new-chat-button"
@@ -474,7 +481,7 @@
 										$pageLimit
 									);
 								}
-								tagView = true;
+								tagView.set(true);
 								await chats.set(chatIds);
 							}}
 						>
@@ -520,7 +527,7 @@
 				class="pl-2 my-2 flex-1 flex flex-col space-y-1 overflow-y-auto scrollbar-hidden"
 				on:scroll={async (e) => {
 					if (!$scrollPaginationEnabled) return;
-					if (tagView) return;
+					if ($tagView) return;
 					if (nextPageLoading) return;
 					if (chatPagniationComplete) return;
 

+ 3 - 3
src/lib/components/layout/Sidebar/ChatItem.svelte

@@ -49,7 +49,7 @@
 				title: _title
 			});
 			await chats.set(
-				await getChatList(localStorage.token, 0, ($pageSkip * $pageLimit) || $pageLimit)
+				await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit)
 			);
 			await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
 		}
@@ -64,7 +64,7 @@
 		if (res) {
 			goto(`/c/${res.id}`);
 			await chats.set(
-				await getChatList(localStorage.token, 0, ($pageSkip * $pageLimit) || $pageLimit)
+				await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit)
 			);
 			await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
 		}
@@ -72,7 +72,7 @@
 
 	const archiveChatHandler = async (id) => {
 		await archiveChatById(localStorage.token, id);
-		await chats.set(await getChatList(localStorage.token, 0, ($pageSkip * $pageLimit) || $pageLimit));
+		await chats.set(await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit));
 		await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
 	};
 

+ 1 - 0
src/lib/stores/index.ts

@@ -44,6 +44,7 @@ export const showCallOverlay = writable(false);
 export const scrollPaginationEnabled = writable(true);
 export const pageSkip = writable(0);
 export const pageLimit = writable(-1);
+export const tagView = writable(false);
 
 export type Model = OpenAIModel | OllamaModel;