refac: folder page chat list
This commit is contained in:
1 parent
e29c262394
commit
cd008eeb50
3 files changed
+51
-17
No files matched your search
@@ -13,11 +13,38 @@
|
||||
|
||||
let selectedTab = 'chats';
|
||||
|
||||
let chats = null;
|
||||
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 () => {
|
||||
chats = null;
|
||||
page = 1;
|
||||
allChatsLoaded = false;
|
||||
chatListLoading = false;
|
||||
|
||||
if (folder && folder.id) {
|
||||
const res = await getChatListByFolderId(localStorage.token, folder.id, page);
|
||||
@@ -71,7 +98,7 @@
|
||||
<FolderKnowledge />
|
||||
{:else if selectedTab === 'chats'}
|
||||
{#if chats !== null}
|
||||
<ChatList {chats} />
|
||||
<ChatList {chats} {chatListLoading} {allChatsLoaded} loadHandler={loadChats} />
|
||||
{:else}
|
||||
<div class="py-10">
|
||||
<Spinner />
|
||||
|
||||
Reference in new issue
Block a user