Browse Source

app api is now more generic

Skylsmoi 7 years ago
parent
commit
0833cbaa09
2 changed files with 33 additions and 25 deletions
  1. 31 23
      src/container/Thread.jsx
  2. 2 2
      src/index.js

+ 31 - 23
src/container/Thread.jsx View File

@@ -12,6 +12,20 @@ import { FETCH_CONFIG } from '../helper.js'
12 12
 import i18n from '../i18n.js'
13 13
 
14 14
 const debug = {
15
+  config: {
16
+    name: 'Thread',
17
+    label: {
18
+      fr: 'Discussion',
19
+      en: 'Thread'
20
+    },
21
+    componentLeft: 'Thread',
22
+    componentRight: 'undefined',
23
+    customClass: 'wsContentThread',
24
+    icon: 'fa fa-comments-o',
25
+    color: '#65c7f2',
26
+    domContainer: 'appContainer',
27
+    apiUrl: 'http://localhost:3001'
28
+  },
15 29
   loggedUser: {
16 30
     id: 5,
17 31
     username: 'Stoi',
@@ -20,23 +34,18 @@ const debug = {
20 34
     email: 'osef@algoo.fr',
21 35
     avatar: 'https://avatars3.githubusercontent.com/u/11177014?s=460&v=4'
22 36
   },
23
-  workspace: {
24
-    id: 1,
25
-    title: 'Test debug workspace'
26
-  },
27 37
   content: {
28 38
     id: 2,
29 39
     type: 'thread',
30 40
     status: 'validated',
31
-    title: 'test debug title'
41
+    title: 'test debug title',
42
+    workspace: {
43
+      id: 1,
44
+      title: 'Test debug workspace',
45
+      ownerId: 5
46
+    }
32 47
   },
33
-  listMessage: listMessageDebugData,
34
-  appConfig: {
35
-    name: 'Thread',
36
-    customClass: 'wsContentThread',
37
-    icon: 'fa fa-comments-o',
38
-    apiUrl: 'http://localhost:3001'
39
-  }
48
+  listMessage: listMessageDebugData
40 49
 }
41 50
 
42 51
 class Thread extends React.Component {
@@ -45,11 +54,10 @@ class Thread extends React.Component {
45 54
     this.state = {
46 55
       appName: 'Thread',
47 56
       isVisible: true,
57
+      config: props.data ? props.data.config : debug.config,
48 58
       loggedUser: props.data ? props.data.loggedUser : debug.loggedUser,
49
-      workspace: props.data ? props.data.workspace : debug.workspace,
50 59
       content: props.data ? props.data.content : debug.content,
51
-      listMessage: props.data ? [] : debug.listMessage,
52
-      appConfig: props.data ? props.data.appConfig : debug.appConfig
60
+      listMessage: props.data ? [] : debug.listMessage
53 61
     }
54 62
 
55 63
     document.addEventListener('appCustomEvent', this.customEventReducer)
@@ -67,10 +75,10 @@ class Thread extends React.Component {
67 75
   }
68 76
 
69 77
   async componentDidMount () {
70
-    const { workspace, content, appConfig } = this.state
78
+    const { content, config } = this.state
71 79
     if (content.id === '-1') return // debug case
72 80
 
73
-    const fetchResultThread = await fetch(`${appConfig.apiUrl}/workspace/${workspace.id}/content/${content.id}`, {
81
+    const fetchResultThread = await fetch(`${config.apiUrl}/workspace/${content.workspace.id}/content/${content.id}`, {
74 82
       ...FETCH_CONFIG,
75 83
       method: 'GET'
76 84
     })
@@ -93,22 +101,22 @@ class Thread extends React.Component {
93 101
   }
94 102
 
95 103
   render () {
96
-    const { isVisible, loggedUser, content, listMessage, appConfig } = this.state
104
+    const { isVisible, loggedUser, content, listMessage, config } = this.state
97 105
 
98 106
     if (!isVisible) return null
99 107
 
100 108
     return (
101
-      <PopinFixed customClass={`${appConfig.customClass}`}>
109
+      <PopinFixed customClass={`${config.customClass}`}>
102 110
         <PopinFixedHeader
103
-          customClass={`${appConfig.customClass}`}
104
-          icon={appConfig.icon}
111
+          customClass={`${config.customClass}`}
112
+          icon={config.icon}
105 113
           name={content.title}
106 114
           onClickCloseBtn={this.handleClickBtnCloseApp}
107 115
         />
108 116
 
109
-        <PopinFixedOption customClass={`${appConfig.customClass}`} i18n={i18n} />
117
+        <PopinFixedOption customClass={`${config.customClass}`} i18n={i18n} />
110 118
 
111
-        <PopinFixedContent customClass={`${appConfig.customClass}__contentpage`}>
119
+        <PopinFixedContent customClass={`${config.customClass}__contentpage`}>
112 120
           <ThreadComponent
113 121
             title={content.title}
114 122
             listMessage={listMessage}

+ 2 - 2
src/index.js View File

@@ -7,10 +7,10 @@ require('./css/index.styl')
7 7
 const appInterface = {
8 8
   name: 'Thread',
9 9
   isRendered: false,
10
-  renderApp: (domId, data) => {
10
+  renderApp: data => {
11 11
     return ReactDOM.render(
12 12
       <Thread data={data} />
13
-      , document.getElementById(domId)
13
+      , document.getElementById(data.config.domContainer)
14 14
     )
15 15
   },
16 16
   hideApp: domId => {