File tree Expand file tree Collapse file tree 1 file changed +12
-21
lines changed
packages/react-sandpack/src/components/FileExplorer/ModuleList Expand file tree Collapse file tree 1 file changed +12
-21
lines changed Original file line number Diff line number Diff line change @@ -21,27 +21,18 @@ export default class ModuleList extends React.PureComponent<Props> {
2121 prefixedPath,
2222 files,
2323 } = this . props ;
24-
25- const filesToShow : { path : string } [ ] = [ ] ;
26- const directoriesToShow : Set < string > = new Set ( ) ;
27- const pathParts = prefixedPath . split ( '/' ) ;
28-
29- Object . keys ( files ) . forEach ( path => {
30- if ( path . startsWith ( prefixedPath ) ) {
31- const filePathParts = path . split ( '/' ) ;
32-
33- if ( filePathParts . length === pathParts . length ) {
34- if ( path . endsWith ( '/' ) ) {
35- directoriesToShow . add ( path ) ;
36- } else {
37- filesToShow . push ( { path } ) ;
38- }
39- } else if ( filePathParts . length === pathParts . length + 1 ) {
40- filePathParts . pop ( ) ;
41- directoriesToShow . add ( filePathParts . join ( '/' ) + '/' ) ;
42- }
43- }
44- } ) ;
24+
25+ const fileListWithoutPrefix = Object . keys ( files )
26+ . filter ( file => file . startsWith ( prefixedPath ) )
27+ . map ( file => file . substring ( prefixedPath . length ) ) ;
28+
29+ const directoriesToShow = new Set ( fileListWithoutPrefix
30+ . filter ( file => file . includes ( '/' ) )
31+ . map ( file => `${ prefixedPath } ${ file . split ( '/' ) [ 0 ] } /` ) ) ;
32+
33+ const filesToShow = fileListWithoutPrefix
34+ . filter ( file => ! file . includes ( '/' ) )
35+ . map ( file => ( { path : `${ prefixedPath } ${ file } ` } ) ) ;
4536
4637 return (
4738 < div style = { { marginLeft : `${ 0.5 * depth } rem` } } >
You can’t perform that action at this time.
0 commit comments