@@ -6,12 +6,12 @@ import React, {
6
6
useCallback ,
7
7
useLayoutEffect ,
8
8
} from 'react' ;
9
- import { IFolderTreeSubItem } from 'mo/model' ;
9
+ import { IFolderTree , IFolderTreeSubItem } from 'mo/model' ;
10
10
import { select , getEventPosition } from 'mo/common/dom' ;
11
11
import Tree , { ITreeNodeItemProps } from 'mo/components/tree' ;
12
12
import { IMenuItemProps , Menu } from 'mo/components/menu' ;
13
13
import { Button } from 'mo/components/button' ;
14
- import { IFolderTreeController } from 'mo/controller/explorer/folderTree' ;
14
+ import { FolderTreeController } from 'mo/controller/explorer/folderTree' ;
15
15
import { useContextView } from 'mo/components/contextView' ;
16
16
import { useContextMenu } from 'mo/components/contextMenu' ;
17
17
import {
@@ -66,13 +66,12 @@ const Input = React.forwardRef(
66
66
}
67
67
) ;
68
68
69
- const FolderTree : React . FunctionComponent < IFolderTreeSubItem > = (
70
- props : IFolderTreeSubItem & IFolderTreeController
71
- ) => {
69
+ const FolderTree : React . FunctionComponent <
70
+ FolderTreeController & IFolderTree
71
+ > = ( props ) => {
72
72
const {
73
- data = [ ] ,
74
- contextMenu : rawContextMenu = [ ] ,
75
- folderPanelContextMenu = [ ] ,
73
+ folderTree = { } ,
74
+ entry,
76
75
onUpdateFileName,
77
76
onSelectFile,
78
77
onDropTree,
@@ -82,6 +81,28 @@ const FolderTree: React.FunctionComponent<IFolderTreeSubItem> = (
82
81
getInputEvent,
83
82
...restProps
84
83
} = props ;
84
+
85
+ const {
86
+ data = [ ] ,
87
+ contextMenu : rawContextMenu = [ ] ,
88
+ folderPanelContextMenu = [ ] ,
89
+ } = folderTree ;
90
+
91
+ const handleAddRootFolder = ( ) => {
92
+ onNewRootFolder ?.( ) ;
93
+ } ;
94
+
95
+ const welcomePage = entry ? (
96
+ < > { entry } </ >
97
+ ) : (
98
+ < div style = { { padding : '10px 5px' } } >
99
+ you have not yet opened a folder
100
+ < Button onClick = { handleAddRootFolder } > Add Folder</ Button >
101
+ </ div >
102
+ ) ;
103
+
104
+ if ( ! data . length ) return welcomePage ;
105
+
85
106
const inputRef = useRef < HTMLInputElement > ( null ) ;
86
107
// tree context view
87
108
const contextMenu = useRef < ReturnType < typeof useContextMenu > > ( ) ;
@@ -164,10 +185,6 @@ const FolderTree: React.FunctionComponent<IFolderTreeSubItem> = (
164
185
}
165
186
} ;
166
187
167
- const handleAddRootFolder = ( ) => {
168
- onNewRootFolder ?.( ) ;
169
- } ;
170
-
171
188
const renderTitle = ( node : ITreeNodeItemProps ) => {
172
189
const { isEditable, name } = node ;
173
190
@@ -194,9 +211,9 @@ const FolderTree: React.FunctionComponent<IFolderTreeSubItem> = (
194
211
return ( ) => {
195
212
contextMenu . current ?. dispose ( ) ;
196
213
} ;
197
- } , [ data ? .length ] ) ;
214
+ } , [ data . length ] ) ;
198
215
199
- const renderByData = (
216
+ return (
200
217
< Tree
201
218
// root folder do not render
202
219
data = { data [ 0 ] ?. children || [ ] }
@@ -211,14 +228,5 @@ const FolderTree: React.FunctionComponent<IFolderTreeSubItem> = (
211
228
{ ...restProps }
212
229
/>
213
230
) ;
214
-
215
- const renderInitial = (
216
- < div style = { { padding : '10px 5px' } } >
217
- you have not yet opened a folder
218
- < Button onClick = { handleAddRootFolder } > Add Folder</ Button >
219
- </ div >
220
- ) ;
221
-
222
- return data ?. length > 0 ? renderByData : renderInitial ;
223
231
} ;
224
232
export default memo ( FolderTree ) ;
0 commit comments