@@ -21,6 +21,7 @@ const PostEditor = ({
21
21
} ) => {
22
22
const [ heading , setHeading ] = useState ( "" ) ;
23
23
const [ upload , setUpload ] = useState ( "" ) ;
24
+ const [ uploadingContent , setUploadingContent ] = useState ( false ) ;
24
25
const [ editorState , setEditorState ] = useState ( ( ) =>
25
26
EditorState . createEmpty ( )
26
27
) ;
@@ -32,6 +33,13 @@ const PostEditor = ({
32
33
}
33
34
} , [ post . imageUploaded ] ) ;
34
35
36
+ useEffect ( ( ) => {
37
+ if ( post . uploadedStatus ) {
38
+ setUploadingContent ( false ) ;
39
+ history . push ( "/" ) ;
40
+ }
41
+ } , [ post . uploadedStatus ] ) ;
42
+
35
43
useEffect ( ( ) => {
36
44
if ( upload === "Uploaded!" ) {
37
45
dispatchPopup ( "Post Image" , "Post image has been uploaded successfully!" ) ;
@@ -43,6 +51,7 @@ const PostEditor = ({
43
51
const postRawContent = convertToRaw ( editorState . getCurrentContent ( ) )
44
52
. blocks ;
45
53
if ( heading !== "" && post . postID !== undefined ) {
54
+ setUploadingContent ( true ) ;
46
55
uploadPost (
47
56
{
48
57
heading : heading ,
@@ -52,7 +61,6 @@ const PostEditor = ({
52
61
) ;
53
62
}
54
63
clearPostID ( ) ;
55
- history . push ( "/" ) ;
56
64
}
57
65
} ;
58
66
@@ -119,8 +127,8 @@ const PostEditor = ({
119
127
/>
120
128
</ EditorWrapper >
121
129
</ S . Box >
122
- < S . Button w = "250px" onClick = { handleSave } >
123
- < S . Text > { post . uploadedStatus ? "" : " Post" } </ S . Text >
130
+ < S . Button w = "250px" onClick = { handleSave } isLoading = { uploadingContent } >
131
+ < S . Text > Post</ S . Text >
124
132
</ S . Button >
125
133
</ S . Flex >
126
134
) ;
0 commit comments