mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
* add decoration for external library warning * add decoration for same name warning * formatted tooltip text * show source code even if contract is not verified * add support for remappings context in file import resolution * library warning decoration styles * external libraries popover * disable contract name warning for a while * add tab to contract page link * change api host for preview * add main file indicator * change button styles and update screenshots * change isNeedProxy for passing pw tests * rollback review env changes
63 lines
1.9 KiB
TypeScript
63 lines
1.9 KiB
TypeScript
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<File>;
|
|
onFileSelect: (index: number) => void;
|
|
selectedFile: string;
|
|
mainFile?: string;
|
|
isActive: boolean;
|
|
setActionBarRenderer: React.Dispatch<React.SetStateAction<(() => 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 (
|
|
<CoderEditorCollapseButton onClick={ handleCollapseButtonClick } label="Collapse folders"/>
|
|
);
|
|
}, [ 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 (
|
|
<Box>
|
|
<CodeEditorFileTree
|
|
key={ key }
|
|
tree={ tree }
|
|
onItemClick={ handleFileClick }
|
|
isCollapsed={ key > 0 }
|
|
selectedFile={ selectedFile }
|
|
mainFile={ mainFile }
|
|
/>
|
|
</Box>
|
|
);
|
|
};
|
|
|
|
export default React.memo(CodeEditorFileExplorer);
|