Browse Source

app openning now waits until workspace content has loader to avoid openning app with default 'reader' rights

Skylsmoi 5 years ago
parent
commit
e9338543a1
1 changed files with 22 additions and 14 deletions
  1. 22 14
      frontend/src/container/WorkspaceContent.jsx

+ 22 - 14
frontend/src/container/WorkspaceContent.jsx View File

@@ -36,7 +36,8 @@ class WorkspaceContent extends React.Component {
36 36
     super(props)
37 37
     this.state = {
38 38
       workspaceIdInUrl: props.match.params.idws ? parseInt(props.match.params.idws) : null, // this is used to avoid handling the parseInt every time
39
-      appOpenedType: false
39
+      appOpenedType: false,
40
+      contentLoaded: false
40 41
     }
41 42
 
42 43
     document.addEventListener('appCustomEvent', this.customEventReducer)
@@ -108,11 +109,13 @@ class WorkspaceContent extends React.Component {
108 109
     const wsContent = await dispatch(getWorkspaceContentList(user, idWorkspace, 0))
109 110
     const wsMember = await dispatch(getWorkspaceMemberList(user, idWorkspace))
110 111
 
111
-    if (await wsContent.status === 200) dispatch(setWorkspaceContentList(wsContent.json))
112
+    if (wsContent.status === 200) dispatch(setWorkspaceContentList(wsContent.json))
112 113
     else dispatch(newFlashMessage('Error while loading workspace', 'danger'))
113 114
 
114
-    if (await wsMember.status === 200) dispatch(setWorkspaceMemberList(wsMember.json))
115
+    if (wsMember.status === 200) dispatch(setWorkspaceMemberList(wsMember.json))
115 116
     else dispatch(newFlashMessage('Error while loading members list', 'warning'))
117
+
118
+    this.setState({contentLoaded: true})
116 119
   }
117 120
 
118 121
   handleClickContentItem = content => {
@@ -178,6 +181,7 @@ class WorkspaceContent extends React.Component {
178 181
 
179 182
   render () {
180 183
     const { user, currentWorkspace, workspaceContentList, contentType } = this.props
184
+    const { state } = this
181 185
 
182 186
     const filterWorkspaceContent = (contentList, filter) => {
183 187
       return filter.length === 0
@@ -198,20 +202,24 @@ class WorkspaceContent extends React.Component {
198 202
 
199 203
     return (
200 204
       <div className='WorkspaceContent' style={{width: '100%'}}>
201
-        <OpenContentApp
202
-          // automatically open the app for the idContent in url
203
-          idWorkspace={this.state.workspaceIdInUrl}
204
-          appOpenedType={this.state.appOpenedType}
205
-          updateAppOpenedType={this.handleUpdateAppOpenedType}
206
-        />
207
-
208
-        <Route path={PAGE.WORKSPACE.NEW(':idws', ':type')} component={() =>
209
-          <OpenCreateContentApp
210
-            // automatically open the popup create content of the app in url
205
+        {state.contentLoaded &&
206
+          <OpenContentApp
207
+            // automatically open the app for the idContent in url
211 208
             idWorkspace={this.state.workspaceIdInUrl}
212 209
             appOpenedType={this.state.appOpenedType}
210
+            updateAppOpenedType={this.handleUpdateAppOpenedType}
213 211
           />
214
-        } />
212
+        }
213
+
214
+        {state.contentLoaded &&
215
+          <Route path={PAGE.WORKSPACE.NEW(':idws', ':type')} component={() =>
216
+            <OpenCreateContentApp
217
+              // automatically open the popup create content of the app in url
218
+              idWorkspace={this.state.workspaceIdInUrl}
219
+              appOpenedType={this.state.appOpenedType}
220
+            />
221
+          } />
222
+        }
215 223
 
216 224
         <PageWrapper customeClass='workspace'>
217 225
           <PageTitle