🤯 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: Cannot load more
Rene Wang13349406d57a
diff --git a/src/features/ResourceManager/components/Explorer/ListView/index.tsx b/src/features/ResourceManager/components/Explorer/ListView/index.tsxindex 90e9cd642f8..ab2e92b7f35 100644--- a/src/features/ResourceManager/components/Explorer/ListView/index.tsx+++ b/src/features/ResourceManager/components/Explorer/ListView/index.tsx@@ -1,7 +1,7 @@'use client';import { Center, Flexbox } from '@lobehub/ui';-import { Checkbox } from 'antd';+import { Button, Checkbox } from 'antd';import { createStyles } from 'antd-style';import { rgba } from 'polished';import { type DragEvent, memo, useCallback, useMemo, useRef, useState } from 'react';@@ -35,6 +35,10 @@ const useStyles = createStyles(({ css, token, isDarkMode }) => ({padding-block: 0;padding-inline: 0 24px;`,+ loadMoreContainer: css`+ padding: 16px;+ border-block-start: 1px solid ${isDarkMode ? token.colorSplit : rgba(token.colorSplit, 0.06)};+ `,}));interface ListViewProps {@@ -62,10 +66,10 @@ const ListView = memo<ListViewProps>(selectFileIds,setSelectedFileIds,}) => {- const { t } = useTranslation('components');+ const { t } = useTranslation(['components', 'file']);const { styles, cx } = useStyles();const virtuaRef = useRef<VListHandle>(null);- const isLoadingMore = useRef(false);+ const [isLoadingMore, setIsLoadingMore] = useState(false);const isDragActive = useDragActive();const [isDropZoneActive, setIsDropZoneActive] = useState(false);@@ -95,24 +99,17 @@ const ListView = memo<ListViewProps>(}};- // Handle scroll to detect when reaching bottom- const handleScroll = useCallback(() => {- const ref = virtuaRef.current;- if (!ref || !hasMore || isLoadingMore.current) return;-- const scrollOffset = ref.scrollOffset;- const scrollSize = ref.scrollSize;- const viewportSize = ref.viewportSize;-- // Trigger load more when within 200px of the bottom- const threshold = 200;- if (scrollSize - scrollOffset - viewportSize <= threshold) {- isLoadingMore.current = true;- loadMore().finally(() => {- isLoadingMore.current = false;- });+ // Handle load more button click+ const handleLoadMore = useCallback(async () => {+ if (!hasMore || isLoadingMore) return;++ setIsLoadingMore(true);+ try {+ await loadMore();+ } finally {+ setIsLoadingMore(false);}- }, [hasMore, loadMore]);+ }, [hasMore, loadMore, isLoadingMore]);// Drop zone handlers for dragging to blank spaceconst handleDropZoneDragOver = useCallback(@@ -133,26 +130,32 @@ const ListView = memo<ListViewProps>(setIsDropZoneActive(false);}, []);+ // Add virtual "load more" item to data if there's more to load+ const displayData = useMemo(() => {+ if (!data) return data;+ if (!hasMore) return data;+ // Add a fake item at the end to represent the Load More button+ return [...data, { id: '__load_more__', isLoadMorePlaceholder: true } as any];+ }, [data, hasMore]);+return (- <>- <Flexbox style={{ fontSize: 12 }}>- <Flexbox align={'center'} className={styles.header} horizontal paddingInline={8}>- <Center height={40} style={{ paddingInline: 4 }}>- <Checkbox- checked={allSelected}- indeterminate={indeterminate}- onChange={handleSelectAll}- />- </Center>- <Flexbox className={styles.headerItem} flex={1} style={{ paddingInline: 8 }}>- {t('FileManager.title.title')}- </Flexbox>- <Flexbox className={styles.headerItem} width={FILE_DATE_WIDTH}>- {t('FileManager.title.createdAt')}- </Flexbox>- <Flexbox className={styles.headerItem} width={FILE_SIZE_WIDTH}>- {t('FileManager.title.size')}- </Flexbox>+ <Flexbox height={'100%'}>+ <Flexbox align={'center'} className={styles.header} horizontal paddingInline={8} style={{ fontSize: 12 }}>+ <Center height={40} style={{ paddingInline: 4 }}>+ <Checkbox+ checked={allSelected}+ indeterminate={indeterminate}+ onChange={handleSelectAll}+ />+ </Center>+ <Flexbox className={styles.headerItem} flex={1} style={{ paddingInline: 8 }}>+ {t('FileManager.title.title')}+ </Flexbox>+ <Flexbox className={styles.headerItem} width={FILE_DATE_WIDTH}>+ {t('FileManager.title.createdAt')}+ </Flexbox>+ <Flexbox className={styles.headerItem} width={FILE_SIZE_WIDTH}>+ {t('FileManager.title.size')}</Flexbox></Flexbox><div@@ -162,28 +165,42 @@ const ListView = memo<ListViewProps>(onDragLeave={handleDropZoneDragLeave}onDragOver={handleDropZoneDragOver}onDrop={handleDropZoneDrop}+ style={{ flex: 1, overflow: 'hidden', position: 'relative' }}><VListbufferSize={typeof window !== 'undefined' ? window.innerHeight : 0}- data={data}+ data={displayData}itemSize={48}- onScroll={handleScroll}ref={virtuaRef}style={{ height: '100%' }}>- {(item, index) => (- <FileListItem- index={index}- key={item.id}- onSelectedChange={onSelectionChange}- pendingRenameItemId={pendingRenameItemId}- selected={selectFileIds.includes(item.id)}- {...item}- />- )}+ {(item, index) => {+ // Render Load More button for the placeholder item+ if (item.isLoadMorePlaceholder) {+ return (+ <Center className={styles.loadMoreContainer} key="load-more">+ <Button loading={isLoadingMore} onClick={handleLoadMore} type="default">+ {t('loadMore', { ns: 'file', defaultValue: 'Load More' })}+ </Button>+ </Center>+ );+ }++ // Render normal file item+ return (+ <FileListItem+ index={index}+ key={item.id}+ onSelectedChange={onSelectionChange}+ pendingRenameItemId={pendingRenameItemId}+ selected={selectFileIds.includes(item.id)}+ {...item}+ />+ );+ }}</VList></div>- </>+ </Flexbox>);},);diff --git a/src/features/ResourceManager/components/Explorer/MasonryView/index.tsx b/src/features/ResourceManager/components/Explorer/MasonryView/index.tsxindex 9036e7da509..16cfb1bbf5b 100644--- a/src/features/ResourceManager/components/Explorer/MasonryView/index.tsx+++ b/src/features/ResourceManager/components/Explorer/MasonryView/index.tsx@@ -1,7 +1,10 @@'use client';+import { Center } from '@lobehub/ui';import { VirtuosoMasonry } from '@virtuoso.dev/masonry';-import { memo, useCallback, useMemo, useRef } from 'react';+import { Button } from 'antd';+import { memo, useCallback, useMemo, useState } from 'react';+import { useTranslation } from 'react-i18next';import { useResourceManagerStore } from '@/app/[variants]/(main)/resource/features/store';import { FileListItem } from '@/types/files';@@ -21,8 +24,9 @@ interface MasonryViewProps {const MasonryView = memo<MasonryViewProps>(({ data, hasMore, isMasonryReady, loadMore, onOpenFile, selectFileIds, setSelectedFileIds }) => {+ const { t } = useTranslation('file');const columnCount = useMasonryColumnCount();- const isLoadingMore = useRef(false);+ const [isLoadingMore, setIsLoadingMore] = useState(false);const libraryId = useResourceManagerStore((s) => s.libraryId);@@ -36,15 +40,17 @@ const MasonryView = memo<MasonryViewProps>([onOpenFile, libraryId, selectFileIds, setSelectedFileIds],);- // Handle end reached to load more items- const handleEndReached = useCallback(() => {- if (!hasMore || isLoadingMore.current) return;+ // Handle load more button click+ const handleLoadMore = useCallback(async () => {+ if (!hasMore || isLoadingMore) return;- isLoadingMore.current = true;- loadMore().finally(() => {- isLoadingMore.current = false;- });- }, [hasMore, loadMore]);+ setIsLoadingMore(true);+ try {+ await loadMore();+ } finally {+ setIsLoadingMore(false);+ }+ }, [hasMore, loadMore, isLoadingMore]);return (<div@@ -56,20 +62,7 @@ const MasonryView = memo<MasonryViewProps>(transition: 'opacity 0.2s ease-in-out',}}>- <div- onScroll={(e) => {- const target = e.currentTarget;- const scrollHeight = target.scrollHeight;- const scrollTop = target.scrollTop;- const clientHeight = target.clientHeight;-- // Trigger load more when within 200px of the bottom- if (scrollHeight - scrollTop - clientHeight <= 200) {- handleEndReached();- }- }}- style={{ paddingBlockEnd: 64, paddingBlockStart: 12, paddingInline: 24 }}- >+ <div style={{ paddingBlockEnd: 24, paddingBlockStart: 12, paddingInline: 24 }}><VirtuosoMasonryItemContent={MasonryItemWrapper}columnCount={columnCount}@@ -79,6 +72,13 @@ const MasonryView = memo<MasonryViewProps>(gap: '16px',}}/>+ {hasMore && (+ <Center style={{ marginBlockStart: 24 }}>+ <Button loading={isLoadingMore} onClick={handleLoadMore} type="default">+ {t('loadMore', { defaultValue: 'Load More' })}+ </Button>+ </Center>+ )}</div></div>);diff --git a/src/features/ResourceManager/components/Explorer/useFileExplorer.ts b/src/features/ResourceManager/components/Explorer/useFileExplorer.tsindex b60a5779d7c..944bbd339a7 100644--- a/src/features/ResourceManager/components/Explorer/useFileExplorer.ts+++ b/src/features/ResourceManager/components/Explorer/useFileExplorer.ts@@ -88,7 +88,7 @@ export const useFileExplorer = ({ category: categoryProp, libraryId }: UseFileExconst { data: folderBreadcrumb } = useFetchFolderBreadcrumb(currentFolderSlug);// Fetch data- const { data: rawData, isLoading } = useFetchKnowledgeItems({+ const { data: swrData, isLoading } = useFetchKnowledgeItems({category,knowledgeBaseId: libraryId,parentId: currentFolderSlug || null,@@ -96,6 +96,9 @@ export const useFileExplorer = ({ category: categoryProp, libraryId }: UseFileExshowFilesInKnowledgeBase: false,});+ // Use fileList from store (which includes paginated data) instead of SWR data+ const rawData = fileList.length > 0 ? fileList : swrData;+// Client-side sortingconst data = useMemo(() => {if (!rawData) return rawData;diff --git a/src/locales/default/file.ts b/src/locales/default/file.tsindex e870098a12a..08ca6f11d57 100644--- a/src/locales/default/file.ts+++ b/src/locales/default/file.ts@@ -56,6 +56,7 @@ export default {'library.list.empty': 'Click <1>+</1> to create a new library','library.new': 'New Library','library.title': 'Library',+ 'loadMore': 'Load More','menu.allFiles': 'All Files','menu.allPages': 'All Pages','networkError':