'use client'; import * as React from 'react'; import { Folder, FolderOpen, ChevronRight } from 'lucide-react'; import { Collapsible, CollapsibleContent, CollapsibleTrigger, } from '@/components/ui/collapsible'; import { cn } from '@/lib/utils'; import type { Folder as FolderType } from '@/app/api/files/route'; interface FolderTreeProps { rootFolder: FolderType; currentPath: string; onSelectFolder: (path: string) => void; } export function FolderTree({ rootFolder, currentPath, onSelectFolder }: FolderTreeProps) { const subFolders = rootFolder.children.filter( (child): child is FolderType => child.type === 'folder' ); return ( {subFolders.map((folder) => ( ))} ); } interface RecursiveFolderProps { folder: FolderType; currentPath: string; onSelectFolder: (path: string) => void; level: number; } function RecursiveFolder({ folder, currentPath, onSelectFolder, level }: RecursiveFolderProps) { const [isOpen, setIsOpen] = React.useState( currentPath.startsWith(`${folder.path}`) ); React.useEffect(() => { setIsOpen(currentPath.startsWith(`${folder.path}`)); }, [currentPath, folder.path]); const subFolders = folder.children.filter( (child): child is FolderType => child.type === 'folder' ); const isActive = currentPath === folder.path; const Icon = isOpen ? FolderOpen : Folder; return ( onSelectFolder(folder.path)} > {folder.name} {subFolders.map((subFolder) => ( ))} ); }