refac
This commit is contained in:
@@ -169,6 +169,9 @@
|
||||
let chat = null;
|
||||
let tags = [];
|
||||
|
||||
// Read-only when viewing someone else's chat (e.g. via shared folder access)
|
||||
$: readOnly = chat != null && chat.user_id !== $user?.id;
|
||||
|
||||
let chatTasks = [];
|
||||
|
||||
let history = {
|
||||
@@ -3103,6 +3106,7 @@
|
||||
<Messages
|
||||
bind:this={messagesRef}
|
||||
chatId={$chatId}
|
||||
{readOnly}
|
||||
bind:history
|
||||
bind:autoScroll
|
||||
bind:prompt
|
||||
@@ -3126,7 +3130,16 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class=" pb-2 {dragged ? 'z-0' : 'z-10'}">
|
||||
{#if readOnly}
|
||||
<div class="pb-6 z-10">
|
||||
<div
|
||||
class="text-xs text-gray-400 dark:text-gray-500 text-center"
|
||||
>
|
||||
{$i18n.t('Read only')}
|
||||
</div>
|
||||
</div>
|
||||
{:else}
|
||||
<div class=" pb-2 {dragged ? 'z-0' : 'z-10'}">
|
||||
<MessageInput
|
||||
bind:this={messageInput}
|
||||
{history}
|
||||
@@ -3208,6 +3221,7 @@
|
||||
<!-- {$i18n.t('LLMs can make mistakes. Verify important information.')} -->
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
{:else}
|
||||
<div class="flex items-center h-full">
|
||||
<Placeholder
|
||||
|
||||
@@ -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;
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user