@@ -43,6 +43,7 @@ type Props = {
43
43
members : User [ ] ;
44
44
textareaHeight ?: string ;
45
45
placeholder ?: string ;
46
+ parentComponent : string ;
46
47
} ;
47
48
48
49
type State = { htmlContent : string } ;
@@ -58,7 +59,7 @@ class PostEditor extends React.Component<Props, State> {
58
59
59
60
public render ( ) {
60
61
const { htmlContent } = this . state ;
61
- const { content, members, store } = this . props ;
62
+ const { content, members, store, parentComponent } = this . props ;
62
63
const { currentUser } = store ;
63
64
64
65
const membersMinusCurrentUser = members . filter ( ( member ) => member . _id !== currentUser . _id ) ;
@@ -86,21 +87,21 @@ class PostEditor extends React.Component<Props, State> {
86
87
</ div >
87
88
88
89
< div style = { { display : 'inline' , float : 'left' } } >
89
- < label htmlFor = " upload-file-post-editor" >
90
+ < label htmlFor = { ' upload-file-post-editor-' + parentComponent } >
90
91
< Button component = "span" style = { { color : '#58a6ff' } } >
91
92
< InsertPhotoIcon style = { { fontSize : '22px' } } />
92
93
</ Button >
93
94
</ label >
94
95
< input
95
96
accept = "image/*"
96
- name = " upload-file-post-editor"
97
- id = " upload-file-post-editor"
97
+ name = { ' upload-file-post-editor-' + parentComponent }
98
+ id = { ' upload-file-post-editor-' + parentComponent }
98
99
type = "file"
99
100
style = { { display : 'none' } }
100
- onChange = { ( event ) => {
101
+ onChange = { async ( event ) => {
101
102
const file = event . target . files [ 0 ] ;
103
+ await this . uploadFile ( file ) ;
102
104
event . target . value = '' ;
103
- this . uploadFile ( file ) ;
104
105
} }
105
106
/>
106
107
</ div >
@@ -257,7 +258,7 @@ class PostEditor extends React.Component<Props, State> {
257
258
bucket,
258
259
} ) ;
259
260
260
- let imageMarkdown ;
261
+ let fileHtmlOrMarkdown ;
261
262
let fileUrl ;
262
263
263
264
if ( file . type . startsWith ( 'image/' ) ) {
@@ -275,7 +276,7 @@ class PostEditor extends React.Component<Props, State> {
275
276
276
277
const finalWidth = width > 768 ? '100%' : `${ width } px` ;
277
278
278
- imageMarkdown = `
279
+ fileHtmlOrMarkdown = `
279
280
<div>
280
281
<img style="max-width: ${ finalWidth } ; width:100%" src="${ fileUrl } " alt="Async" class="s3-image" />
281
282
</div>` ;
@@ -286,14 +287,13 @@ class PostEditor extends React.Component<Props, State> {
286
287
) ;
287
288
288
289
fileUrl = responseFromApiServerForUpload . url ;
289
- imageMarkdown = `[${ file . name } ](${ fileUrl } )` ;
290
+ fileHtmlOrMarkdown = `[${ file . name } ](${ fileUrl } )` ;
290
291
}
291
292
292
- const content = `${ this . props . content } \n${ imageMarkdown . replace ( / \s + / g, ' ' ) } ` ;
293
+ const content = `${ this . props . content } \n${ fileHtmlOrMarkdown . replace ( / \s + / g, ' ' ) } ` ;
293
294
294
295
this . props . onChanged ( content ) ;
295
296
296
- NProgress . done ( ) ;
297
297
notify ( 'You successfully uploaded file.' ) ;
298
298
} catch ( error ) {
299
299
console . log ( error ) ;
0 commit comments