Browse Source

added colored debug msg + fixed double event sometimes emited

Skylsmoi 5 years ago
parent
commit
15714c45cb

+ 5 - 5
dist/index.html View File

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

+ 3 - 3
src/container/OpenContentApp.jsx View File

@@ -18,7 +18,7 @@ export class OpenContentApp extends React.Component {
18 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 23
       if (appOpenedType === contentToOpen.type) { // app already open
24 24
         GLOBAL_dispatchEvent({
@@ -40,13 +40,13 @@ export class OpenContentApp extends React.Component {
40 40
   }
41 41
 
42 42
   componentDidMount () {
43
-    console.log('OpenContentApp did Mount', this.props)
43
+    console.log('%c<OpenContentApp> did Mount', 'color: #dcae84', this.props)
44 44
 
45 45
     this.openContentApp()
46 46
   }
47 47
 
48 48
   componentDidUpdate () {
49
-    console.log('OpenContentApp did Update', this.props)
49
+    console.log('%c<OpenContentApp> did Update', 'color: #dcae84', this.props)
50 50
 
51 51
     this.openContentApp()
52 52
   }

+ 1 - 1
src/container/Sidebar.jsx View File

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

+ 31 - 25
src/container/WorkspaceContent.jsx View File

@@ -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 => {

+ 1 - 1
src/css/Generic.styl View File

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