Browse Source

fixed app opening and reopening

Skylsmoi 6 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
 
5
 
6
 export class OpenContentApp extends React.Component {
6
 export class OpenContentApp extends React.Component {
7
   openContentApp = () => {
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
     if (isNaN(idWorkspace)) return
10
     if (isNaN(idWorkspace)) return
11
 
11
 
20
 
20
 
21
       console.log('contentToOpen', contentToOpen)
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
         renderApp(
32
         renderApp(
25
           contentType.find(ct => ct.slug === contentToOpen.type),
33
           contentType.find(ct => ct.slug === contentToOpen.type),
26
           user,
34
           user,
27
           contentToOpen
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
   getAppList,
16
   getAppList,
17
   getContentTypeList,
17
   getContentTypeList,
18
   getWorkspaceContentList,
18
   getWorkspaceContentList,
19
-  // getWorkspaceContent,
20
   getFolderContent,
19
   getFolderContent,
21
   getWorkspaceList
20
   getWorkspaceList
22
 } from '../action-creator.async.js'
21
 } from '../action-creator.async.js'
41
         folder: undefined
40
         folder: undefined
42
       },
41
       },
43
       workspaceIdInUrl: props.match.params.idws ? parseInt(props.match.params.idws) : null, // this is used to avoid handling the parseInt everytime
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
     document.addEventListener('appCustomEvent', this.customEventReducer)
46
     document.addEventListener('appCustomEvent', this.customEventReducer)
171
     )
170
     )
172
   }
171
   }
173
 
172
 
174
-  handleUpdateAppOpened = opened => this.setState({appOpened: opened})
173
+  handleUpdateAppOpenedType = openedAppType => this.setState({appOpenedType: openedAppType})
175
 
174
 
176
   render () {
175
   render () {
177
     const { workspaceContent, contentType, match } = this.props
176
     const { workspaceContent, contentType, match } = this.props
196
       <div className='sidebarpagecontainer'>
195
       <div className='sidebarpagecontainer'>
197
         <Sidebar />
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
         <PageWrapper customeClass='workspace'>
204
         <PageWrapper customeClass='workspace'>
202
           <PageTitle
205
           <PageTitle