Browse Source

added edit title async call

Skylsmoi 6 years ago
parent
commit
ef53f8579c
2 changed files with 25 additions and 1 deletions
  1. 10 0
      src/action.async.js
  2. 15 1
      src/container/Thread.jsx

+ 10 - 0
src/action.async.js View File

40
       label: newContentName
40
       label: newContentName
41
     })
41
     })
42
   })
42
   })
43
+
44
+export const putThreadContent = (apiUrl, idWorkspace, idContent, label) =>
45
+  fetch(`${apiUrl}/workspaces/${idWorkspace}/threads/${idContent}`, {
46
+    ...FETCH_CONFIG,
47
+    method: 'PUT',
48
+    body: JSON.stringify({
49
+      label: label,
50
+      raw_content: '' // threads have no content
51
+    })
52
+  })

+ 15 - 1
src/container/Thread.jsx View File

15
   getThreadContent,
15
   getThreadContent,
16
   getThreadComment,
16
   getThreadComment,
17
   postThreadNewComment,
17
   postThreadNewComment,
18
-  putThreadStatus
18
+  putThreadStatus,
19
+  putThreadContent
19
 } from '../action.async.js'
20
 } from '../action.async.js'
20
 
21
 
21
 class Thread extends React.Component {
22
 class Thread extends React.Component {
91
     GLOBAL_dispatchEvent({type: 'appClosed', data: {}}) // handled by tracim_front::src/container/WorkspaceContent.jsx
92
     GLOBAL_dispatchEvent({type: 'appClosed', data: {}}) // handled by tracim_front::src/container/WorkspaceContent.jsx
92
   }
93
   }
93
 
94
 
95
+  handleSaveEditTitle = async newTitle => {
96
+    const { config, content } = this.state
97
+
98
+    const fetchResultSaveThread = putThreadContent(config.apiUrl, content.workspace_id, content.content_id, newTitle)
99
+
100
+    handleFetchResult(await fetchResultSaveThread)
101
+      .then(resSave => {
102
+        if (resSave.apiResponse.status === 200) this.loadContent()
103
+        else console.warn('Error saving threads. Result:', resSave, 'content:', content, 'config:', config)
104
+      })
105
+  }
106
+
94
   handleChangeNewComment = e => {
107
   handleChangeNewComment = e => {
95
     const newComment = e.target.value
108
     const newComment = e.target.value
96
     this.setState({newComment})
109
     this.setState({newComment})
146
           faIcon={config.faIcon}
159
           faIcon={config.faIcon}
147
           title={content.label}
160
           title={content.label}
148
           onClickCloseBtn={this.handleClickBtnCloseApp}
161
           onClickCloseBtn={this.handleClickBtnCloseApp}
162
+          onValidateChangeTitle={this.handleSaveEditTitle}
149
         />
163
         />
150
 
164
 
151
         <PopinFixedOption customClass={`wsContentThread`} i18n={i18n}>
165
         <PopinFixedOption customClass={`wsContentThread`} i18n={i18n}>