import { Box } from '@chakra-ui/react'; import React from 'react'; import type { File } from './types'; import CodeEditorFileTree from './CodeEditorFileTree'; import CoderEditorCollapseButton from './CoderEditorCollapseButton'; import composeFileTree from './utils/composeFileTree'; interface Props { data: Array; onFileSelect: (index: number) => void; selectedFile: string; mainFile?: string; isActive: boolean; setActionBarRenderer: React.Dispatch React.JSX.Element) | undefined>>; } const CodeEditorFileExplorer = ({ data, onFileSelect, selectedFile, mainFile, isActive, setActionBarRenderer }: Props) => { const [ key, setKey ] = React.useState(0); const tree = React.useMemo(() => { return composeFileTree(data); }, [ data ]); const handleCollapseButtonClick = React.useCallback(() => { setKey((prev) => prev + 1); }, []); const renderActionBar = React.useCallback(() => { return ( ); }, [ handleCollapseButtonClick ]); const handleFileClick = React.useCallback((event: React.MouseEvent) => { const filePath = (event.currentTarget as HTMLDivElement).getAttribute('data-file-path'); const fileIndex = data.findIndex((item) => item.file_path === filePath); if (fileIndex > -1) { onFileSelect(fileIndex); } }, [ data, onFileSelect ]); React.useEffect(() => { isActive && setActionBarRenderer(() => renderActionBar); }, [ isActive, renderActionBar, setActionBarRenderer ]); return ( 0 } selectedFile={ selectedFile } mainFile={ mainFile } /> ); }; export default React.memo(CodeEditorFileExplorer);