This commit is contained in:
Timothy Jaeryang Baek
2026-06-15 23:42:29 +02:00
parent c783fd30f2
commit 45fcf272ef
11 changed files with 474 additions and 66 deletions
@@ -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 = [];
@@ -20,6 +20,7 @@
import { getChatsByFolderId } from '$lib/apis/chats';
import FolderModal from '$lib/components/layout/Sidebar/Folders/FolderModal.svelte';
import FolderShareModal from '$lib/components/layout/Sidebar/Folders/FolderShareModal.svelte';
import Folder from '$lib/components/icons/Folder.svelte';
import XMark from '$lib/components/icons/XMark.svelte';
@@ -36,6 +37,7 @@
let showFolderModal = false;
let showCreateSubFolderModal = false;
let showShareModal = false;
let showDeleteConfirm = false;
let deleteFolderContents = true;
@@ -173,6 +175,8 @@
onSubmit={createSubFolderHandler}
/>
<FolderShareModal bind:show={showShareModal} {folder} />
<DeleteConfirmDialog
bind:show={showDeleteConfirm}
title={$i18n.t('Delete folder?')}
@@ -232,6 +236,9 @@
onEdit={() => {
showFolderModal = true;
}}
onShare={() => {
showShareModal = true;
}}
onDelete={() => {
showDeleteConfirm = true;
}}