Browse Source

refactored app interface to allow popupCreateContent

Skylsmoi 5 years ago
parent
commit
33c1e5c457
6 changed files with 85 additions and 5 deletions
  1. 2 1
      package.json
  2. 1 1
      src/component/PageHtml.jsx
  3. 4 2
      src/container/PageHtml.jsx
  4. 50 0
      src/container/PopupCreatePageHtml.jsx
  5. 2 1
      src/index.dev.js
  6. 26 0
      src/index.js

+ 2 - 1
package.json View File

@@ -50,7 +50,8 @@
50 50
       "fetch",
51 51
       "history",
52 52
       "GLOBAL_renderApp",
53
-      "GLOBAL_unmountApp"
53
+      "GLOBAL_unmountApp",
54
+      "GLOBAL_dispatchEvent"
54 55
     ],
55 56
     "parser": "babel-eslint",
56 57
     "ignore": []

+ 1 - 1
src/component/PageHtml.jsx View File

@@ -13,7 +13,7 @@ const PageHtml = props => {
13 13
       }
14 14
 
15 15
       {props.mode === MODE.EDIT &&
16
-        <TextAreaApp customClass={'wsContentPageHtml'} onClickCancelBtn={props.onClickCloseEditMode}/>
16
+        <TextAreaApp customClass={'wsContentPageHtml'} onClickCancelBtn={props.onClickCloseEditMode} />
17 17
       }
18 18
     </div>
19 19
   )

+ 4 - 2
src/container/PageHtml.jsx View File

@@ -27,6 +27,7 @@ const debug = {
27 27
     domContainer: 'appContainer',
28 28
     mockApiUrl: 'http://localhost:3001'
29 29
   },
30
+  contentAction: 'showContent',
30 31
   loggedUser: {
31 32
     id: 5,
32 33
     username: 'Smoi',
@@ -67,8 +68,8 @@ class pageHtml extends React.Component {
67 68
     document.addEventListener('appCustomEvent', this.customEventReducer)
68 69
   }
69 70
 
70
-  customEventReducer = ({ detail: action }) => { // action: { type: '', data: {} }
71
-    switch (action.type) {
71
+  customEventReducer = ({ detail: { type, data } }) => { // action: { type: '', data: {} }
72
+    switch (type) {
72 73
       case 'PageHtml_showApp':
73 74
         this.setState({isVisible: true})
74 75
         break
@@ -104,6 +105,7 @@ class pageHtml extends React.Component {
104 105
 
105 106
   handleClickBtnCloseApp = () => {
106 107
     this.setState({ isVisible: false })
108
+    GLOBAL_dispatchEvent({type: 'appClosed', data: {}})
107 109
   }
108 110
 
109 111
   handleChangeTitle = e => console.log('new title : ', e.target.value)

+ 50 - 0
src/container/PopupCreatePageHtml.jsx View File

@@ -0,0 +1,50 @@
1
+import React from 'react'
2
+import { CardPopupCreateContent } from 'tracim_lib'
3
+
4
+class PopupCreatePageHtml extends React.Component {
5
+  constructor (props) {
6
+    super(props)
7
+    this.state = {
8
+      newContentName: ''
9
+    }
10
+  }
11
+
12
+  handleChangeNewContentName = e => this.setState({newContentName: e.target.value})
13
+
14
+  handleClose = () => GLOBAL_dispatchEvent({
15
+    type: 'hide_popupCreateContent',
16
+    data: {
17
+      name: 'PageHtml'
18
+    }
19
+  })
20
+
21
+  handleValidate = () => {
22
+    console.log(`fetch(/workspace/:id/content, POST, body:{name: ${this.state.newContentName})`)
23
+    // API return the id of the new content
24
+    this.handleClose()
25
+    GLOBAL_dispatchEvent({
26
+      type: 'openContentUrl',
27
+      data: {
28
+        idWorkspace: this.props.data.folder.workspace_id,
29
+        idContent: '1' // will the id returned by api
30
+      }
31
+    })
32
+  }
33
+
34
+  render () {
35
+    return (
36
+      <CardPopupCreateContent
37
+        onClose={this.handleClose}
38
+        onValidate={this.handleValidate}
39
+        title={this.props.data.config.label.fr} // @TODO get the lang of user
40
+        color={this.props.data.config.color}
41
+        icon={this.props.data.config.icon}
42
+        contentName={this.state.newContentName}
43
+        onChangeContentName={this.handleChangeNewContentName}
44
+        btnValidateLabel='Valider et créer'
45
+      />
46
+    )
47
+  }
48
+}
49
+
50
+export default PopupCreatePageHtml

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

@@ -1,10 +1,11 @@
1 1
 import React from 'react'
2 2
 import ReactDOM from 'react-dom'
3 3
 import PageHtml from './container/PageHtml.jsx'
4
+import PopupCreatePageHtml from './container/PopupCreatePageHtml.jsx'
4 5
 
5 6
 require('./css/index.styl')
6 7
 
7 8
 ReactDOM.render(
8
-  <PageHtml />
9
+  <PopupCreatePageHtml />
9 10
   , document.getElementById('content')
10 11
 )

+ 26 - 0
src/index.js View File

@@ -1,9 +1,29 @@
1 1
 import React from 'react'
2 2
 import ReactDOM from 'react-dom'
3 3
 import PageHtml from './container/PageHtml.jsx'
4
+import PopupCreatePageHtml from './container/PopupCreatePageHtml.jsx'
4 5
 
5 6
 require('./css/index.styl')
6 7
 
8
+/* data : {
9
+  loggedUser: {},
10
+  config: {
11
+    name: 'PageHtml',
12
+    label: {
13
+      fr: 'Document',
14
+      en: 'Document'
15
+    },
16
+    customClass: 'wsContentPageHtml',
17
+    icon: 'fa fa-fw fa-file-text-o',
18
+    color: '#3f52e3',
19
+    domContainer: 'appContainer'
20
+    apiUrl: FETCH_CONFIG.apiUrl,
21
+    mockApiUrl: FETCH_CONFIG.mockApiUrl
22
+  },
23
+  content || folder
24
+}
25
+ */
26
+
7 27
 const appInterface = {
8 28
   name: 'PageHtml',
9 29
   isRendered: false,
@@ -15,6 +35,12 @@ const appInterface = {
15 35
   },
16 36
   hideApp: domId => {
17 37
     return ReactDOM.unmountComponentAtNode(document.getElementById(domId)) // returns bool
38
+  },
39
+  renderPopupCreation: data => {
40
+    return ReactDOM.render(
41
+      <PopupCreatePageHtml data={data} />
42
+      , document.getElementById(data.config.domContainer)
43
+    )
18 44
   }
19 45
 }
20 46