diff --git a/ui/desktop/src/components/sessions/SessionListView.tsx b/ui/desktop/src/components/sessions/SessionListView.tsx index e56842b9c99e..e1b5e01cfd2b 100644 --- a/ui/desktop/src/components/sessions/SessionListView.tsx +++ b/ui/desktop/src/components/sessions/SessionListView.tsx @@ -185,6 +185,8 @@ const SessionListView: React.FC = React.memo( currentIndex: number; } | null>(null); + const [visibleGroupsCount, setVisibleGroupsCount] = useState(15); + // Edit modal state const [showEditModal, setShowEditModal] = useState(false); const [editingSession, setEditingSession] = useState(null); @@ -210,6 +212,33 @@ const SessionListView: React.FC = React.memo( } }; + const visibleDateGroups = useMemo(() => { + return dateGroups.slice(0, visibleGroupsCount); + }, [dateGroups, visibleGroupsCount]); + + const handleScroll = useCallback( + (target: HTMLDivElement) => { + const { scrollTop, scrollHeight, clientHeight } = target; + const threshold = 200; + + if ( + scrollHeight - scrollTop - clientHeight < threshold && + visibleGroupsCount < dateGroups.length + ) { + setVisibleGroupsCount((prev) => Math.min(prev + 5, dateGroups.length)); + } + }, + [visibleGroupsCount, dateGroups.length] + ); + + useEffect(() => { + if (debouncedSearchTerm) { + setVisibleGroupsCount(dateGroups.length); + } else { + setVisibleGroupsCount(15); + } + }, [debouncedSearchTerm, dateGroups.length]); + const loadSessions = useCallback(async () => { setIsLoading(true); setShowSkeleton(true); @@ -557,10 +586,9 @@ const SessionListView: React.FC = React.memo( ); } - // For regular rendering in grid layout return (
- {dateGroups.map((group) => ( + {visibleDateGroups.map((group) => (

{group.label}

@@ -577,6 +605,15 @@ const SessionListView: React.FC = React.memo(
))} + + {visibleGroupsCount < dateGroups.length && ( +
+
+
+ Loading more sessions... +
+
+ )}
); }; @@ -597,7 +634,7 @@ const SessionListView: React.FC = React.memo(
- +
void; } const ScrollArea = React.forwardRef( - ({ className, children, autoScroll = false, paddingX, paddingY, ...props }, ref) => { + ( + { + className, + children, + autoScroll = false, + paddingX, + paddingY, + handleScroll: handleScrollProp, + ...props + }, + ref + ) => { const rootRef = React.useRef>(null); const viewportRef = React.useRef(null); const viewportEndRef = React.useRef(null); @@ -71,7 +83,11 @@ const ScrollArea = React.forwardRef( setIsFollowing(isAtBottom); setIsScrolled(scrollTop > 0); - }, []); + + if (handleScrollProp) { + handleScrollProp(viewport); + } + }, [handleScrollProp]); // Track previous scroll height to detect content changes const prevScrollHeightRef = React.useRef(0);