Browse Source

added PAGE_NAME var + now send logged user info to App

Skylsmoi 7 years ago
parent
commit
4439a13df1
6 changed files with 36 additions and 24 deletions
  1. 2 0
      .gitignore
  2. 13 14
      src/container/Tracim.jsx
  3. 7 5
      src/container/WorkspaceContent.jsx
  4. 0 2
      src/css/UploadPopup.styl
  5. 10 1
      src/helper.js
  6. 4 2
      src/reducer/user.js

+ 2 - 0
.gitignore View File

3
 .git/
3
 .git/
4
 node_modules/
4
 node_modules/
5
 /dist/tracim.app.entry.js
5
 /dist/tracim.app.entry.js
6
+/dist/tracim.app.entry.js.map
6
 /dist/tracim.vendor.bundle.js
7
 /dist/tracim.vendor.bundle.js
8
+/dist/tracim.vendor.bundle.js.map
7
 /dist/app/*
9
 /dist/app/*

+ 13 - 14
src/container/Tracim.jsx View File

12
   withRouter
12
   withRouter
13
 } from 'react-router-dom'
13
 } from 'react-router-dom'
14
 import PrivateRoute from './PrivateRoute.jsx'
14
 import PrivateRoute from './PrivateRoute.jsx'
15
+import { PAGE_NAME } from '../helper.js'
15
 import { getIsUserConnected } from '../action-creator.async.js'
16
 import { getIsUserConnected } from '../action-creator.async.js'
16
 
17
 
17
 class Tracim extends React.Component {
18
 class Tracim extends React.Component {
22
   render () {
23
   render () {
23
     const { user, location } = this.props
24
     const { user, location } = this.props
24
 
25
 
25
-    const SidebarWrapper = props => {
26
-      if (props.locationPath !== '/login') {
27
-        return (
28
-          <div className='sidebarpagecontainer'>
29
-            <Sidebar />
30
-            {props.children}
31
-          </div>
32
-        )
33
-      } else return props.children
34
-    }
26
+    const SidebarWrapper = props => props.locationPath !== '/login'
27
+      ? (
28
+        <div className='sidebarpagecontainer'>
29
+          <Sidebar />
30
+          {props.children}
31
+        </div>
32
+      )
33
+      : props.children
35
 
34
 
36
     return (
35
     return (
37
       <div>
36
       <div>
41
           ? (<div />) // while we dont know if user is connected, display nothing but the header @TODO show loader
40
           ? (<div />) // while we dont know if user is connected, display nothing but the header @TODO show loader
42
           : (
41
           : (
43
             <div>
42
             <div>
44
-              <Route path='/login' component={Login} />
43
+              <Route path={PAGE_NAME.LOGIN} component={Login} />
45
 
44
 
46
               <SidebarWrapper locationPath={location.pathname}>
45
               <SidebarWrapper locationPath={location.pathname}>
47
 
46
 
48
-                <PrivateRoute exact path='/' component={WorkspaceContent} />
49
-                <PrivateRoute exact path='/account' component={AccountPage} />
50
-                <PrivateRoute exact path='/dashboard' component={Dashboard} />
47
+                <PrivateRoute exact path={PAGE_NAME.HOME} component={WorkspaceContent} />
48
+                <PrivateRoute exact path={PAGE_NAME.ACCOUNT} component={AccountPage} />
49
+                <PrivateRoute exact path={PAGE_NAME.DASHBOARD} component={Dashboard} />
51
 
50
 
52
               </SidebarWrapper>
51
               </SidebarWrapper>
53
 
52
 

+ 7 - 5
src/container/WorkspaceContent.jsx View File

7
 import PageTitle from '../component/common/layout/PageTitle.jsx'
7
 import PageTitle from '../component/common/layout/PageTitle.jsx'
8
 import PageContent from '../component/common/layout/PageContent.jsx'
8
 import PageContent from '../component/common/layout/PageContent.jsx'
9
 import DropdownCreateButton from '../component/common/Input/DropdownCreateButton.jsx'
9
 import DropdownCreateButton from '../component/common/Input/DropdownCreateButton.jsx'
10
+import { FETCH_CONFIG } from '../helper.js'
10
 import {
11
 import {
11
   getAppList,
12
   getAppList,
12
   getWorkspaceContent
13
   getWorkspaceContent
27
   }
28
   }
28
 
29
 
29
   handleClickContentItem = content => {
30
   handleClickContentItem = content => {
30
-    const { workspace } = this.props
31
+    const { user, workspace } = this.props
31
     GLOBAL_renderApp({
32
     GLOBAL_renderApp({
32
       workspace: {
33
       workspace: {
33
         id: workspace.id,
34
         id: workspace.id,
34
         title: workspace.title
35
         title: workspace.title
35
       },
36
       },
36
-      content,
37
       appConfig: {
37
       appConfig: {
38
         ...this.props.app[content.type],
38
         ...this.props.app[content.type],
39
-        apiUrl: 'http://localhost:3001'
40
-      }
39
+        apiUrl: FETCH_CONFIG.apiUrl
40
+      },
41
+      loggedUser: user.isLoggedIn ? user : {},
42
+      content,
41
     })
43
     })
42
   }
44
   }
43
 
45
 
87
   }
89
   }
88
 }
90
 }
89
 
91
 
90
-const mapStateToProps = ({ workspace, activeFileContent, app }) => ({ workspace, activeFileContent, app })
92
+const mapStateToProps = ({ user, workspace, activeFileContent, app }) => ({ user, workspace, activeFileContent, app })
91
 export default connect(mapStateToProps)(WorkspaceContent)
93
 export default connect(mapStateToProps)(WorkspaceContent)

+ 0 - 2
src/css/UploadPopup.styl View File

25
     &__filename
25
     &__filename
26
       margin-top 30px
26
       margin-top 30px
27
       font-size 25px
27
       font-size 25px
28
-
29
-

+ 10 - 1
src/helper.js View File

2
   headers: {
2
   headers: {
3
     'Accept': 'application/json',
3
     'Accept': 'application/json',
4
     'Content-Type': 'application/json'
4
     'Content-Type': 'application/json'
5
-  }
5
+  },
6
+  apiUrl: 'http://localhost:3001'
7
+}
8
+
9
+export const PAGE_NAME = {
10
+  HOME: '/',
11
+  WS_CONTENT: '/',
12
+  LOGIN: '/login',
13
+  DASHBOARD: '/dashboard',
14
+  ACCOUNT: '/account'
6
 }
15
 }

+ 4 - 2
src/reducer/user.js View File

9
   username: data.user.username,
9
   username: data.user.username,
10
   firstname: data.user.firstname,
10
   firstname: data.user.firstname,
11
   lastname: data.user.lastname,
11
   lastname: data.user.lastname,
12
-  email: data.user.email
12
+  email: data.user.email,
13
+  avatar: data.user.avatar
13
 })
14
 })
14
 
15
 
15
 export default function user (state = {
16
 export default function user (state = {
18
   username: '',
19
   username: '',
19
   firstname: '',
20
   firstname: '',
20
   lastname: '',
21
   lastname: '',
21
-  email: ''
22
+  email: '',
23
+  avatar: ''
22
 }, action) {
24
 }, action) {
23
   switch (action.type) {
25
   switch (action.type) {
24
     case `Update/${USER_CONNECTED}`:
26
     case `Update/${USER_CONNECTED}`: