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
 import i18n from '../i18n.js'
12
 import i18n from '../i18n.js'
13
 
13
 
14
 const debug = {
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
   loggedUser: {
29
   loggedUser: {
16
     id: 5,
30
     id: 5,
17
     username: 'Stoi',
31
     username: 'Stoi',
20
     email: 'osef@algoo.fr',
34
     email: 'osef@algoo.fr',
21
     avatar: 'https://avatars3.githubusercontent.com/u/11177014?s=460&v=4'
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
   content: {
37
   content: {
28
     id: 2,
38
     id: 2,
29
     type: 'thread',
39
     type: 'thread',
30
     status: 'validated',
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
 class Thread extends React.Component {
51
 class Thread extends React.Component {
45
     this.state = {
54
     this.state = {
46
       appName: 'Thread',
55
       appName: 'Thread',
47
       isVisible: true,
56
       isVisible: true,
57
+      config: props.data ? props.data.config : debug.config,
48
       loggedUser: props.data ? props.data.loggedUser : debug.loggedUser,
58
       loggedUser: props.data ? props.data.loggedUser : debug.loggedUser,
49
-      workspace: props.data ? props.data.workspace : debug.workspace,
50
       content: props.data ? props.data.content : debug.content,
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
     document.addEventListener('appCustomEvent', this.customEventReducer)
63
     document.addEventListener('appCustomEvent', this.customEventReducer)
67
   }
75
   }
68
 
76
 
69
   async componentDidMount () {
77
   async componentDidMount () {
70
-    const { workspace, content, appConfig } = this.state
78
+    const { content, config } = this.state
71
     if (content.id === '-1') return // debug case
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
       ...FETCH_CONFIG,
82
       ...FETCH_CONFIG,
75
       method: 'GET'
83
       method: 'GET'
76
     })
84
     })
93
   }
101
   }
94
 
102
 
95
   render () {
103
   render () {
96
-    const { isVisible, loggedUser, content, listMessage, appConfig } = this.state
104
+    const { isVisible, loggedUser, content, listMessage, config } = this.state
97
 
105
 
98
     if (!isVisible) return null
106
     if (!isVisible) return null
99
 
107
 
100
     return (
108
     return (
101
-      <PopinFixed customClass={`${appConfig.customClass}`}>
109
+      <PopinFixed customClass={`${config.customClass}`}>
102
         <PopinFixedHeader
110
         <PopinFixedHeader
103
-          customClass={`${appConfig.customClass}`}
104
-          icon={appConfig.icon}
111
+          customClass={`${config.customClass}`}
112
+          icon={config.icon}
105
           name={content.title}
113
           name={content.title}
106
           onClickCloseBtn={this.handleClickBtnCloseApp}
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
           <ThreadComponent
120
           <ThreadComponent
113
             title={content.title}
121
             title={content.title}
114
             listMessage={listMessage}
122
             listMessage={listMessage}

+ 2 - 2
src/index.js View File

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