refac: folder page chat list

This commit is contained in:
Timothy Jaeryang Baek 2025-11-23 20:11:55 -05:00
parent e29c262394
commit cd008eeb50
3 changed files with 51 additions and 17 deletions

View file

@ -218,7 +218,7 @@ async def get_chat_list_by_folder_id(
folder_id: str, page: Optional[int] = 1, user=Depends(get_verified_user) folder_id: str, page: Optional[int] = 1, user=Depends(get_verified_user)
): ):
try: try:
limit = 60 limit = 10
skip = (page - 1) * limit skip = (page - 1) * limit
return [ return [

View file

@ -7,11 +7,18 @@
import { getTimeRange } from '$lib/utils'; import { getTimeRange } from '$lib/utils';
import ChevronUp from '$lib/components/icons/ChevronUp.svelte'; import ChevronUp from '$lib/components/icons/ChevronUp.svelte';
import ChevronDown from '$lib/components/icons/ChevronDown.svelte'; import ChevronDown from '$lib/components/icons/ChevronDown.svelte';
import Loader from '$lib/components/common/Loader.svelte';
import Spinner from '$lib/components/common/Spinner.svelte';
dayjs.extend(localizedFormat); dayjs.extend(localizedFormat);
export let chats = []; export let chats = [];
export let chatListLoading = false;
export let allChatsLoaded = false;
export let loadHandler: Function = null;
let chatList = null; let chatList = null;
const init = async () => { const init = async () => {
@ -158,7 +165,7 @@
</a> </a>
{/each} {/each}
<!-- {#if !allChatsLoaded && loadHandler} {#if !allChatsLoaded && loadHandler}
<Loader <Loader
on:visible={(e) => { on:visible={(e) => {
if (!chatListLoading) { if (!chatListLoading) {
@ -171,6 +178,6 @@
<div class=" ">Loading...</div> <div class=" ">Loading...</div>
</div> </div>
</Loader> </Loader>
{/if} --> {/if}
</div> </div>
{/if} {/if}

View file

@ -13,11 +13,38 @@
let selectedTab = 'chats'; let selectedTab = 'chats';
let chats = null;
let page = 1; let page = 1;
let chats = null;
let chatListLoading = false;
let allChatsLoaded = false;
const loadChats = async () => {
chatListLoading = true;
page += 1;
let newChatList = [];
newChatList = await getChatListByFolderId(localStorage.token, folder.id, page).catch(
(error) => {
console.error(error);
return [];
}
);
// once the bottom of the list has been reached (no results) there is no need to continue querying
allChatsLoaded = newChatList.length === 0;
chats = [...chats, ...newChatList];
chatListLoading = false;
};
const setChatList = async () => { const setChatList = async () => {
chats = null; chats = null;
page = 1;
allChatsLoaded = false;
chatListLoading = false;
if (folder && folder.id) { if (folder && folder.id) {
const res = await getChatListByFolderId(localStorage.token, folder.id, page); const res = await getChatListByFolderId(localStorage.token, folder.id, page);
@ -71,7 +98,7 @@
<FolderKnowledge /> <FolderKnowledge />
{:else if selectedTab === 'chats'} {:else if selectedTab === 'chats'}
{#if chats !== null} {#if chats !== null}
<ChatList {chats} /> <ChatList {chats} {chatListLoading} {allChatsLoaded} loadHandler={loadChats} />
{:else} {:else}
<div class="py-10"> <div class="py-10">
<Spinner /> <Spinner />