Browse Source

fixed app opening and reopening

Skylsmoi 5 years ago
parent
commit
0fcc5b76d9
2 changed files with 18 additions and 12 deletions
  1. 11 8
      src/container/OpenContentApp.jsx
  2. 7 4
      src/container/WorkspaceContent.jsx

+ 11 - 8
src/container/OpenContentApp.jsx View File

@@ -5,7 +5,7 @@ import appFactory from '../appFactory.js'
5 5
 
6 6
 export class OpenContentApp extends React.Component {
7 7
   openContentApp = () => {
8
-    const { idWorkspace, appOpened, user, workspaceContent, contentType, renderApp, match } = this.props
8
+    const { idWorkspace, appOpenedType, user, workspaceContent, contentType, renderApp, match } = this.props
9 9
 
10 10
     if (isNaN(idWorkspace)) return
11 11
 
@@ -20,18 +20,21 @@ export class OpenContentApp extends React.Component {
20 20
 
21 21
       console.log('contentToOpen', contentToOpen)
22 22
 
23
-      if (!appOpened) {
23
+      if (appOpenedType === contentToOpen.type) { // app already open
24
+        GLOBAL_dispatchEvent({
25
+          type: `${contentToOpen.type}_reloadContent`, // handled by html-documents:src/container/HtmlDocument.jsx
26
+          data: contentToOpen
27
+        })
28
+      } else { // open another app
29
+        // if another app is already visible, hide it
30
+        if (appOpenedType !== false) GLOBAL_dispatchEvent(`${appOpenedType}_hideApp`)
31
+        // open app
24 32
         renderApp(
25 33
           contentType.find(ct => ct.slug === contentToOpen.type),
26 34
           user,
27 35
           contentToOpen
28 36
         )
29
-        this.props.updateAppOpened(true)
30
-      } else {
31
-        GLOBAL_dispatchEvent({
32
-          type: 'html-documents_reloadContent', // handled by html-documents:src/container/HtmlDocument.jsx
33
-          data: contentToOpen
34
-        })
37
+        this.props.updateAppOpenedType(contentToOpen.type)
35 38
       }
36 39
     }
37 40
   }

+ 7 - 4
src/container/WorkspaceContent.jsx View File

@@ -16,7 +16,6 @@ import {
16 16
   getAppList,
17 17
   getContentTypeList,
18 18
   getWorkspaceContentList,
19
-  // getWorkspaceContent,
20 19
   getFolderContent,
21 20
   getWorkspaceList
22 21
 } from '../action-creator.async.js'
@@ -41,7 +40,7 @@ class WorkspaceContent extends React.Component {
41 40
         folder: undefined
42 41
       },
43 42
       workspaceIdInUrl: props.match.params.idws ? parseInt(props.match.params.idws) : null, // this is used to avoid handling the parseInt everytime
44
-      appOpened: false
43
+      appOpenedType: false
45 44
     }
46 45
 
47 46
     document.addEventListener('appCustomEvent', this.customEventReducer)
@@ -171,7 +170,7 @@ class WorkspaceContent extends React.Component {
171 170
     )
172 171
   }
173 172
 
174
-  handleUpdateAppOpened = opened => this.setState({appOpened: opened})
173
+  handleUpdateAppOpenedType = openedAppType => this.setState({appOpenedType: openedAppType})
175 174
 
176 175
   render () {
177 176
     const { workspaceContent, contentType, match } = this.props
@@ -196,7 +195,11 @@ class WorkspaceContent extends React.Component {
196 195
       <div className='sidebarpagecontainer'>
197 196
         <Sidebar />
198 197
 
199
-        <OpenContentApp idWorkspace={match.params.idws} appOpened={this.state.appOpened} updateAppOpened={this.handleUpdateAppOpened} />
198
+        <OpenContentApp
199
+          idWorkspace={match.params.idws}
200
+          appOpenedType={this.state.appOpenedType}
201
+          updateAppOpenedType={this.handleUpdateAppOpenedType}
202
+        />
200 203
 
201 204
         <PageWrapper customeClass='workspace'>
202 205
           <PageTitle