🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
fix: Drag stuck
Rene Wangf9595f0dfa77
diff --git a/src/app/[variants]/(main)/resource/(home)/index.tsx b/src/app/[variants]/(main)/resource/(home)/index.tsxindex 7ce05dc3325..60f28c1d8dd 100644--- a/src/app/[variants]/(main)/resource/(home)/index.tsx+++ b/src/app/[variants]/(main)/resource/(home)/index.tsx@@ -38,30 +38,34 @@ const ResourceHomePage = memo(() => {if (fileId) {setCurrentViewItemId(fileId);- // Check if it's a PDF file - check both file data and document data- const isPDF =- fileData?.fileType?.toLowerCase() === 'pdf' ||- fileData?.fileType?.toLowerCase() === 'application/pdf' ||- fileData?.name?.toLowerCase().endsWith('.pdf') ||- documentData?.fileType?.toLowerCase() === 'pdf' ||- documentData?.fileType?.toLowerCase() === 'application/pdf' ||- documentData?.filename?.toLowerCase().endsWith('.pdf');+ // Only determine mode when we have file data loaded+ // This prevents incorrect mode being set while data is loading+ if (fileData || documentData) {+ // Check if it's a PDF file - check both file data and document data+ const isPDF =+ fileData?.fileType?.toLowerCase() === 'pdf' ||+ fileData?.fileType?.toLowerCase() === 'application/pdf' ||+ fileData?.name?.toLowerCase().endsWith('.pdf') ||+ documentData?.fileType?.toLowerCase() === 'pdf' ||+ documentData?.fileType?.toLowerCase() === 'application/pdf' ||+ documentData?.filename?.toLowerCase().endsWith('.pdf');- // Check if it's a page/document- const isPage =- !isPDF &&- (fileData?.sourceType === 'document' ||- fileData?.fileType === 'custom/document' ||- !!documentData);+ // Check if it's a page/document+ const isPage =+ !isPDF &&+ (fileData?.sourceType === 'document' ||+ fileData?.fileType === 'custom/document' ||+ !!documentData);- // Determine mode based on file type- if (isPDF) {- // PDF files should always use editor mode for PDF viewer- setMode('editor');- } else if (isPage) {- setMode('page');- } else {- setMode('editor');+ // Determine mode based on file type+ if (isPDF) {+ // PDF files should always use editor mode for PDF viewer+ setMode('editor');+ } else if (isPage) {+ setMode('page');+ } else {+ setMode('editor');+ }}} else {// Reset to explorer mode when no file is selecteddiff --git a/src/app/[variants]/(main)/resource/features/DndContextWrapper.tsx b/src/app/[variants]/(main)/resource/features/DndContextWrapper.tsxindex 80eca62a915..c22bd018a35 100644--- a/src/app/[variants]/(main)/resource/features/DndContextWrapper.tsx+++ b/src/app/[variants]/(main)/resource/features/DndContextWrapper.tsx@@ -142,13 +142,23 @@ export const DndContextWrapper = memo<PropsWithChildren>(({ children }) => {return;}+ // Save current drag data before clearing state+ const draggedItemId = currentDrag.id;+ const draggedItemData = currentDrag.data;++ // Clear drag state immediately for better UX+ setCurrentDrag(null);++ // Show loading toast+ const hideLoading = message.loading(t('FileManager.actions.moving'), 0);+try {// Track source folder IDs before movingconst sourceFolderIds = new Set<string | null>();const pools = itemsToMove.map((id) => {const item = fileList.find((f) => f.id === id);- const itemData = item || (id === currentDrag.id ? currentDrag.data : null);+ const itemData = item || (id === draggedItemId ? draggedItemData : null);if (!itemData) return Promise.resolve();@@ -179,6 +189,8 @@ export const DndContextWrapper = memo<PropsWithChildren>(({ children }) => {await clearTreeFolderCache(libraryId);}+ // Hide loading and show success+ hideLoading();message.success(t('FileManager.actions.moveSuccess'));if (isDraggingSelection) {@@ -186,9 +198,9 @@ export const DndContextWrapper = memo<PropsWithChildren>(({ children }) => {}} catch (error) {console.error('Failed to move file:', error);+ // Hide loading and show error+ hideLoading();message.error(t('FileManager.actions.moveError'));- } finally {- setCurrentDrag(null);}};@@ -196,16 +208,24 @@ export const DndContextWrapper = memo<PropsWithChildren>(({ children }) => {event.preventDefault();};+ const handleDragEnd = () => {+ // Always clear drag state when drag ends, regardless of drop success+ // This ensures the overlay disappears immediately+ setCurrentDrag(null);+ };+document.addEventListener('dragstart', handleDragStart);document.addEventListener('drag', handleDrag);document.addEventListener('drop', handleDrop);document.addEventListener('dragover', handleDragOver);+ document.addEventListener('dragend', handleDragEnd);return () => {document.removeEventListener('dragstart', handleDragStart);document.removeEventListener('drag', handleDrag);document.removeEventListener('drop', handleDrop);document.removeEventListener('dragover', handleDragOver);+ document.removeEventListener('dragend', handleDragEnd);};}, [currentDrag,diff --git a/src/app/[variants]/(main)/resource/features/store/action.ts b/src/app/[variants]/(main)/resource/features/store/action.tsindex f0a60ea14d0..e3d5a9ec7b4 100644--- a/src/app/[variants]/(main)/resource/features/store/action.ts+++ b/src/app/[variants]/(main)/resource/features/store/action.ts@@ -246,8 +246,19 @@ export const store: CreateStore = (publicState) => (set, get) => ({set({ isTransitioning });},- setLibraryId: (libraryId) => {+ setLibraryId: async (libraryId) => {set({ libraryId });++ // Reset pagination state when switching libraries to prevent showing stale data+ set({+ fileListHasMore: false,+ fileListOffset: 0,+ });++ // Invalidate SWR cache to prevent showing stale data from previous library+ const { useFileStore } = await import('@/store/file');+ const fileStore = useFileStore.getState();+ await fileStore.refreshFileList();},setMode: (mode) => {diff --git a/src/app/[variants]/(main)/resource/library/index.tsx b/src/app/[variants]/(main)/resource/library/index.tsxindex 5bd7e7f3794..e333eb87c6b 100644--- a/src/app/[variants]/(main)/resource/library/index.tsx+++ b/src/app/[variants]/(main)/resource/library/index.tsx@@ -40,30 +40,34 @@ const MainContent = memo(() => {if (fileId) {setCurrentViewItemId(fileId);- // Check if it's a PDF file - check both file data and document data- const isPDF =- fileData?.fileType?.toLowerCase() === 'pdf' ||- fileData?.fileType?.toLowerCase() === 'application/pdf' ||- fileData?.name?.toLowerCase().endsWith('.pdf') ||- documentData?.fileType?.toLowerCase() === 'pdf' ||- documentData?.fileType?.toLowerCase() === 'application/pdf' ||- documentData?.filename?.toLowerCase().endsWith('.pdf');-- // Check if it's a page/document- const isPage =- !isPDF &&- (fileData?.sourceType === 'document' ||- fileData?.fileType === 'custom/document' ||- !!documentData);-- // Determine mode based on file type- if (isPDF) {- // PDF files should always use editor mode for PDF viewer- setMode('editor');- } else if (isPage) {- setMode('page');- } else {- setMode('editor');+ // Only determine mode when we have file data loaded+ // This prevents incorrect mode being set while data is loading+ if (fileData || documentData) {+ // Check if it's a PDF file - check both file data and document data+ const isPDF =+ fileData?.fileType?.toLowerCase() === 'pdf' ||+ fileData?.fileType?.toLowerCase() === 'application/pdf' ||+ fileData?.name?.toLowerCase().endsWith('.pdf') ||+ documentData?.fileType?.toLowerCase() === 'pdf' ||+ documentData?.fileType?.toLowerCase() === 'application/pdf' ||+ documentData?.filename?.toLowerCase().endsWith('.pdf');++ // Check if it's a page/document+ const isPage =+ !isPDF &&+ (fileData?.sourceType === 'document' ||+ fileData?.fileType === 'custom/document' ||+ !!documentData);++ // Determine mode based on file type+ if (isPDF) {+ // PDF files should always use editor mode for PDF viewer+ setMode('editor');+ } else if (isPage) {+ setMode('page');+ } else {+ setMode('editor');+ }}} else {// Reset to explorer mode when no file is selecteddiff --git a/src/features/ResourceManager/components/Editor/index.tsx b/src/features/ResourceManager/components/Editor/index.tsxindex f8997347022..927caffe98d 100644--- a/src/features/ResourceManager/components/Editor/index.tsx+++ b/src/features/ResourceManager/components/Editor/index.tsx@@ -22,14 +22,9 @@ import FileContent from './FileContent';const FileEditor = memo(() => {const { t } = useTranslation('common');- const [currentViewItemId, category, setMode, setCurrentViewItemId, libraryId] =- useResourceManagerStore((s) => [- s.currentViewItemId,- s.category,- s.setMode,- s.setCurrentViewItemId,- s.libraryId,- ]);+ const [currentViewItemId, category, setMode, setCurrentViewItemId] = useResourceManagerStore(+ (s) => [s.currentViewItemId, s.category, s.setMode, s.setCurrentViewItemId],+ );const fileDetail = useFileStore(fileManagerSelectors.getFileById(currentViewItemId));@@ -44,15 +39,10 @@ const FileEditor = memo(() => {setMode('explorer');setCurrentViewItemId(undefined);}}- size={'small'}title={t('back')}/><Flexbox align={'center'} style={{ marginLeft: 8 }}>- <Breadcrumb- category={category}- fileName={fileDetail?.name}- knowledgeBaseId={libraryId}- />+ <Breadcrumb category={category} fileName={fileDetail?.name} /></Flexbox></Flexbox>}diff --git a/src/features/ResourceManager/components/Explorer/Header/Breadcrumb.tsx b/src/features/ResourceManager/components/Explorer/Header/Breadcrumb.tsxindex 0767cdc1eb1..9cfdc2705ea 100644--- a/src/features/ResourceManager/components/Explorer/Header/Breadcrumb.tsx+++ b/src/features/ResourceManager/components/Explorer/Header/Breadcrumb.tsx@@ -45,7 +45,7 @@ interface FolderCrumb {slug: string;}-const Breadcrumb = memo<BreadcrumbProps>(({ category, knowledgeBaseId, fileName }) => {+const Breadcrumb = memo<BreadcrumbProps>(({ category, fileName }) => {const { t } = useTranslation('file');const navigate = useNavigate();const [searchParams] = useSearchParams();@@ -54,7 +54,7 @@ const Breadcrumb = memo<BreadcrumbProps>(({ category, knowledgeBaseId, fileNameconst setMode = useResourceManagerStore((s) => s.setMode);const setCurrentViewItemId = useResourceManagerStore((s) => s.setCurrentViewItemId);- const baseKnowledgeBaseId = knowledgeBaseId || currentKnowledgeBaseId;+ const baseKnowledgeBaseId = currentKnowledgeBaseId;const knowledgeBaseName = useKnowledgeBaseStore(knowledgeBaseSelectors.getKnowledgeBaseNameById(baseKnowledgeBaseId || ''),);diff --git a/src/locales/default/components.ts b/src/locales/default/components.tsindex c8ece614581..f10995ffec4 100644--- a/src/locales/default/components.ts+++ b/src/locales/default/components.ts@@ -35,6 +35,7 @@ export default {'FileManager.actions.moveSuccess': 'File moved successfully','FileManager.actions.moveToFolder': 'Move to...','FileManager.actions.moveToRoot': 'Move to root directory',+ 'FileManager.actions.moving': 'Moving...','FileManager.actions.removeFromKnowledgeBase': 'Remove from Library','FileManager.actions.removeFromKnowledgeBaseSuccess': 'File removed successfully.','FileManager.actions.rename': 'Rename',diff --git a/src/store/file/slices/fileManager/action.ts b/src/store/file/slices/fileManager/action.tsindex 0d782df33bd..7ac3d6100e5 100644--- a/src/store/file/slices/fileManager/action.ts+++ b/src/store/file/slices/fileManager/action.ts@@ -104,13 +104,16 @@ export const createFileManageSlice: StateCreator<offset: fileListOffset,});- const updatedFileList = [...fileList, ...response.items];+ // Deduplicate items by ID to prevent duplicate items at page boundaries+ const existingIds = new Set(fileList.map((item) => item.id));+ const newItems = response.items.filter((item) => !existingIds.has(item.id));+ const updatedFileList = [...fileList, ...newItems];// Update Zustand storeset({fileList: updatedFileList,fileListHasMore: response.hasMore,- fileListOffset: fileListOffset + response.items.length,+ fileListOffset: fileListOffset + newItems.length,});// Update SWR cache so the component sees the new items@@ -441,24 +444,21 @@ export const createFileManageSlice: StateCreator<),useFetchKnowledgeItems: (params) =>- useClientDataSWR<FileListItem[]>(- [FETCH_ALL_KNOWLEDGE_KEY, params],- async () => {- const response = await serverFileService.getKnowledgeItems({- ...params,- limit: params.limit ?? 50,- offset: 0,- });+ useClientDataSWR<FileListItem[]>([FETCH_ALL_KNOWLEDGE_KEY, params], async () => {+ const response = await serverFileService.getKnowledgeItems({+ ...params,+ limit: params.limit ?? 50,+ offset: 0,+ });- // Update store immediately with response data (no duplicate fetch!)- set({- fileList: response.items,- fileListHasMore: response.hasMore,- fileListOffset: response.items.length,- queryListParams: params,- });+ // Update store immediately with response data (no duplicate fetch!)+ set({+ fileList: response.items,+ fileListHasMore: response.hasMore,+ fileListOffset: response.items.length,+ queryListParams: params,+ });- return response.items;- },- ),+ return response.items;+ }),});