refactor(sidebar): streamline DocumentsSidebar and FolderTreeView for improved performance

- Removed unnecessary filtering logic in FolderTreeView to simplify document rendering.
- Updated DocumentsSidebar to eliminate redundant props and enhance layout consistency.
- Adjusted Sidebar component to conditionally render DocumentsSidebar based on the documentsPanel state.
This commit is contained in:
Anish Sarkar 2026-07-06 12:49:41 +05:30
parent 53259b6105
commit e24abd7eac
5 changed files with 102 additions and 890 deletions

View file

@ -260,16 +260,6 @@ export function FolderTreeView({
const nodes: React.ReactNode[] = [];
if (parentId === null) {
const processingDocs = childDocs.filter((d) => {
const state = d.status?.state;
return state === "pending" || state === "processing";
});
for (const d of processingDocs) {
nodes.push(renderDocumentNode(d, depth));
}
}
for (let i = 0; i < visibleFolders.length; i++) {
const f = visibleFolders[i];
const siblingPositions = {
@ -314,15 +304,7 @@ export function FolderTreeView({
}
}
const remainingDocs =
parentId === null
? childDocs.filter((d) => {
const state = d.status?.state;
return state !== "pending" && state !== "processing";
})
: childDocs;
for (const d of remainingDocs) {
for (const d of childDocs) {
nodes.push(renderDocumentNode(d, depth));
}

View file

@ -27,7 +27,6 @@ import {
RightPanelToggleButton,
} from "../right-panel/RightPanel";
import {
DocumentsSidebar,
InboxSidebarContent,
MobileSidebar,
MobileSidebarTrigger,
@ -313,6 +312,7 @@ export function LayoutShell({
onChatArchive={onChatArchive}
onViewAllChats={onViewAllChats}
isAllChatsActive={isAllChatsPage}
documentsPanel={documentsPanel}
user={user}
onSettings={onSettings}
onManageMembers={onManageMembers}
@ -366,14 +366,6 @@ export function LayoutShell({
)}
</AnimatePresence>
</SidebarSlideOutPanel>
{/* Mobile Documents Sidebar - separate (not part of slide-out group) */}
{documentsPanel && (
<DocumentsSidebar
open={documentsPanel.open}
onOpenChange={documentsPanel.onOpenChange}
/>
)}
</div>
</TooltipProvider>
</SidebarProvider>

View file

@ -28,6 +28,10 @@ interface MobileSidebarProps {
onChatArchive?: (chat: ChatItem) => void;
onViewAllChats?: () => void;
isAllChatsActive?: boolean;
documentsPanel?: {
open: boolean;
onOpenChange: (open: boolean) => void;
};
user: User;
onSettings?: () => void;
onManageMembers?: () => void;
@ -76,6 +80,7 @@ export function MobileSidebar({
onChatArchive,
onViewAllChats,
isAllChatsActive = false,
documentsPanel,
user,
onSettings,
onManageMembers,
@ -94,6 +99,9 @@ export function MobileSidebar({
const handleNavItemClick = (item: NavItem) => {
onNavItemClick?.(item);
if (item.url === "#documents") {
return;
}
onOpenChange(false);
};
@ -167,6 +175,7 @@ export function MobileSidebar({
: undefined
}
isAllChatsActive={isAllChatsActive}
documentsPanel={documentsPanel}
user={user}
onSettings={
onSettings

View file

@ -337,11 +337,7 @@ export function Sidebar({
</SidebarSection>
{documentsPanel?.open ? (
<div className="min-h-0 flex flex-1 flex-col">
<DocumentsSidebar
open={documentsPanel.open}
onOpenChange={documentsPanel.onOpenChange}
embedded
/>
<DocumentsSidebar embedded />
</div>
) : null}
</div>