@@ -6,13 +6,16 @@ import { Utils } from '../../../utils/utils';
6
6
import toaster from '../../../components/toast' ;
7
7
import InternalLinkDialog from '../../../components/dialog/internal-link-dialog' ;
8
8
import ShareDialog from '../../../components/dialog/share-dialog' ;
9
+ import CreateFile from '../../../components/dialog/create-file-dialog' ;
9
10
10
11
const propTypes = {
11
12
repoID : PropTypes . string . isRequired ,
12
13
docPath : PropTypes . string . isRequired ,
13
14
docName : PropTypes . string . isRequired ,
14
15
docPerm : PropTypes . string . isRequired ,
15
16
isStarred : PropTypes . bool . isRequired ,
17
+ direntList : PropTypes . array . isRequired ,
18
+ dirPath : PropTypes . string . isRequired ,
16
19
toggleStar : PropTypes . func . isRequired ,
17
20
unmarkDraft : PropTypes . func . isRequired
18
21
} ;
@@ -25,6 +28,7 @@ class ExternalOperations extends React.Component {
25
28
isShowInternalLinkDialog : false ,
26
29
isShowShareDialog : false ,
27
30
internalLink : '' ,
31
+ isShowCreateFileDialog : false ,
28
32
} ;
29
33
}
30
34
@@ -36,13 +40,15 @@ class ExternalOperations extends React.Component {
36
40
this . unsubscribeShare = eventBus . subscribe ( EXTERNAL_EVENT . SHARE_SDOC , this . onShareToggle ) ;
37
41
this . unsubscribeShare = eventBus . subscribe ( EXTERNAL_EVENT . FREEZE_DOCUMENT , this . onFreezeDocument ) ;
38
42
this . unsubscribeShare = eventBus . subscribe ( EXTERNAL_EVENT . UNFREEZE , this . unFreeze ) ;
43
+ this . unsubscribeCreateSdocFile = eventBus . subscribe ( EXTERNAL_EVENT . CREATE_SDOC_FILE , this . onCreateSdocFile ) ;
39
44
}
40
45
41
46
componentWillUnmount ( ) {
42
47
this . unsubscribeInternalLinkEvent ( ) ;
43
48
this . unsubscribeStar ( ) ;
44
49
this . unsubscribeUnmark ( ) ;
45
50
this . unsubscribeShare ( ) ;
51
+ this . unsubscribeCreateSdocFile ( ) ;
46
52
}
47
53
48
54
onInternalLinkToggle = ( options ) => {
@@ -107,9 +113,31 @@ class ExternalOperations extends React.Component {
107
113
} ) ;
108
114
} ;
109
115
116
+ onCreateSdocFile = ( ) => {
117
+ this . setState ( {
118
+ isShowCreateFileDialog : ! this . state . isShowCreateFileDialog
119
+ } ) ;
120
+ } ;
121
+
122
+ checkDuplicatedName = ( newName ) => {
123
+ let direntList = this . props . direntList ;
124
+ let isDuplicated = direntList . some ( object => {
125
+ return object . name === newName ;
126
+ } ) ;
127
+ return isDuplicated ;
128
+ } ;
129
+
130
+ onAddFile = ( filePath , isMarkdownDraft , isSdocDraft ) => {
131
+ let repoID = this . props . repoID ;
132
+ seafileAPI . createFile ( repoID , filePath , isMarkdownDraft ) . catch ( ( error ) => {
133
+ let errMessage = Utils . getErrorMsg ( error ) ;
134
+ toaster . danger ( errMessage ) ;
135
+ } ) ;
136
+ } ;
137
+
110
138
render ( ) {
111
- const { repoID, docPath, docName, docPerm } = this . props ;
112
- const { isShowInternalLinkDialog, isShowShareDialog, internalLink } = this . state ;
139
+ const { repoID, docPath, docName, docPerm, dirPath } = this . props ;
140
+ const { isShowInternalLinkDialog, isShowShareDialog, internalLink, isShowCreateFileDialog } = this . state ;
113
141
return (
114
142
< >
115
143
{ isShowInternalLinkDialog && (
@@ -130,6 +158,15 @@ class ExternalOperations extends React.Component {
130
158
toggleDialog = { this . onShareToggle }
131
159
/>
132
160
) }
161
+ { isShowCreateFileDialog && (
162
+ < CreateFile
163
+ parentPath = { dirPath }
164
+ fileType = '.sdoc'
165
+ onAddFile = { this . onAddFile }
166
+ checkDuplicatedName = { this . checkDuplicatedName }
167
+ toggleDialog = { this . onCreateSdocFile }
168
+ />
169
+ ) }
133
170
</ >
134
171
) ;
135
172
}
0 commit comments