Browse Source

improved routes management

Skylsmoi 5 years ago
parent
commit
cff6632433
3 changed files with 30 additions and 29 deletions
  1. 1 1
      frontend/src/container/Sidebar.jsx
  2. 28 27
      frontend/src/container/Tracim.jsx
  3. 1 1
      frontend/src/reducer/user.js

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

@@ -107,7 +107,7 @@ class Sidebar extends React.Component {
107 107
     return (
108 108
       <div className={classnames('sidebar primaryColorBgDarken', {'sidebarclose': sidebarClose})}>
109 109
         <div className='sidebarSticky'>
110
-          <div className='sidebar__expand primaryColorBg whiteColorBorder' onClick={this.handleClickToggleSidebar}>
110
+          <div className='sidebar__expand primaryColorBg' onClick={this.handleClickToggleSidebar}>
111 111
             <i className={classnames('fa fa-chevron-left', {'fa-chevron-right': sidebarClose, 'fa-chevron-left': !sidebarClose})} />
112 112
           </div>
113 113
 

+ 28 - 27
frontend/src/container/Tracim.jsx View File

@@ -70,6 +70,12 @@ class Tracim extends React.Component {
70 70
   render () {
71 71
     const { props } = this
72 72
 
73
+    if (props.user.logged === null) return null // @TODO show loader
74
+
75
+    if (props.user.logged === false && props.location.pathname !== '/login') {
76
+      return <Redirect to={{pathname: '/login', state: {from: props.location}}} />
77
+    }
78
+
73 79
     return (
74 80
       <div className='tracim'>
75 81
         <Header />
@@ -89,34 +95,29 @@ class Tracim extends React.Component {
89 95
             }
90 96
           }} />
91 97
 
92
-          { props.user.logged
93
-            ? (
94
-              <Route path='/workspaces/:idws?' render={() => // Workspace Router
95
-                <div className='sidebarpagecontainer'>
96
-                  <Sidebar />
97
-
98
-                  <Route exact path={PAGE.WORKSPACE.ROOT} render={() => props.workspaceList.length === 0 // handle '/' and redirect to first workspace
99
-                    ? null
100
-                    : <Redirect to={{pathname: `/workspaces/${props.workspaceList[0].id}/contents`, state: {from: props.location}}} />
101
-                  } />
102
-
103
-                  <Route exact path={`${PAGE.WORKSPACE.ROOT}/:idws`} render={props2 => // handle '/workspaces/:id' and add '/contents'
104
-                    <Redirect to={{pathname: `/workspaces/${props2.match.params.idws}/contents`, state: {from: props.location}}} />
105
-                  } />
106
-
107
-                  <Route path={PAGE.WORKSPACE.DASHBOARD(':idws')} component={Dashboard} />
108
-                  <Route path={PAGE.WORKSPACE.CALENDAR(':idws')} component={() => <div><br /><br /><br /><br />NYI</div>} />
109
-                  <Route path={PAGE.WORKSPACE.CONTENT(':idws', ':type', ':idcts')} component={WorkspaceContent} />
110
-                  <Route exact path={PAGE.WORKSPACE.CONTENT_LIST(':idws')} component={WorkspaceContent} />
111
-
112
-                  <Route path={PAGE.ACCOUNT} component={Account} />
113
-                  <Route path={PAGE.ADMIN.ROOT} component={AppFullscreenManager} />
114
-                </div>
98
+          <Route path='/workspaces/:idws?' render={() => // Workspace Router
99
+            <div className='sidebarpagecontainer'>
100
+              <Sidebar />
101
+
102
+              <Route exact path={PAGE.WORKSPACE.ROOT} render={() => props.workspaceList.length === 0 // handle '/' and redirect to first workspace
103
+                ? null // @FIXME this needs to be handled in case of new user that has no workspace
104
+                : <Redirect to={{pathname: `/workspaces/${props.workspaceList[0].id}/contents`, state: {from: props.location}}} />
115 105
               } />
116
-            )
117
-            : props.user.logged === false && props.location.pathname !== '/login' &&
118
-              <Redirect to={{pathname: '/login', state: {from: props.location}}} />
119
-          }
106
+
107
+              <Route exact path={`${PAGE.WORKSPACE.ROOT}/:idws`} render={props2 => // handle '/workspaces/:id' and add '/contents'
108
+                <Redirect to={{pathname: `/workspaces/${props2.match.params.idws}/contents`, state: {from: props.location}}} />
109
+              } />
110
+
111
+              <Route path={PAGE.WORKSPACE.DASHBOARD(':idws')} component={Dashboard} />
112
+              <Route path={PAGE.WORKSPACE.CALENDAR(':idws')} component={() => <div><br /><br /><br /><br />NYI</div>} />
113
+              <Route path={PAGE.WORKSPACE.CONTENT(':idws', ':type', ':idcts')} component={WorkspaceContent} />
114
+              <Route exact path={PAGE.WORKSPACE.CONTENT_LIST(':idws')} component={WorkspaceContent} />
115
+            </div>
116
+          } />
117
+
118
+          <Route path={PAGE.ACCOUNT} component={Account} />
119
+
120
+          <Route path={PAGE.ADMIN.ROOT} component={AppFullscreenManager} />
120 121
 
121 122
           <Route path='/admin_temp/workspace' component={AdminWorkspacePage} />
122 123
 

+ 1 - 1
frontend/src/reducer/user.js View File

@@ -35,7 +35,7 @@ export default function user (state = defaultUser, action) {
35 35
       }
36 36
 
37 37
     case `${SET}/${USER_DISCONNECTED}`:
38
-      return defaultUser
38
+      return {...defaultUser, logged: false}
39 39
 
40 40
     case `${UPDATE}/${USER_DATA}`:
41 41
       return {...state, ...action.data}