This commit is contained in:
Timothy Jaeryang Baek committed 2026-06-15 23:42:29 +02:00
1 parent c783fd30f2
commit 45fcf272ef
11 files changed
+474 -66

No files matched your search

@@ -4,12 +4,15 @@
const i18n: Writable<any> = getContext('i18n');
import { user } from '$lib/stores';
import { fade } from 'svelte/transition';
import ChatList from './ChatList.svelte';
import FolderKnowledge from './FolderKnowledge.svelte';
import Spinner from '$lib/components/common/Spinner.svelte';
import { getChatListByFolderId } from '$lib/apis/chats';
import { getSharedFolderChats } from '$lib/apis/folders';
export let folder: any = null;
@@ -22,24 +25,8 @@
let allChatsLoaded = false;
const loadChats = async () => {
chatListLoading = true;
page += 1;
let newChatList: any[] = [];
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;
// getSharedFolderChats returns all users' chats in one shot; no pagination
allChatsLoaded = true;
};
const setChatList = async () => {
@@ -49,12 +36,21 @@
chatListLoading = false;
if (folder && folder.id) {
const res = await getChatListByFolderId(localStorage.token, folder.id, page);
if (res) {
chats = res;
// Always use the shared folder endpoint so owners also see
// chats created by users who have write access to this folder.
const res = await getSharedFolderChats(localStorage.token, folder.id).catch(
(error) => {
console.error(error);
return null;
}
);
if (res && res.chats) {
chats = res.chats;
allChatsLoaded = true;
} else {
chats = [];
// Fallback to regular API (e.g. if user has no shared access)
const fallback = await getChatListByFolderId(localStorage.token, folder.id, page).catch(() => []);
chats = fallback || [];
}
} else {
chats = [];