'use client' import { useState, useMemo } from 'react' import { FileTree, useFileTree, useFileTreeSelection } from '@pierre/trees/react' import { FileViewer } from './FileViewer' interface Props { paths: string[] } export function TreeBrowser({ paths }: Props) { const [selectedFile, setSelectedFile] = useState(null) const { model } = useFileTree({ paths, search: true, fileTreeSearchMode: 'hide-non-matches', flattenEmptyDirectories: true, }) const selectedPaths = useFileTreeSelection(model) const currentFile = useMemo(() => { const sel = selectedPaths[0] if (sel && !sel.endsWith('/')) { return sel } return selectedFile }, [selectedPaths, selectedFile]) return ( <>
Files
{ const path = e?.item?.path if (path && !path.endsWith('/')) { setSelectedFile(path) } }} />
{currentFile ? ( ) : (
Select a file to view
)}
) }