|
@@ -7,67 +7,111 @@ import {
|
7
|
7
|
PopinFixedContent,
|
8
|
8
|
Timeline
|
9
|
9
|
} from 'tracim_lib'
|
|
10
|
+import { FETCH_CONFIG } from '../helper.js'
|
|
11
|
+
|
|
12
|
+const debug = {
|
|
13
|
+ workspace: {
|
|
14
|
+ id: '-1',
|
|
15
|
+ title: 'Test debugg workspace'
|
|
16
|
+ },
|
|
17
|
+ content: {
|
|
18
|
+ id: '-1',
|
|
19
|
+ type: 'pageHtml',
|
|
20
|
+ title: 'Test debugg pageHtml',
|
|
21
|
+ status: 'validated',
|
|
22
|
+ version: '-1',
|
|
23
|
+ text: 'This is the default pageHtml content for debug purpose'
|
|
24
|
+ },
|
|
25
|
+ appConfig: {
|
|
26
|
+ name: 'PageHtml',
|
|
27
|
+ customClass: 'wsFilePageHtml',
|
|
28
|
+ icon: 'fa fa-file-word-o',
|
|
29
|
+ apiUrl: 'http://localhost:3001'
|
|
30
|
+ }
|
|
31
|
+}
|
10
|
32
|
|
11
|
33
|
class pageHtml extends React.Component {
|
12
|
34
|
constructor (props) {
|
13
|
35
|
super(props)
|
14
|
36
|
this.state = {
|
15
|
37
|
appName: 'PageHtml',
|
16
|
|
- data: props.data
|
17
|
|
- ? props.data
|
18
|
|
- : { // for debugg purpose
|
19
|
|
- file: {
|
20
|
|
- version: '3',
|
21
|
|
- text: 'Bonjour ?'
|
22
|
|
- },
|
23
|
|
- appData: {
|
24
|
|
- name: 'PageHtml',
|
25
|
|
- componentLeft: 'PageHtml',
|
26
|
|
- componentRight: 'Timeline',
|
27
|
|
- customClass: 'wsFilePageHtml',
|
28
|
|
- icon: 'fa fa-file-word-o'
|
29
|
|
- }
|
30
|
|
- }
|
|
38
|
+ isVisible: true,
|
|
39
|
+ workspace: props.app ? props.app.workspace : debug.workspace,
|
|
40
|
+ content: props.app ? props.app.content : debug.content,
|
|
41
|
+ appConfig: props.app ? props.app.appConfig : debug.appConfig
|
31
|
42
|
}
|
32
|
43
|
|
33
|
|
- document.addEventListener('appCustomEvent', this.customEventReducer, false)
|
|
44
|
+ document.addEventListener('appCustomEvent', this.customEventReducer)
|
34
|
45
|
}
|
35
|
46
|
|
36
|
|
- customEventReducer = ({detail}) => {
|
37
|
|
- switch (detail.type) {
|
38
|
|
- case 'PageHtml_showMsg': // unused for now, for testing purpose
|
39
|
|
- this.setState({inputText: detail.content})
|
|
47
|
+ async componentDidMount () {
|
|
48
|
+ const { workspace, content, appConfig } = this.state
|
|
49
|
+ if (content.id === '-1') return
|
|
50
|
+
|
|
51
|
+ const fetchResult = await fetch(`${appConfig.apiUrl}/workspace/${workspace.id}/content/${content.id}`, {
|
|
52
|
+ ...FETCH_CONFIG,
|
|
53
|
+ method: 'GET'
|
|
54
|
+ })
|
|
55
|
+
|
|
56
|
+ fetchResult.json = await (async () => {
|
|
57
|
+ switch (fetchResult.status) {
|
|
58
|
+ case 200:
|
|
59
|
+ case 304:
|
|
60
|
+ return fetchResult.json()
|
|
61
|
+ case 204:
|
|
62
|
+ case 400:
|
|
63
|
+ case 404:
|
|
64
|
+ case 409:
|
|
65
|
+ case 500:
|
|
66
|
+ case 501:
|
|
67
|
+ case 502:
|
|
68
|
+ case 503:
|
|
69
|
+ case 504:
|
|
70
|
+ return `Error: ${fetchResult.status}` // @TODO : handle errors from api result
|
|
71
|
+ }
|
|
72
|
+ })()
|
|
73
|
+
|
|
74
|
+ this.setState({content: fetchResult.json})
|
|
75
|
+ }
|
|
76
|
+
|
|
77
|
+ customEventReducer = action => { // action: { type: '', data: {} }
|
|
78
|
+ switch (action.type) {
|
|
79
|
+ case 'PageHtml_dummyTest':
|
|
80
|
+ this.setState({dummy: true})
|
40
|
81
|
break
|
41
|
82
|
}
|
42
|
83
|
}
|
43
|
84
|
|
44
|
85
|
handleClickBtnCloseApp = () => {
|
45
|
|
- GLOBAL_unmountApp(this.state.appName)
|
|
86
|
+ // GLOBAL_unmountApp(this.state.appName)
|
|
87
|
+ this.setState({ isVisible: false })
|
46
|
88
|
}
|
47
|
89
|
|
48
|
90
|
render () {
|
49
|
|
- const { file, appData } = this.state.data
|
|
91
|
+ const { isVisible, content, appConfig } = this.state
|
|
92
|
+
|
|
93
|
+ if (!isVisible) return null
|
50
|
94
|
|
51
|
95
|
return (
|
52
|
|
- <PopinFixed customClass={`${appData.customClass}`}>
|
|
96
|
+ <PopinFixed customClass={`${appConfig.customClass}`}>
|
53
|
97
|
<PopinFixedHeader
|
54
|
|
- customClass={`${appData.customClass}`}
|
55
|
|
- icon={appData.icon}
|
56
|
|
- name={file.title}
|
|
98
|
+ customClass={`${appConfig.customClass}`}
|
|
99
|
+ icon={appConfig.icon}
|
|
100
|
+ name={content.title}
|
57
|
101
|
onClickCloseBtn={this.handleClickBtnCloseApp}
|
58
|
102
|
/>
|
59
|
103
|
|
60
|
|
- <PopinFixedOption customClass={`${appData.customClass}`} />
|
|
104
|
+ <PopinFixedOption customClass={`${appConfig.customClass}`} />
|
61
|
105
|
|
62
|
|
- <PopinFixedContent customClass={`${appData.customClass}__contentpage`}>
|
|
106
|
+ <PopinFixedContent customClass={`${appConfig.customClass}__contentpage`}>
|
63
|
107
|
<PageHtmlComponent
|
64
|
|
- version={file.version}
|
65
|
|
- text={file.text}
|
|
108
|
+ version={content.version}
|
|
109
|
+ text={content.text}
|
66
|
110
|
key={'PageHtml'}
|
67
|
111
|
/>
|
68
|
112
|
|
69
|
113
|
<Timeline
|
70
|
|
- customClass={`${appData.customClass}__contentpage`}
|
|
114
|
+ customClass={`${appConfig.customClass}__contentpage`}
|
71
|
115
|
key={'pageHtml__timeline'}
|
72
|
116
|
/>
|
73
|
117
|
</PopinFixedContent>
|