|
@@ -14,33 +14,41 @@ import {
|
14
|
14
|
getWorkspaceContent,
|
15
|
15
|
getFolderContent
|
16
|
16
|
} from '../action-creator.async.js'
|
|
17
|
+import {newFlashMessage, setWorkspaceData} from '../action-creator.sync.js'
|
|
18
|
+import { PAGE } from '../helper.js'
|
|
19
|
+
|
|
20
|
+const qs = require('query-string')
|
17
|
21
|
|
18
|
22
|
class WorkspaceContent extends React.Component {
|
19
|
|
- componentDidMount () {
|
20
|
|
- const { workspaceList, app, match, dispatch } = this.props
|
|
23
|
+ async componentDidMount () {
|
|
24
|
+ const { workspaceList, app, match, location, dispatch } = this.props
|
21
|
25
|
|
22
|
|
- if (match.params.idws !== undefined) dispatch(getWorkspaceContent(match.params.idws, match.params.filter))
|
23
|
|
- else if (workspaceList.length > 0) dispatch(getWorkspaceContent(workspaceList[0].id, match.params.filter)) // load first ws if none specified
|
|
26
|
+ if (Object.keys(app).length === 0) await dispatch(getAppList())
|
24
|
27
|
|
25
|
|
- if (Object.keys(app).length === 0) dispatch(getAppList())
|
26
|
|
- }
|
|
28
|
+ const wsToLoad = (() => {
|
|
29
|
+ if (match.params.idws !== undefined) return match.params.idws
|
|
30
|
+ if (workspaceList.length > 0) return workspaceList[0].id // load first ws if none specified
|
|
31
|
+ return null
|
|
32
|
+ })()
|
|
33
|
+
|
|
34
|
+ if (wsToLoad === null) return
|
27
|
35
|
|
28
|
|
- componentDidUpdate (prevProps) {
|
29
|
|
- const { workspace, workspaceList, match, dispatch } = this.props
|
|
36
|
+ const wsContent = await dispatch(getWorkspaceContent(wsToLoad))
|
|
37
|
+ if (wsContent.status === 200) {
|
|
38
|
+ dispatch(setWorkspaceData(wsContent.json, qs.parse(location.search).type))
|
30
|
39
|
|
31
|
|
- // if a workspace is already loaded and the idws in url hasn't changed, do nothing
|
32
|
|
- if (workspace.id !== -1 && prevProps.match.params.idws === match.params.idws) return
|
|
40
|
+ if (match.params.idcts) { // if a content id is in url, open it
|
|
41
|
+ const contentToOpen = wsContent.json.content.find(wsc => wsc.id === parseInt(match.params.idcts))
|
|
42
|
+ if (contentToOpen === undefined) return
|
33
|
43
|
|
34
|
|
- // if the idws in url has changed, load the new workspace
|
35
|
|
- if (match.params.idws !== undefined) dispatch(getWorkspaceContent(match.params.idws, match.params.filter))
|
36
|
|
- // else bellow is for loading url PAGE_NAME.HOME (without an idws), when workspaceList is loaded, load the first workspace
|
37
|
|
- else if (workspace.id === -1 && workspaceList.length > 0) dispatch(getWorkspaceContent(workspaceList[0].id))
|
|
44
|
+ this.handleClickContentItem(contentToOpen)
|
|
45
|
+ }
|
|
46
|
+ } else dispatch(newFlashMessage('Error while loading workspace', 'danger'))
|
38
|
47
|
}
|
39
|
48
|
|
40
|
49
|
handleClickContentItem = content => {
|
|
50
|
+ this.props.history.push(`${PAGE.WORKSPACE.CONTENT(content.workspace_id, content.id)}${this.props.location.search}`)
|
41
|
51
|
this.props.renderApp(this.props.app[content.type], this.props.user, {...content, workspace: this.props.workspace})
|
42
|
|
- // Côme - 2018/03/08 - line bellow is useless because we cannot call the reducer again when hiding app since the call comes from the app
|
43
|
|
- // dispatch(setActiveFileContentActive(content))
|
44
|
52
|
}
|
45
|
53
|
|
46
|
54
|
handleClickEditContentItem = (e, content) => {
|