Browse Source

fixed popin fixed, timeline and textareaapp

Skylsmoi 5 years ago
parent
commit
369f045029

+ 23 - 3
src/component/Input/TextAreaApp/TextAreaApp.jsx View File

@@ -1,11 +1,16 @@
1 1
 import React from 'react'
2
-// import classnames from 'classnames'
2
+import PropTypes from 'prop-types'
3 3
 
4 4
 require('./TextAreaApp.styl')
5 5
 
6 6
 export const TextAreaApp = props =>
7 7
   <form className={`${props.customClass} editionmode`}>
8
-    <textarea className={`${props.customClass}__text editionmode__text`} />
8
+    <textarea
9
+      className={`${props.customClass}__text editionmode__text`}
10
+      value={props.text}
11
+      onChange={props.onChangeText}
12
+    />
13
+
9 14
     <div className={`${props.customClass}__button editionmode__button`}>
10 15
       <button
11 16
         type='button'
@@ -14,8 +19,23 @@ export const TextAreaApp = props =>
14 19
       >
15 20
         Annuler
16 21
       </button>
17
-      <button type='submit' className={`${props.customClass}__submit editionmode__button__submit btn btn-outline-primary`}>Valider</button>
22
+
23
+      <button
24
+        type='button'
25
+        className={`${props.customClass}__submit editionmode__button__submit btn btn-outline-primary`}
26
+        onClick={props.onClickValidateBtn}
27
+      >
28
+        Valider
29
+      </button>
18 30
     </div>
19 31
   </form>
20 32
 
21 33
 export default TextAreaApp
34
+
35
+TextAreaApp.propTypes = {
36
+  text: PropTypes.string.isRequired,
37
+  onChangeText: PropTypes.func.isRequired,
38
+  onClickCancelBtn: PropTypes.func.isRequired,
39
+  onClickValidateBtn: PropTypes.func.isRequired,
40
+  customClass: PropTypes.string
41
+}

+ 26 - 18
src/component/PopinFixed/PopinFixedHeader.jsx View File

@@ -6,31 +6,39 @@ class PopinFixedHeader extends React.Component {
6 6
   constructor (props) {
7 7
     super(props)
8 8
     this.state = {
9
-      editTitle: false
9
+      editTitle: false,
10
+      editTitleValue: ''
10 11
     }
11 12
   }
12 13
 
13
-  handleClickChangeTitleBtn = () => this.setState(prevState => ({
14
-    editTitle: !prevState.editTitle
15
-  }))
14
+  componentDidUpdate (prevProps) {
15
+    if (prevProps.title !== this.props.title) this.setState({editTitleValue: this.props.title})
16
+  }
17
+
18
+  onChangeTitle = e => {
19
+    const newTitle = e.target.value
20
+    this.setState({editTitleValue: newTitle})
21
+  }
22
+
23
+  handleClickChangeTitleBtn = () => {
24
+    if (this.state.editTitle) this.props.onValidateChangeTitle(this.state.editTitleValue)
25
+
26
+    this.setState(prevState => ({editTitle: !prevState.editTitle}))
27
+  }
16 28
 
17 29
   render () {
18
-    const { customClass, icon, name, onChangeTitle, onClickCloseBtn } = this.props
30
+    const { customClass, faIcon, title, onClickCloseBtn } = this.props
19 31
 
20 32
     return (
21 33
       <div className={classnames('wsContentGeneric__header', `${customClass}__header`)}>
22 34
         <div className={classnames('wsContentGeneric__header__icon', `${customClass}__header__icon`)}>
23
-          <i className={`fa fa-${icon}`} />
35
+          <i className={`fa fa-${faIcon}`} />
24 36
         </div>
25 37
 
26 38
         <div className={classnames('wsContentGeneric__header__title mr-auto', `${customClass}__header__title`)}>
27
-          {this.state.editTitle === false &&
28
-            <div>
29
-              {name}
30
-            </div>
31
-          }
32
-          {this.state.editTitle === true &&
33
-            <input onChange={onChangeTitle} />
39
+          {this.state.editTitle
40
+            ? <input value={this.state.editTitleValue} onChange={this.onChangeTitle} />
41
+            : <div>{title}</div>
34 42
           }
35 43
         </div>
36 44
 
@@ -38,7 +46,7 @@ class PopinFixedHeader extends React.Component {
38 46
           className={classnames('wsContentGeneric__header__edittitle', `${customClass}__header__changetitle`)}
39 47
           onClick={this.handleClickChangeTitleBtn}
40 48
         >
41
-          <i className='fa fa-pencil' />
49
+          {this.state.editTitle ? <i className='fa fa-check' /> : <i className='fa fa-pencil' />}
42 50
         </div>
43 51
 
44 52
         <div
@@ -55,15 +63,15 @@ class PopinFixedHeader extends React.Component {
55 63
 export default PopinFixedHeader
56 64
 
57 65
 PopinFixedHeader.propTypes = {
58
-  icon: PropTypes.string.isRequired,
66
+  faIcon: PropTypes.string.isRequired,
59 67
   onClickCloseBtn: PropTypes.func.isRequired,
60 68
   customClass: PropTypes.string,
61
-  name: PropTypes.string,
62
-  onChangeTitle: PropTypes.func
69
+  title: PropTypes.string,
70
+  onValidateChangeTitle: PropTypes.func
63 71
 }
64 72
 
65 73
 PopinFixedHeader.defaultProps = {
66 74
   customClass: '',
67
-  name: '',
75
+  title: '',
68 76
   onChangeTitle: () => {}
69 77
 }

+ 45 - 31
src/component/Timeline/Timeline.jsx View File

@@ -4,21 +4,22 @@ import classnames from 'classnames'
4 4
 
5 5
 require('./Timeline.styl')
6 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
-  )}>
7
+const Comment = props => (
8
+  <li
9
+    className={classnames(
10
+      `${props.customClass}__messagelist__item`,
11
+      'timeline__messagelist__item', {
12
+        'sended': props.fromMe,
13
+        'received': !props.fromMe
14
+      }
15
+    )}
16
+  >
16 17
     <div className={classnames(`${props.customClass}__messagelist__item__avatar`, 'timeline__messagelist__item__avatar')}>
17
-      <img src={props.avatar} alt='avatar' />
18
+      {props.avatar ? <img src={props.avatar} /> : ''}
18 19
     </div>
19 20
     <div
20 21
       className={classnames(`${props.customClass}__messagelist__item__createhour`, 'timeline__messagelist__item__createhour')}>
21
-      {props.createdAt.day} à {props.createdAt.hour}
22
+      {props.createdAt}
22 23
     </div>
23 24
     <div
24 25
       className={classnames(`${props.customClass}__messagelist__item__content`, 'timeline__messagelist__item__content')}>
@@ -27,19 +28,24 @@ const Message = props => (
27 28
   </li>
28 29
 )
29 30
 
30
-const Version = props => (
31
-  <li className={classnames(`${props.customClass}__messagelist__version`, 'timeline__messagelist__version')}>
31
+const Revision = props => (
32
+  <li className={classnames(`${props.customClass}__messagelist__version`, 'timeline__messagelist__version')} >
32 33
     <div className={classnames(`${props.customClass}__messagelist__version__btn`, 'timeline__messagelist__version__btn btn')}>
33 34
       <i className='fa fa-code-fork' />
34 35
       version {props.number}
35 36
     </div>
36 37
     <div className={classnames(`${props.customClass}__messagelist__version__date`, 'timeline__messagelist__version__date')}>
37
-      Créer le {props.createdAt.day}
38
+      Créer le {props.createdAt}
38 39
     </div>
39 40
   </li>
40 41
 )
41 42
 
42 43
 const Timeline = props => {
44
+  if (!Array.isArray(props.timelineData)) {
45
+    console.log('Error in Timeline.jsx, props.timelineData is not an array. timelineData: ', props.timelineData)
46
+    return null
47
+  }
48
+
43 49
   return (
44 50
     <div className='timeline'>
45 51
       <div className={classnames(`${props.customClass}__header`, 'timeline__header')}>
@@ -48,23 +54,23 @@ const Timeline = props => {
48 54
 
49 55
       <ul className={classnames(`${props.customClass}__messagelist`, 'timeline__messagelist')}>
50 56
         { props.timelineData.map(content => {
51
-          switch (content.type) {
52
-            case 'message':
53
-              return <Message
57
+          switch (content.timelineType) {
58
+            case 'comment':
59
+              return <Comment
54 60
                 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}
61
+                avatar={content.author.avatar_url}
62
+                createdAt={content.created}
63
+                text={content.raw_content}
64
+                fromMe={props.loggedUser.user_id === content.author.user_id}
65
+                key={`comment_${content.content_id}`}
60 66
               />
61 67
 
62
-            case 'version':
63
-              return <Version
68
+            case 'revision':
69
+              return <Revision
64 70
                 customClass={props.customClass}
65
-                createdAt={content.createdAt}
66
-                number={content.number}
67
-                key={content.id}
71
+                createdAt={content.created}
72
+                number={content.revision_id}
73
+                key={`revision_${content.revision_id}`}
68 74
               />
69 75
           }
70 76
         })}
@@ -73,7 +79,11 @@ const Timeline = props => {
73 79
       <form className={classnames(`${props.customClass}__texteditor`, 'timeline__texteditor d-flex align-items-center justify-content-between flex-wrap')}>
74 80
 
75 81
         <div className={classnames(`${props.customClass}__texteditor__textinput`, 'timeline__texteditor__textinput')}>
76
-          <textarea placeholder='Taper votre message ici' />
82
+          <textarea
83
+            placeholder='Taper votre message ici'
84
+            value={props.newComment}
85
+            onChange={props.onChangeNewComment}
86
+          />
77 87
         </div>
78 88
 
79 89
         <div className={classnames(`${props.customClass}__texteditor__wrapper`, 'timeline__texteditor__wrapper')}>
@@ -86,8 +96,9 @@ const Timeline = props => {
86 96
 
87 97
           <div className={classnames(`${props.customClass}__texteditor__submit`, 'timeline__texteditor__submit mb-2')}>
88 98
             <button
89
-              type='submit'
99
+              type='button'
90 100
               className={classnames(`${props.customClass}__texteditor__submit__btn`, 'timeline__texteditor__submit__btn btn')}
101
+              onClick={props.onClickValidateNewCommentBtn}
91 102
             >
92 103
               Envoyer
93 104
               <div className={classnames(`${props.customClass}__texteditor__submit__btn__icon`, 'timeline__texteditor__submit__btn__icon')}>
@@ -105,9 +116,12 @@ const Timeline = props => {
105 116
 export default Timeline
106 117
 
107 118
 Timeline.propTypes = {
119
+  timelineData: PropTypes.array.isRequired,
120
+  newComment: PropTypes.string.isRequired,
121
+  onChangeNewComment: PropTypes.func.isRequired,
122
+  onClickValidateNewCommentBtn: PropTypes.func.isRequired,
108 123
   customClass: PropTypes.string,
109
-  loggedUser: PropTypes.object,
110
-  timelineData: PropTypes.array
124
+  loggedUser: PropTypes.object
111 125
 }
112 126
 
113 127
 Timeline.defaultProps = {

+ 6 - 2
src/helper.js View File

@@ -1,8 +1,12 @@
1
-export const libHandleFetchResult = fetchResult => {
1
+export const libHandleFetchResult = async fetchResult => {
2 2
   switch (fetchResult.status) {
3 3
     case 200:
4 4
     case 304:
5
-      return fetchResult.json()
5
+      const resultJson = await fetchResult.clone().json()
6
+      return new Promise((resolve, reject) => resolve({
7
+        apiResponse: fetchResult,
8
+        body: resultJson
9
+      }))
6 10
     case 204:
7 11
     case 400:
8 12
     case 404:

+ 2 - 11
src/index.dev.js View File

@@ -19,7 +19,7 @@ import CardPopupCreateContent from './component/CardPopup/CardPopupCreateContent
19 19
 
20 20
 ReactDOM.render(
21 21
   <div>
22
-    <PopinFixed customClass={`${'randomClass'}`} style={{display: 'none'}}>
22
+    <PopinFixed customClass={`${'randomClass'}`}>
23 23
       <PopinFixedHeader
24 24
         customClass={`${'randomClass'}`}
25 25
         icon={'fa fa-file-word-o'}
@@ -34,7 +34,7 @@ ReactDOM.render(
34 34
           <Delimiter />
35 35
           <span>Here will be the app content. Style is handled by the app (obviously)</span>
36 36
           <BtnSwitch />
37
-          <TextAreaApp customClass={'randomClass'} />
37
+          <TextAreaApp customClass={'randomClass'} text={'woot'} />
38 38
         </div>
39 39
 
40 40
         <Timeline
@@ -48,15 +48,6 @@ ReactDOM.render(
48 48
         />
49 49
       </PopinFixedContent>
50 50
     </PopinFixed>
51
-
52
-    <CardPopupCreateContent
53
-      onClose={() => {}}
54
-      icon='fa-file-word-o'
55
-      color='#3f52e3'
56
-      title='Exemple of popup create content'
57
-      inputPlaceHolder='Exemple placeholder'
58
-      btnValidateLabel='Valider et créer'
59
-    />
60 51
   </div>
61 52
   , document.getElementById('content')
62 53
 )