Browse Source

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

Skylsmoi 5 years ago
parent
commit
9771052f39
3 changed files with 12 additions and 3 deletions
  1. 1 1
      src/container/PrivateRoute.jsx
  2. 7 1
      src/container/Sidebar.jsx
  3. 4 1
      src/container/WorkspaceContent.jsx

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

@@ -22,6 +22,6 @@ export default withRouter(connect(mapStateToProps)(PrivateRoute))
22 22
 PrivateRoute.propTypes = {
23 23
   component: PropTypes.func.isRequired,
24 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 View File

@@ -37,12 +37,18 @@ class Sidebar extends React.Component {
37 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 41
   handleClickContentFilter = (idWs, filter) => {
41 42
     const { workspace, history } = this.props
42 43
 
43 44
     const newFilter = workspace.filter.includes(filter) ? [] : [filter] // use an array to allow multiple filters (NYI)
44 45
 
46
+    console.log('wtf')
45 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 54
   handleClickToggleSidebar = () => this.setState(prev => ({sidebarClose: !prev.sidebarClose}))
@@ -70,7 +76,7 @@ class Sidebar extends React.Component {
70 76
                   isOpenInSidebar={ws.isOpenInSidebar}
71 77
                   onClickTitle={() => this.handleClickWorkspace(ws.id, !ws.isOpenInSidebar)}
72 78
                   onClickAllContent={this.handleClickAllContent}
73
-                  onClickContentFilter={this.handleClickContentFilter}
79
+                  // onClickContentFilter={this.handleClickContentFilter}
74 80
                   key={ws.id}
75 81
                 />
76 82
               )}

+ 4 - 1
src/container/WorkspaceContent.jsx View File

@@ -112,7 +112,10 @@ class WorkspaceContent extends React.Component {
112 112
 
113 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 119
       this.setState({workspaceIdInUrl: idWorkspace})
117 120
       this.loadContentList(idWorkspace)
118 121
     }