|
@@ -46,15 +46,20 @@ class WorkspaceContent extends React.Component {
|
46
|
46
|
document.addEventListener('appCustomEvent', this.customEventReducer)
|
47
|
47
|
}
|
48
|
48
|
|
49
|
|
- customEventReducer = ({ detail: { type, data } }) => {
|
|
49
|
+ customEventReducer = async ({ detail: { type, data } }) => {
|
50
|
50
|
switch (type) {
|
|
51
|
+ case 'refreshContentList':
|
|
52
|
+ console.log('%c<WorkspaceContent> Custom event', 'color: #28a745', type, data)
|
|
53
|
+ this.loadContentList(this.state.workspaceIdInUrl)
|
|
54
|
+ break
|
|
55
|
+
|
51
|
56
|
case 'openContentUrl':
|
52
|
|
- console.log('<WorkspaceContent>', type, data)
|
|
57
|
+ console.log('%c<WorkspaceContent> Custom event', 'color: #28a745', type, data)
|
53
|
58
|
this.props.history.push(PAGE.WORKSPACE.CONTENT(data.idWorkspace, data.contentType, data.idContent))
|
54
|
59
|
break
|
|
60
|
+
|
55
|
61
|
case 'appClosed':
|
56
|
|
- console.log('<WorkspaceContent>', type, data, this.state.workspaceIdInUrl)
|
57
|
|
- if (this.state.workspaceIdInUrl === null) return // @FIXME: find out why when app is closed, workspaceInUrl is null then has it's proper value
|
|
62
|
+ console.log('%c<WorkspaceContent> Custom event', 'color: #28a745', type, data, this.state.workspaceIdInUrl)
|
58
|
63
|
this.props.history.push(PAGE.WORKSPACE.CONTENT_LIST(this.state.workspaceIdInUrl))
|
59
|
64
|
this.setState({appOpenedType: false})
|
60
|
65
|
break
|
|
@@ -63,9 +68,9 @@ class WorkspaceContent extends React.Component {
|
63
|
68
|
|
64
|
69
|
async componentDidMount () {
|
65
|
70
|
const { workspaceIdInUrl } = this.state
|
66
|
|
- const { user, workspaceList, app, contentType, match, location, dispatch } = this.props
|
|
71
|
+ const { user, workspaceList, app, contentType, match, dispatch } = this.props
|
67
|
72
|
|
68
|
|
- console.log('<WorkspaceContent> componentDidMount')
|
|
73
|
+ console.log('%c<WorkspaceContent> componentDidMount', 'color: #c17838')
|
69
|
74
|
|
70
|
75
|
if (app.length === 0) {
|
71
|
76
|
const fetchGetAppList = await dispatch(getAppList(user))
|
|
@@ -95,30 +100,21 @@ class WorkspaceContent extends React.Component {
|
95
|
100
|
|
96
|
101
|
if (wsToLoad === null) return // ws already loaded
|
97
|
102
|
|
98
|
|
- const wsContent = await dispatch(getWorkspaceContentList(user, wsToLoad, 0))
|
99
|
|
-
|
100
|
|
- if (wsContent.status === 200) dispatch(setWorkspaceContent(wsContent.json, qs.parse(location.search).type))
|
101
|
|
- else dispatch(newFlashMessage('Error while loading workspace', 'danger'))
|
|
103
|
+ this.loadContentList(wsToLoad)
|
102
|
104
|
}
|
103
|
105
|
|
104
|
106
|
async componentDidUpdate (prevProps, prevState) {
|
105
|
|
- const { user, match, location, dispatch } = this.props
|
106
|
|
-
|
107
|
|
- console.log('<WorkspaceContent> componentDidUpdate')
|
|
107
|
+ console.log('%c<WorkspaceContent> componentDidUpdate', 'color: #c17838')
|
108
|
108
|
|
109
|
109
|
if (this.state.workspaceIdInUrl === null) return
|
110
|
110
|
|
111
|
|
- const idWorkspace = parseInt(match.params.idws)
|
|
111
|
+ const idWorkspace = parseInt(this.props.match.params.idws)
|
112
|
112
|
|
113
|
113
|
if (isNaN(idWorkspace)) return
|
114
|
114
|
|
115
|
115
|
if (prevState.workspaceIdInUrl !== idWorkspace) {
|
116
|
116
|
this.setState({workspaceIdInUrl: idWorkspace})
|
117
|
|
-
|
118
|
|
- const wsContent = await dispatch(getWorkspaceContentList(user, idWorkspace, 0))
|
119
|
|
-
|
120
|
|
- if (wsContent.status === 200) dispatch(setWorkspaceContent(wsContent.json, qs.parse(location.search).type))
|
121
|
|
- else dispatch(newFlashMessage('Error while loading workspace', 'danger'))
|
|
117
|
+ this.loadContentList(idWorkspace)
|
122
|
118
|
}
|
123
|
119
|
|
124
|
120
|
// if (user.user_id !== -1 && prevProps.user.id !== user.id) dispatch(getWorkspaceList(user.user_id, idWorkspace))
|
|
@@ -126,36 +122,46 @@ class WorkspaceContent extends React.Component {
|
126
|
122
|
|
127
|
123
|
componentWillUnmount () {
|
128
|
124
|
this.props.emitEventApp('unmount_app')
|
|
125
|
+ document.removeEventListener('appCustomEvent', this.customEventReducer)
|
|
126
|
+ }
|
|
127
|
+
|
|
128
|
+ loadContentList = async idWorkspace => {
|
|
129
|
+ const { user, location, dispatch } = this.props
|
|
130
|
+
|
|
131
|
+ const wsContent = await dispatch(getWorkspaceContentList(user, idWorkspace, 0))
|
|
132
|
+
|
|
133
|
+ if (wsContent.status === 200) dispatch(setWorkspaceContent(wsContent.json, qs.parse(location.search).type))
|
|
134
|
+ else dispatch(newFlashMessage('Error while loading workspace', 'danger'))
|
129
|
135
|
}
|
130
|
136
|
|
131
|
137
|
handleClickContentItem = content => {
|
132
|
|
- console.log('content clicked', content)
|
|
138
|
+ console.log('%c<WorkspaceContent> content clicked', 'color: #c17838', content)
|
133
|
139
|
this.props.history.push(`/workspaces/${content.idWorkspace}/${content.type}/${content.id}`)
|
134
|
140
|
}
|
135
|
141
|
|
136
|
142
|
handleClickEditContentItem = (e, content) => {
|
137
|
143
|
e.stopPropagation()
|
138
|
|
- console.log('edit nyi', content)
|
|
144
|
+ console.log('%c<WorkspaceContent> edit nyi', 'color: #c17838', content)
|
139
|
145
|
}
|
140
|
146
|
|
141
|
147
|
handleClickMoveContentItem = (e, content) => {
|
142
|
148
|
e.stopPropagation()
|
143
|
|
- console.log('move nyi', content)
|
|
149
|
+ console.log('%c<WorkspaceContent> move nyi', 'color: #c17838', content)
|
144
|
150
|
}
|
145
|
151
|
|
146
|
152
|
handleClickDownloadContentItem = (e, content) => {
|
147
|
153
|
e.stopPropagation()
|
148
|
|
- console.log('download nyi', content)
|
|
154
|
+ console.log('%c<WorkspaceContent> download nyi', 'color: #c17838', content)
|
149
|
155
|
}
|
150
|
156
|
|
151
|
157
|
handleClickArchiveContentItem = (e, content) => {
|
152
|
158
|
e.stopPropagation()
|
153
|
|
- console.log('archive nyi', content)
|
|
159
|
+ console.log('%c<WorkspaceContent> archive nyi', 'color: #c17838', content)
|
154
|
160
|
}
|
155
|
161
|
|
156
|
162
|
handleClickDeleteContentItem = (e, content) => {
|
157
|
163
|
e.stopPropagation()
|
158
|
|
- console.log('delete nyi', content)
|
|
164
|
+ console.log('%c<WorkspaceContent> delete nyi', 'color: #c17838', content)
|
159
|
165
|
}
|
160
|
166
|
|
161
|
167
|
handleClickFolder = folderId => {
|