Parcourir la source

changing filters of a workspace now reload it's content from api

Skylsmoi il y a 5 ans
Parent
révision
9771052f39

+ 1 - 1
src/container/PrivateRoute.jsx Voir le fichier

22
 PrivateRoute.propTypes = {
22
 PrivateRoute.propTypes = {
23
   component: PropTypes.func.isRequired,
23
   component: PropTypes.func.isRequired,
24
   user: PropTypes.shape({ // user is get with redux connect
24
   user: PropTypes.shape({ // user is get with redux connect
25
-    logged: PropTypes.bool.isRequired
25
+    logged: PropTypes.any // can be true, false or null
26
   })
26
   })
27
 }
27
 }

+ 7 - 1
src/container/Sidebar.jsx Voir le fichier

37
     this.props.history.push(PAGE.WORKSPACE.CONTENT_LIST(idWs))
37
     this.props.history.push(PAGE.WORKSPACE.CONTENT_LIST(idWs))
38
   }
38
   }
39
 
39
 
40
+  // not used, right now, link on sidebar filters is a <Link>
40
   handleClickContentFilter = (idWs, filter) => {
41
   handleClickContentFilter = (idWs, filter) => {
41
     const { workspace, history } = this.props
42
     const { workspace, history } = this.props
42
 
43
 
43
     const newFilter = workspace.filter.includes(filter) ? [] : [filter] // use an array to allow multiple filters (NYI)
44
     const newFilter = workspace.filter.includes(filter) ? [] : [filter] // use an array to allow multiple filters (NYI)
44
 
45
 
46
+    console.log('wtf')
45
     history.push(`${PAGE.WORKSPACE.CONTENT_LIST(idWs)}?type=${newFilter.join(';')}`) // workspace.filter gets updated on react redraw from match.params
47
     history.push(`${PAGE.WORKSPACE.CONTENT_LIST(idWs)}?type=${newFilter.join(';')}`) // workspace.filter gets updated on react redraw from match.params
48
+
49
+    // obviously, it's ugly to use custom event to tell WorkspaceContent to refresh, but since WorkspaceContent
50
+    // will end up being an App, it'll have to be that way. So it's fine
51
+    GLOBAL_dispatchEvent({ type: 'refreshContentList', data: {} })
46
   }
52
   }
47
 
53
 
48
   handleClickToggleSidebar = () => this.setState(prev => ({sidebarClose: !prev.sidebarClose}))
54
   handleClickToggleSidebar = () => this.setState(prev => ({sidebarClose: !prev.sidebarClose}))
70
                   isOpenInSidebar={ws.isOpenInSidebar}
76
                   isOpenInSidebar={ws.isOpenInSidebar}
71
                   onClickTitle={() => this.handleClickWorkspace(ws.id, !ws.isOpenInSidebar)}
77
                   onClickTitle={() => this.handleClickWorkspace(ws.id, !ws.isOpenInSidebar)}
72
                   onClickAllContent={this.handleClickAllContent}
78
                   onClickAllContent={this.handleClickAllContent}
73
-                  onClickContentFilter={this.handleClickContentFilter}
79
+                  // onClickContentFilter={this.handleClickContentFilter}
74
                   key={ws.id}
80
                   key={ws.id}
75
                 />
81
                 />
76
               )}
82
               )}

+ 4 - 1
src/container/WorkspaceContent.jsx Voir le fichier

112
 
112
 
113
     if (isNaN(idWorkspace)) return
113
     if (isNaN(idWorkspace)) return
114
 
114
 
115
-    if (prevState.workspaceIdInUrl !== idWorkspace) {
115
+    const prevFilter = qs.parse(prevProps.location.search).type
116
+    const currentFilter = qs.parse(this.props.location.search).type
117
+
118
+    if (prevState.workspaceIdInUrl !== idWorkspace || prevFilter !== currentFilter) {
116
       this.setState({workspaceIdInUrl: idWorkspace})
119
       this.setState({workspaceIdInUrl: idWorkspace})
117
       this.loadContentList(idWorkspace)
120
       this.loadContentList(idWorkspace)
118
     }
121
     }