Browse Source

added handleFetchResult + fixed timeline

Skylsmoi 7 years ago
parent
commit
15e256142f

+ 0 - 5
src/component/PopinFixed/PopinFixed.jsx View File

18
 export default PopinFixed
18
 export default PopinFixed
19
 
19
 
20
 PopinFixed.propTypes = {
20
 PopinFixed.propTypes = {
21
-  customClass: PropTypes.string,
22
-  visible: PropTypes.bool
23
-}
24
-
25
-PopinFixed.propTypes = {
26
   // from http://www.mattzabriskie.com/blog/react-validating-children
21
   // from http://www.mattzabriskie.com/blog/react-validating-children
27
   children: PropTypes.arrayOf((children, key, componentName /* , location, propFullName */) => {
22
   children: PropTypes.arrayOf((children, key, componentName /* , location, propFullName */) => {
28
     if (
23
     if (

+ 1 - 2
src/component/PopinFixed/PopinFixed.styl View File

8
   height 100%
8
   height 100%
9
   background-color lightGrey
9
   background-color lightGrey
10
   box-shadow shadow-page
10
   box-shadow shadow-page
11
-  visibility hidden
12
   z-index 1
11
   z-index 1
13
   &.visible
12
   &.visible
14
     visibility visible
13
     visibility visible
32
       color white
31
       color white
33
       font-size 20px
32
       font-size 20px
34
       cursor pointer
33
       cursor pointer
35
-      &:hover , &:focus
34
+      &:hover, &:focus
36
         border 1px solid off-white
35
         border 1px solid off-white
37
         padding 0 10px
36
         padding 0 10px
38
         border-radius 5px
37
         border-radius 5px

+ 7 - 3
src/component/PopinFixed/PopinFixedContent.jsx View File

26
 
26
 
27
 PopinFixedContent.propTypes = {
27
 PopinFixedContent.propTypes = {
28
   customClass: PropTypes.string,
28
   customClass: PropTypes.string,
29
-  children: PropTypes.arrayOf((children, key, componentName /* , location, propFullName */) =>
30
-    children.length !== 2 && new Error(`PropType Error: ${componentName} must have 2 children.`)
31
-  ).isRequired
29
+  children: (props, propName, componentName) => {
30
+    if (Array.isArray(props) && props.length !== 2) {
31
+      return new Error(`PropType Error: ${componentName} must have 1 or 2 children.`)
32
+    } else if (typeof props !== 'object') {
33
+      return new Error(`PropType Error: childrens of ${componentName} must have 1 or 2 children.`)
34
+    }
35
+  }
32
 }
36
 }

+ 73 - 76
src/component/Timeline/Timeline.jsx View File

1
 import React from 'react'
1
 import React from 'react'
2
+import PropTypes from 'prop-types'
2
 import classnames from 'classnames'
3
 import classnames from 'classnames'
3
-import imgProfil from '../../img/imgProfil.png'
4
-import imgProfilReverse from '../../img/imgProfil-reverse.png'
5
 
4
 
6
 require('./Timeline.styl')
5
 require('./Timeline.styl')
7
 
6
 
7
+const Message = props => (
8
+  <li className={classnames(
9
+    `${props.customClass}__messagelist__item`,
10
+    'timeline__messagelist__item',
11
+    {
12
+      'sended': props.fromMe,
13
+      'received': !props.fromMe
14
+    }
15
+  )}>
16
+    <div className={classnames(`${props.customClass}__messagelist__item__avatar`, 'timeline__messagelist__item__avatar')}>
17
+      <img src={props.avatar} alt='avatar' />
18
+    </div>
19
+    <div
20
+      className={classnames(`${props.customClass}__messagelist__item__createhour`, 'timeline__messagelist__item__createhour')}>
21
+      {props.createdAt.day} à {props.createdAt.hour}
22
+    </div>
23
+    <div
24
+      className={classnames(`${props.customClass}__messagelist__item__content`, 'timeline__messagelist__item__content')}>
25
+      {props.text}
26
+    </div>
27
+  </li>
28
+)
29
+
30
+const Version = props => (
31
+  <li className={classnames(`${props.customClass}__messagelist__version`, 'timeline__messagelist__version')}>
32
+    <div className={classnames(`${props.customClass}__messagelist__version__btn`, 'timeline__messagelist__version__btn btn')}>
33
+      <i className='fa fa-code-fork' />
34
+      version {props.number}
35
+    </div>
36
+    <div className={classnames(`${props.customClass}__messagelist__version__date`, 'timeline__messagelist__version__date')}>
37
+      Créer le {props.createdAt.day}
38
+    </div>
39
+  </li>
40
+)
41
+
8
 const Timeline = props => {
42
 const Timeline = props => {
9
   return (
43
   return (
10
     <div className='timeline'>
44
     <div className='timeline'>
13
       </div>
47
       </div>
14
 
48
 
15
       <ul className={classnames(`${props.customClass}__messagelist`, 'timeline__messagelist')}>
49
       <ul className={classnames(`${props.customClass}__messagelist`, 'timeline__messagelist')}>
50
+        { props.timelineData.map(content => {
51
+          switch (content.type) {
52
+            case 'message':
53
+              return <Message
54
+                customClass={props.customClass}
55
+                avatar={content.author.avatar}
56
+                createdAt={content.createdAt}
57
+                text={content.text}
58
+                fromMe={props.loggedUser.id === content.author.id}
59
+                key={content.id}
60
+              />
16
 
61
 
17
-        <li className={classnames(`${props.customClass}__messagelist__item`, 'timeline__messagelist__item sended')}>
18
-          <div className={classnames(`${props.customClass}__messagelist__item__avatar`, 'timeline__messagelist__item__avatar')}>
19
-            <img src={imgProfil} alt='avatar' />
20
-          </div>
21
-          <div
22
-            className={classnames(`${props.customClass}__messagelist__item__createhour`, 'timeline__messagelist__item__createhour')}>
23
-            27/11/17 à 11h45
24
-          </div>
25
-          <div
26
-            className={classnames(`${props.customClass}__messagelist__item__content`, 'timeline__messagelist__item__content')}>
27
-            Proident esse laboris in sed officia exercitation ut anim ea.
28
-          </div>
29
-        </li>
30
-
31
-        <li className={classnames(`${props.customClass}__messagelist__item`, 'timeline__messagelist__item received')}>
32
-          <div className={classnames(`${props.customClass}__messagelist__item__avatar`, 'timeline__messagelist__item__avatar')}>
33
-            <img src={imgProfilReverse} alt='avatar' />
34
-          </div>
35
-          <div
36
-            className={classnames(`${props.customClass}__messagelist__item__createhour`, 'timeline__messagelist__item__createhour')}>
37
-            27/11/17 à 11h47
38
-          </div>
39
-          <div
40
-            className={classnames(`${props.customClass}__messagelist__item__content`, 'timeline__messagelist__item__content')}>
41
-            Proident esse laboris in sed officia exercitation ut anim ea.
42
-            Proident esse laboris in sed officia exercitation ut anim ea.
43
-            Proident esse laboris in sed officia exercitation ut anim ea.
44
-            Proident esse laboris in sed officia exercitation ut anim ea.
45
-            Proident esse laboris in sed officia exercitation ut anim ea.
46
-          </div>
47
-        </li>
48
-
49
-        <li className={classnames(`${props.customClass}__messagelist__version`, 'timeline__messagelist__version')}>
50
-          <div className={classnames(`${props.customClass}__messagelist__version__btn`, 'timeline__messagelist__version__btn btn')}>
51
-            <i className='fa fa-code-fork' />
52
-            version 3
53
-          </div>
54
-          <div className={classnames(`${props.customClass}__messagelist__version__date`, 'timeline__messagelist__version__date')}>
55
-            Créer le 22/11/17
56
-          </div>
57
-        </li>
58
-
59
-        <li className={classnames(`${props.customClass}__messagelist__item`, 'timeline__messagelist__item sended')}>
60
-          <div className={classnames(`${props.customClass}__messagelist__item__avatar`, 'timeline__messagelist__item__avatar')}>
61
-            <img src={imgProfil} alt='avatar' />
62
-          </div>
63
-          <div
64
-            className={classnames(`${props.customClass}__messagelist__item__createhour`, 'timeline__messagelist__item__createhour')}>
65
-            27/11/17 à 11h45
66
-          </div>
67
-          <div
68
-            className={classnames(`${props.customClass}__messagelist__item__content`, 'timeline__messagelist__item__content')}>
69
-            Proident esse laboris in sed officia exercitation ut anim ea.
70
-          </div>
71
-        </li>
72
-
73
-        <li className={classnames(`${props.customClass}__messagelist__item`, 'timeline__messagelist__item received')}>
74
-          <div className={classnames(`${props.customClass}__messagelist__item__avatar`, 'timeline__messagelist__item__avatar')}>
75
-            <img src={imgProfilReverse} alt='avatar' />
76
-          </div>
77
-          <div
78
-            className={classnames(`${props.customClass}__messagelist__item__createhour`, 'timeline__messagelist__item__createhour')}>
79
-            27/11/17 à 11h47
80
-          </div>
81
-          <div
82
-            className={classnames(`${props.customClass}__messagelist__item__content`, 'timeline__messagelist__item__content')}>
83
-            Proident esse laboris in sed officia exercitation ut anim ea.
84
-            Proident esse laboris in sed officia exercitation ut anim ea.
85
-            Proident esse laboris in sed officia exercitation ut anim ea.
86
-            Proident esse laboris in sed officia exercitation ut anim ea.
87
-            Proident esse laboris in sed officia exercitation ut anim ea.
88
-          </div>
89
-        </li>
90
-
62
+            case 'version':
63
+              return <Version
64
+                customClass={props.customClas}
65
+                createdAt={content.createdAt}
66
+                number={content.number}
67
+                key={content.id}
68
+              />
69
+          }
70
+        })}
91
       </ul>
71
       </ul>
72
+
92
       <form className={classnames(`${props.customClass}__texteditor`, 'timeline__texteditor')}>
73
       <form className={classnames(`${props.customClass}__texteditor`, 'timeline__texteditor')}>
93
         <div
74
         <div
94
           className={classnames(`${props.customClass}__texteditor__simpletext`, 'timeline__texteditor__simpletext input-group')}>
75
           className={classnames(`${props.customClass}__texteditor__simpletext`, 'timeline__texteditor__simpletext input-group')}>
122
 }
103
 }
123
 
104
 
124
 export default Timeline
105
 export default Timeline
106
+
107
+Timeline.propTypes = {
108
+  customClass: PropTypes.string,
109
+  loggedUser: PropTypes.object,
110
+  timelineData: PropTypes.array
111
+}
112
+
113
+Timeline.defaultProps = {
114
+  customClass: '',
115
+  loggedUser: {
116
+    id: '',
117
+    name: '',
118
+    avatar: ''
119
+  },
120
+  timelineData: []
121
+}

+ 54 - 0
src/component/Timeline/debugData.js View File

1
+export const TimelineDebugData = [{
2
+  id: 0,
3
+  type: 'message',
4
+  author: {
5
+    id: 5,
6
+    name: 'MrLapin',
7
+    avatar: 'https://avatars3.githubusercontent.com/u/11177014?s=460&v=4'
8
+  },
9
+  createdAt: {
10
+    day: '27/11/17',
11
+    hour: '11h45'
12
+  },
13
+  text: 'Proident esse laboris in sed officia exercitation ut anim ea.'
14
+}, {
15
+  id: 1,
16
+  type: 'message',
17
+  author: {
18
+    id: 1,
19
+    name: 'smoi',
20
+    avatar: 'https://www.algoo.fr/static/images/algoo_images/algoo-logo.jpg'
21
+  },
22
+  createdAt: {
23
+    day: '27/11/16',
24
+    hour: '10h30'
25
+  },
26
+  text: 'Proident esse laboris in sed officia exercitation ut anim ea. in sed officia exercitation ut'
27
+}, {
28
+  id: 2,
29
+  type: 'message',
30
+  author: {
31
+    id: 1,
32
+    name: 'smoi',
33
+    avatar: 'https://www.algoo.fr/static/images/algoo_images/algoo-logo.jpg'
34
+  },
35
+  createdAt: {
36
+    day: '27/11/15',
37
+    hour: '10h30'
38
+  },
39
+  text: 'Proident esse laboris in sed officia exercitation ut anim ea. Proident esse laboris in sed officia exercitation ut anim ea. Proident esse laboris in sed officia exercitation ut anim ea.'
40
+}, {
41
+  id: 3,
42
+  type: 'version',
43
+  author: {
44
+    id: 1,
45
+    name: 'smoi',
46
+    avatar: 'https://www.algoo.fr/static/images/algoo_images/algoo-logo.jpg'
47
+  },
48
+  createdAt: {
49
+    day: '27/11/11'
50
+  },
51
+  number: '5'
52
+}]
53
+
54
+export default TimelineDebugData

+ 17 - 0
src/helper.js View File

1
+export const libHandleFetchResult = fetchResult => {
2
+  switch (fetchResult.status) {
3
+    case 200:
4
+    case 304:
5
+      return fetchResult.json()
6
+    case 204:
7
+    case 400:
8
+    case 404:
9
+    case 409:
10
+    case 500:
11
+    case 501:
12
+    case 502:
13
+    case 503:
14
+    case 504:
15
+      return `Error: ${fetchResult.status}` // @TODO : handle errors from api result
16
+  }
17
+}

+ 7 - 1
src/index.dev.js View File

10
 import BtnSwitch from './component/Input/BtnSwitch/BtnSwitch.jsx'
10
 import BtnSwitch from './component/Input/BtnSwitch/BtnSwitch.jsx'
11
 
11
 
12
 import Timeline from './component/Timeline/Timeline.jsx'
12
 import Timeline from './component/Timeline/Timeline.jsx'
13
+import TimelineDebugData from './component/Timeline/debugData.js'
13
 
14
 
14
 ReactDOM.render(
15
 ReactDOM.render(
15
   <PopinFixed customClass={`${'randomClass'}`}>
16
   <PopinFixed customClass={`${'randomClass'}`}>
31
 
32
 
32
       <Timeline
33
       <Timeline
33
         customClass={`${'randomClass'}__contentpage`}
34
         customClass={`${'randomClass'}__contentpage`}
34
-        key={'pageHtml__timeline'}
35
+        loggedUser={{
36
+          id: '1',
37
+          name: 'smoi',
38
+          avatar: 'https://www.algoo.fr/static/images/algoo_images/algoo-logo.jpg'
39
+        }}
40
+        timelineData={TimelineDebugData}
35
       />
41
       />
36
     </PopinFixedContent>
42
     </PopinFixedContent>
37
   </PopinFixed>
43
   </PopinFixed>

+ 4 - 0
src/index.js View File

1
+import { libHandleFetchResult } from './helper.js'
2
+
1
 import libPopinFixed from './component/PopinFixed/PopinFixed.jsx'
3
 import libPopinFixed from './component/PopinFixed/PopinFixed.jsx'
2
 import libPopinFixedHeader from './component/PopinFixed/PopinFixedHeader.jsx'
4
 import libPopinFixedHeader from './component/PopinFixed/PopinFixedHeader.jsx'
3
 import libPopinFixedOption from './component/PopinFixed/PopinFixedOption.jsx'
5
 import libPopinFixedOption from './component/PopinFixed/PopinFixedOption.jsx'
8
 import libTextAreaApp from './component/Input/TextAreaApp/TextAreaApp.jsx'
10
 import libTextAreaApp from './component/Input/TextAreaApp/TextAreaApp.jsx'
9
 import libBtnSwitch from './component/Input/BtnSwitch/BtnSwitch.jsx'
11
 import libBtnSwitch from './component/Input/BtnSwitch/BtnSwitch.jsx'
10
 
12
 
13
+export const handleFetchResult = libHandleFetchResult
14
+
11
 export const PopinFixed = libPopinFixed
15
 export const PopinFixed = libPopinFixed
12
 export const PopinFixedHeader = libPopinFixedHeader
16
 export const PopinFixedHeader = libPopinFixedHeader
13
 export const PopinFixedOption = libPopinFixedOption
17
 export const PopinFixedOption = libPopinFixedOption