Browse Source

added PAGE_NAME var + now send logged user info to App

Skylsmoi 6 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,5 +3,7 @@
3 3
 .git/
4 4
 node_modules/
5 5
 /dist/tracim.app.entry.js
6
+/dist/tracim.app.entry.js.map
6 7
 /dist/tracim.vendor.bundle.js
8
+/dist/tracim.vendor.bundle.js.map
7 9
 /dist/app/*

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

@@ -12,6 +12,7 @@ import {
12 12
   withRouter
13 13
 } from 'react-router-dom'
14 14
 import PrivateRoute from './PrivateRoute.jsx'
15
+import { PAGE_NAME } from '../helper.js'
15 16
 import { getIsUserConnected } from '../action-creator.async.js'
16 17
 
17 18
 class Tracim extends React.Component {
@@ -22,16 +23,14 @@ class Tracim extends React.Component {
22 23
   render () {
23 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 35
     return (
37 36
       <div>
@@ -41,13 +40,13 @@ class Tracim extends React.Component {
41 40
           ? (<div />) // while we dont know if user is connected, display nothing but the header @TODO show loader
42 41
           : (
43 42
             <div>
44
-              <Route path='/login' component={Login} />
43
+              <Route path={PAGE_NAME.LOGIN} component={Login} />
45 44
 
46 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 51
               </SidebarWrapper>
53 52
 

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

@@ -7,6 +7,7 @@ import PageWrapper from '../component/common/layout/PageWrapper.jsx'
7 7
 import PageTitle from '../component/common/layout/PageTitle.jsx'
8 8
 import PageContent from '../component/common/layout/PageContent.jsx'
9 9
 import DropdownCreateButton from '../component/common/Input/DropdownCreateButton.jsx'
10
+import { FETCH_CONFIG } from '../helper.js'
10 11
 import {
11 12
   getAppList,
12 13
   getWorkspaceContent
@@ -27,17 +28,18 @@ class WorkspaceContent extends React.Component {
27 28
   }
28 29
 
29 30
   handleClickContentItem = content => {
30
-    const { workspace } = this.props
31
+    const { user, workspace } = this.props
31 32
     GLOBAL_renderApp({
32 33
       workspace: {
33 34
         id: workspace.id,
34 35
         title: workspace.title
35 36
       },
36
-      content,
37 37
       appConfig: {
38 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,5 +89,5 @@ class WorkspaceContent extends React.Component {
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 93
 export default connect(mapStateToProps)(WorkspaceContent)

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

@@ -25,5 +25,3 @@
25 25
     &__filename
26 26
       margin-top 30px
27 27
       font-size 25px
28
-
29
-

+ 10 - 1
src/helper.js View File

@@ -2,5 +2,14 @@ export const FETCH_CONFIG = {
2 2
   headers: {
3 3
     'Accept': 'application/json',
4 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,7 +9,8 @@ const serializeUser = data => ({
9 9
   username: data.user.username,
10 10
   firstname: data.user.firstname,
11 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 16
 export default function user (state = {
@@ -18,7 +19,8 @@ export default function user (state = {
18 19
   username: '',
19 20
   firstname: '',
20 21
   lastname: '',
21
-  email: ''
22
+  email: '',
23
+  avatar: ''
22 24
 }, action) {
23 25
   switch (action.type) {
24 26
     case `Update/${USER_CONNECTED}`: