Pārlūkot izejas kodu

added colored debug msg + fixed double event sometimes emited

Skylsmoi 5 gadus atpakaļ
vecāks
revīzija
15714c45cb

+ 5 - 5
dist/index.html Parādīt failu

48
       }
48
       }
49
 
49
 
50
       GLOBAL_renderApp = app => {
50
       GLOBAL_renderApp = app => {
51
-        console.log('GLOBAL_renderApp', app)
51
+        console.log('%cGLOBAL_renderApp', 'color: #5cebeb', app)
52
 
52
 
53
         const selectedApp = getSelectedApp(app.config.slug)
53
         const selectedApp = getSelectedApp(app.config.slug)
54
 
54
 
63
       }
63
       }
64
 
64
 
65
       GLOBAL_renderCreateContentApp = app => {
65
       GLOBAL_renderCreateContentApp = app => {
66
-        console.log('GLOBAL_renderCreateContentApp', app)
66
+        console.log('%cGLOBAL_renderCreateContentApp', 'color: #5cebeb', app)
67
 
67
 
68
         getSelectedApp(app.config.slug).renderPopupCreation(app)
68
         getSelectedApp(app.config.slug).renderPopupCreation(app)
69
       }
69
       }
70
 
70
 
71
       GLOBAL_dispatchEvent = ({ type, data }) => {
71
       GLOBAL_dispatchEvent = ({ type, data }) => {
72
-        console.log('GLOBAL_dispatchEvent', type, data)
72
+        console.log('%cGLOBAL_dispatchEvent', 'color: #fff', type, data)
73
 
73
 
74
         const event = new CustomEvent('appCustomEvent', { detail: { type, data } })
74
         const event = new CustomEvent('appCustomEvent', { detail: { type, data } })
75
         document.dispatchEvent(event)
75
         document.dispatchEvent(event)
78
       GLOBAL_eventReducer = ({ detail: { type, data } }) => {
78
       GLOBAL_eventReducer = ({ detail: { type, data } }) => {
79
         switch (type) {
79
         switch (type) {
80
           case 'hide_popupCreateContent':
80
           case 'hide_popupCreateContent':
81
-            console.log('GLOBAL_eventReducer', type, data)
81
+            console.log('%cGLOBAL_eventReducer Custom Event', 'color: #28a745', type, data)
82
             getSelectedApp(data.name).unmountApp('popupCreateContentContainer')
82
             getSelectedApp(data.name).unmountApp('popupCreateContentContainer')
83
             break
83
             break
84
           case 'unmount_app':
84
           case 'unmount_app':
85
-            console.log('GLOBAL_eventReducer', type, data)
85
+            console.log('%cGLOBAL_eventReducer Custom Event', 'color: #28a745', type, data)
86
             if (prevSelectedApp.name === '') return
86
             if (prevSelectedApp.name === '') return
87
 
87
 
88
             prevSelectedApp.unmountApp('appContainer')
88
             prevSelectedApp.unmountApp('appContainer')

+ 3 - 3
src/container/OpenContentApp.jsx Parādīt failu

18
         type: match.params.type
18
         type: match.params.type
19
       }
19
       }
20
 
20
 
21
-      console.log('contentToOpen', contentToOpen)
21
+      console.log('%c<OpenContentApp> contentToOpen', 'color: #dcae84', contentToOpen)
22
 
22
 
23
       if (appOpenedType === contentToOpen.type) { // app already open
23
       if (appOpenedType === contentToOpen.type) { // app already open
24
         GLOBAL_dispatchEvent({
24
         GLOBAL_dispatchEvent({
40
   }
40
   }
41
 
41
 
42
   componentDidMount () {
42
   componentDidMount () {
43
-    console.log('OpenContentApp did Mount', this.props)
43
+    console.log('%c<OpenContentApp> did Mount', 'color: #dcae84', this.props)
44
 
44
 
45
     this.openContentApp()
45
     this.openContentApp()
46
   }
46
   }
47
 
47
 
48
   componentDidUpdate () {
48
   componentDidUpdate () {
49
-    console.log('OpenContentApp did Update', this.props)
49
+    console.log('%c<OpenContentApp> did Update', 'color: #dcae84', this.props)
50
 
50
 
51
     this.openContentApp()
51
     this.openContentApp()
52
   }
52
   }

+ 1 - 1
src/container/Sidebar.jsx Parādīt failu

22
   }
22
   }
23
 
23
 
24
   componentDidUpdate (prevProps, prevState) {
24
   componentDidUpdate (prevProps, prevState) {
25
-    console.log('<Sidebar> Did Update')
25
+    // console.log('%c<Sidebar> Did Update', 'color: #c17838')
26
     if (this.props.match.params.idws === undefined || isNaN(this.props.match.params.idws)) return
26
     if (this.props.match.params.idws === undefined || isNaN(this.props.match.params.idws)) return
27
 
27
 
28
     const newWorkspaceId = parseInt(this.props.match.params.idws)
28
     const newWorkspaceId = parseInt(this.props.match.params.idws)

+ 31 - 25
src/container/WorkspaceContent.jsx Parādīt failu

46
     document.addEventListener('appCustomEvent', this.customEventReducer)
46
     document.addEventListener('appCustomEvent', this.customEventReducer)
47
   }
47
   }
48
 
48
 
49
-  customEventReducer = ({ detail: { type, data } }) => {
49
+  customEventReducer = async ({ detail: { type, data } }) => {
50
     switch (type) {
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
       case 'openContentUrl':
56
       case 'openContentUrl':
52
-        console.log('<WorkspaceContent>', type, data)
57
+        console.log('%c<WorkspaceContent> Custom event', 'color: #28a745', type, data)
53
         this.props.history.push(PAGE.WORKSPACE.CONTENT(data.idWorkspace, data.contentType, data.idContent))
58
         this.props.history.push(PAGE.WORKSPACE.CONTENT(data.idWorkspace, data.contentType, data.idContent))
54
         break
59
         break
60
+
55
       case 'appClosed':
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
         this.props.history.push(PAGE.WORKSPACE.CONTENT_LIST(this.state.workspaceIdInUrl))
63
         this.props.history.push(PAGE.WORKSPACE.CONTENT_LIST(this.state.workspaceIdInUrl))
59
         this.setState({appOpenedType: false})
64
         this.setState({appOpenedType: false})
60
         break
65
         break
63
 
68
 
64
   async componentDidMount () {
69
   async componentDidMount () {
65
     const { workspaceIdInUrl } = this.state
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
     if (app.length === 0) {
75
     if (app.length === 0) {
71
       const fetchGetAppList = await dispatch(getAppList(user))
76
       const fetchGetAppList = await dispatch(getAppList(user))
95
 
100
 
96
     if (wsToLoad === null) return // ws already loaded
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
   async componentDidUpdate (prevProps, prevState) {
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
     if (this.state.workspaceIdInUrl === null) return
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
     if (isNaN(idWorkspace)) return
113
     if (isNaN(idWorkspace)) return
114
 
114
 
115
     if (prevState.workspaceIdInUrl !== idWorkspace) {
115
     if (prevState.workspaceIdInUrl !== idWorkspace) {
116
       this.setState({workspaceIdInUrl: idWorkspace})
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
     // if (user.user_id !== -1 && prevProps.user.id !== user.id) dispatch(getWorkspaceList(user.user_id, idWorkspace))
120
     // if (user.user_id !== -1 && prevProps.user.id !== user.id) dispatch(getWorkspaceList(user.user_id, idWorkspace))
126
 
122
 
127
   componentWillUnmount () {
123
   componentWillUnmount () {
128
     this.props.emitEventApp('unmount_app')
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
   handleClickContentItem = content => {
137
   handleClickContentItem = content => {
132
-    console.log('content clicked', content)
138
+    console.log('%c<WorkspaceContent> content clicked', 'color: #c17838', content)
133
     this.props.history.push(`/workspaces/${content.idWorkspace}/${content.type}/${content.id}`)
139
     this.props.history.push(`/workspaces/${content.idWorkspace}/${content.type}/${content.id}`)
134
   }
140
   }
135
 
141
 
136
   handleClickEditContentItem = (e, content) => {
142
   handleClickEditContentItem = (e, content) => {
137
     e.stopPropagation()
143
     e.stopPropagation()
138
-    console.log('edit nyi', content)
144
+    console.log('%c<WorkspaceContent> edit nyi', 'color: #c17838', content)
139
   }
145
   }
140
 
146
 
141
   handleClickMoveContentItem = (e, content) => {
147
   handleClickMoveContentItem = (e, content) => {
142
     e.stopPropagation()
148
     e.stopPropagation()
143
-    console.log('move nyi', content)
149
+    console.log('%c<WorkspaceContent> move nyi', 'color: #c17838', content)
144
   }
150
   }
145
 
151
 
146
   handleClickDownloadContentItem = (e, content) => {
152
   handleClickDownloadContentItem = (e, content) => {
147
     e.stopPropagation()
153
     e.stopPropagation()
148
-    console.log('download nyi', content)
154
+    console.log('%c<WorkspaceContent> download nyi', 'color: #c17838', content)
149
   }
155
   }
150
 
156
 
151
   handleClickArchiveContentItem = (e, content) => {
157
   handleClickArchiveContentItem = (e, content) => {
152
     e.stopPropagation()
158
     e.stopPropagation()
153
-    console.log('archive nyi', content)
159
+    console.log('%c<WorkspaceContent> archive nyi', 'color: #c17838', content)
154
   }
160
   }
155
 
161
 
156
   handleClickDeleteContentItem = (e, content) => {
162
   handleClickDeleteContentItem = (e, content) => {
157
     e.stopPropagation()
163
     e.stopPropagation()
158
-    console.log('delete nyi', content)
164
+    console.log('%c<WorkspaceContent> delete nyi', 'color: #c17838', content)
159
   }
165
   }
160
 
166
 
161
   handleClickFolder = folderId => {
167
   handleClickFolder = folderId => {

+ 1 - 1
src/css/Generic.styl Parādīt failu

64
   min-height calc(100% - 50px)
64
   min-height calc(100% - 50px)
65
 
65
 
66
 .pageWrapperGeneric
66
 .pageWrapperGeneric
67
-  width calc(100% - 300px) // 300px => width of the sidebar + margin
67
+  width 100%
68
   &__header
68
   &__header
69
     display flex
69
     display flex
70
   &__content
70
   &__content