|  | @@ -11,7 +11,15 @@ import {
 | 
	
		
			
			| 11 | 11 |    ArchiveDeleteContent,
 | 
	
		
			
			| 12 | 12 |    SelectStatus
 | 
	
		
			
			| 13 | 13 |  } from 'tracim_lib'
 | 
	
		
			
			| 14 |  | -import { FETCH_CONFIG, MODE, debug } from '../helper.js'
 | 
	
		
			
			|  | 14 | +import { MODE, debug } from '../helper.js'
 | 
	
		
			
			|  | 15 | +import {
 | 
	
		
			
			|  | 16 | +  getHtmlDocContent,
 | 
	
		
			
			|  | 17 | +  getHtmlDocComment,
 | 
	
		
			
			|  | 18 | +  getHtmlDocRevision,
 | 
	
		
			
			|  | 19 | +  postHtmlDocNewComment,
 | 
	
		
			
			|  | 20 | +  putHtmlDocContent,
 | 
	
		
			
			|  | 21 | +  putHtmlDocStatus
 | 
	
		
			
			|  | 22 | +} from '../action.async.js'
 | 
	
		
			
			| 15 | 23 |  import i18n from '../i18n.js'
 | 
	
		
			
			| 16 | 24 |  
 | 
	
		
			
			| 17 | 25 |  class HtmlDocument extends React.Component {
 | 
	
	
		
			
			|  | @@ -68,26 +76,17 @@ class HtmlDocument extends React.Component {
 | 
	
		
			
			| 68 | 76 |    loadContent = async () => {
 | 
	
		
			
			| 69 | 77 |      const { content, config } = this.state
 | 
	
		
			
			| 70 | 78 |  
 | 
	
		
			
			| 71 |  | -    const fetchResultHtmlDocument = await fetch(`${config.apiUrl}/workspaces/${content.workspace_id}/html-documents/${content.content_id}`, { // ${content.workspace_id} ${content.content_id}
 | 
	
		
			
			| 72 |  | -      ...FETCH_CONFIG,
 | 
	
		
			
			| 73 |  | -      method: 'GET'
 | 
	
		
			
			| 74 |  | -    })
 | 
	
		
			
			| 75 |  | -    const fetchResultComment = await fetch(`${config.apiUrl}/workspaces/${content.workspace_id}/contents/${content.content_id}/comments`, { // ${content.workspace_id} ${content.content_id}
 | 
	
		
			
			| 76 |  | -      ...FETCH_CONFIG,
 | 
	
		
			
			| 77 |  | -      method: 'GET'
 | 
	
		
			
			| 78 |  | -    })
 | 
	
		
			
			| 79 |  | -    const fetchResultRevision = await fetch(`${config.apiUrl}/workspaces/${content.workspace_id}/html-documents/${content.content_id}/revisions`, { // ${content.workspace_id} ${content.content_id}
 | 
	
		
			
			| 80 |  | -      ...FETCH_CONFIG,
 | 
	
		
			
			| 81 |  | -      method: 'GET'
 | 
	
		
			
			| 82 |  | -    })
 | 
	
		
			
			| 83 |  | -
 | 
	
		
			
			| 84 |  | -    handleFetchResult(fetchResultHtmlDocument)
 | 
	
		
			
			|  | 79 | +    const fetchResultHtmlDocument = getHtmlDocContent(config.apiUrl, content.workspace_id, content.content_id)
 | 
	
		
			
			|  | 80 | +    const fetchResultComment = getHtmlDocComment(config.apiUrl, content.workspace_id, content.content_id)
 | 
	
		
			
			|  | 81 | +    const fetchResultRevision = getHtmlDocRevision(config.apiUrl, content.workspace_id, content.content_id)
 | 
	
		
			
			|  | 82 | +
 | 
	
		
			
			|  | 83 | +    handleFetchResult(await fetchResultHtmlDocument)
 | 
	
		
			
			| 85 | 84 |        .then(resHtmlDocument => this.setState({content: resHtmlDocument.body}))
 | 
	
		
			
			| 86 | 85 |        .catch(e => console.log('Error loading content.', e))
 | 
	
		
			
			| 87 | 86 |  
 | 
	
		
			
			| 88 | 87 |      Promise.all([
 | 
	
		
			
			| 89 |  | -      handleFetchResult(fetchResultComment),
 | 
	
		
			
			| 90 |  | -      handleFetchResult(fetchResultRevision)
 | 
	
		
			
			|  | 88 | +      handleFetchResult(await fetchResultComment),
 | 
	
		
			
			|  | 89 | +      handleFetchResult(await fetchResultRevision)
 | 
	
		
			
			| 91 | 90 |      ])
 | 
	
		
			
			| 92 | 91 |        .then(([resComment, resRevision]) => {
 | 
	
		
			
			| 93 | 92 |          const resCommentWithProperDate = resComment.body.map(c => ({...c, created: (new Date(c.created)).toLocaleString()}))
 | 
	
	
		
			
			|  | @@ -121,25 +120,20 @@ class HtmlDocument extends React.Component {
 | 
	
		
			
			| 121 | 120 |        })
 | 
	
		
			
			| 122 | 121 |    }
 | 
	
		
			
			| 123 | 122 |  
 | 
	
		
			
			| 124 |  | -  saveEditHtmlDocument = (label, rawContent) =>
 | 
	
		
			
			| 125 |  | -    fetch(`${this.state.config.apiUrl}/workspaces/${this.state.content.workspace_id}/html-documents/${this.state.content.content_id}`, {
 | 
	
		
			
			| 126 |  | -      ...FETCH_CONFIG,
 | 
	
		
			
			| 127 |  | -      method: 'PUT',
 | 
	
		
			
			| 128 |  | -      body: JSON.stringify({label: label, raw_content: rawContent})
 | 
	
		
			
			| 129 |  | -    })
 | 
	
		
			
			| 130 |  | -
 | 
	
		
			
			| 131 | 123 |    handleClickBtnCloseApp = () => {
 | 
	
		
			
			| 132 | 124 |      this.setState({ isVisible: false })
 | 
	
		
			
			| 133 | 125 |      GLOBAL_dispatchEvent({type: 'appClosed', data: {}})
 | 
	
		
			
			| 134 | 126 |    }
 | 
	
		
			
			| 135 | 127 |  
 | 
	
		
			
			| 136 | 128 |    handleSaveEditTitle = async newTitle => {
 | 
	
		
			
			| 137 |  | -    const fetchResultSaveHtmlDoc = await this.saveEditHtmlDocument(newTitle, this.state.content.raw_content)
 | 
	
		
			
			|  | 129 | +    const { config, content } = this.state
 | 
	
		
			
			|  | 130 | +
 | 
	
		
			
			|  | 131 | +    const fetchResultSaveHtmlDoc = putHtmlDocContent(config.apiUrl, content.workspace_id, content.content_id, newTitle, content.raw_content)
 | 
	
		
			
			| 138 | 132 |  
 | 
	
		
			
			| 139 |  | -    handleFetchResult(fetchResultSaveHtmlDoc)
 | 
	
		
			
			|  | 133 | +    handleFetchResult(await fetchResultSaveHtmlDoc)
 | 
	
		
			
			| 140 | 134 |        .then(resSave => {
 | 
	
		
			
			| 141 | 135 |          if (resSave.apiResponse.status === 200) this.loadContent()
 | 
	
		
			
			| 142 |  | -        else console.warn('Error saving html-document. Result:', resSave, 'content:', this.state.content, 'config:', this.state.config)
 | 
	
		
			
			|  | 136 | +        else console.warn('Error saving html-document. Result:', resSave, 'content:', content, 'config:', config)
 | 
	
		
			
			| 143 | 137 |        })
 | 
	
		
			
			| 144 | 138 |    }
 | 
	
		
			
			| 145 | 139 |  
 | 
	
	
		
			
			|  | @@ -153,9 +147,9 @@ class HtmlDocument extends React.Component {
 | 
	
		
			
			| 153 | 147 |    handleSaveHtmlDocument = async () => {
 | 
	
		
			
			| 154 | 148 |      const { content, config } = this.state
 | 
	
		
			
			| 155 | 149 |  
 | 
	
		
			
			| 156 |  | -    const fetchResultSaveHtmlDoc = await this.saveEditHtmlDocument(content.label, content.raw_content)
 | 
	
		
			
			|  | 150 | +    const fetchResultSaveHtmlDoc = putHtmlDocContent(config.apiUrl, content.workspace_id, content.content_id, content.label, content.raw_content)
 | 
	
		
			
			| 157 | 151 |  
 | 
	
		
			
			| 158 |  | -    handleFetchResult(fetchResultSaveHtmlDoc)
 | 
	
		
			
			|  | 152 | +    handleFetchResult(await fetchResultSaveHtmlDoc)
 | 
	
		
			
			| 159 | 153 |        .then(resSave => {
 | 
	
		
			
			| 160 | 154 |          if (resSave.apiResponse.status === 200) {
 | 
	
		
			
			| 161 | 155 |            this.handleCloseNewVersion()
 | 
	
	
		
			
			|  | @@ -179,15 +173,9 @@ class HtmlDocument extends React.Component {
 | 
	
		
			
			| 179 | 173 |    handleClickValidateNewCommentBtn = async () => {
 | 
	
		
			
			| 180 | 174 |      const { config, content, newComment } = this.state
 | 
	
		
			
			| 181 | 175 |  
 | 
	
		
			
			| 182 |  | -    const fetchResultSaveNewComment = await fetch(`${config.apiUrl}/workspaces/${content.workspace_id}/contents/${content.content_id}/comments`, {
 | 
	
		
			
			| 183 |  | -      ...FETCH_CONFIG,
 | 
	
		
			
			| 184 |  | -      method: 'POST',
 | 
	
		
			
			| 185 |  | -      body: JSON.stringify({
 | 
	
		
			
			| 186 |  | -        raw_content: newComment
 | 
	
		
			
			| 187 |  | -      })
 | 
	
		
			
			| 188 |  | -    })
 | 
	
		
			
			|  | 176 | +    const fetchResultSaveNewComment = await postHtmlDocNewComment(config.apiUrl, content.workspace_id, content.content_id, newComment)
 | 
	
		
			
			| 189 | 177 |  
 | 
	
		
			
			| 190 |  | -    handleFetchResult(fetchResultSaveNewComment)
 | 
	
		
			
			|  | 178 | +    handleFetchResult(await fetchResultSaveNewComment)
 | 
	
		
			
			| 191 | 179 |        .then(resSave => {
 | 
	
		
			
			| 192 | 180 |          if (resSave.apiResponse.status === 200) {
 | 
	
		
			
			| 193 | 181 |            this.setState({newComment: ''})
 | 
	
	
		
			
			|  | @@ -204,13 +192,9 @@ class HtmlDocument extends React.Component {
 | 
	
		
			
			| 204 | 192 |    handleChangeStatus = async newStatus => {
 | 
	
		
			
			| 205 | 193 |      const { config, content } = this.state
 | 
	
		
			
			| 206 | 194 |  
 | 
	
		
			
			| 207 |  | -    const fetchResultSaveEditStatus = await fetch(`${config.apiUrl}/workspaces/${content.workspace_id}/html-documents/${content.content_id}/status`, {
 | 
	
		
			
			| 208 |  | -      ...FETCH_CONFIG,
 | 
	
		
			
			| 209 |  | -      method: 'PUT',
 | 
	
		
			
			| 210 |  | -      body: JSON.stringify({status: newStatus})
 | 
	
		
			
			| 211 |  | -    })
 | 
	
		
			
			|  | 195 | +    const fetchResultSaveEditStatus = putHtmlDocStatus(config.apiUrl, content.workspace_id, content.content_id, newStatus)
 | 
	
		
			
			| 212 | 196 |  
 | 
	
		
			
			| 213 |  | -    handleFetchResult(fetchResultSaveEditStatus)
 | 
	
		
			
			|  | 197 | +    handleFetchResult(await fetchResultSaveEditStatus)
 | 
	
		
			
			| 214 | 198 |        .then(resSave => {
 | 
	
		
			
			| 215 | 199 |          if (resSave.status !== 204) { // 204 no content so dont take status from resSave.apiResponse.status
 | 
	
		
			
			| 216 | 200 |            console.warn('Error saving html-document comment. Result:', resSave, 'content:', content, 'config:', config)
 |