Kaynağa Gözat

added edit title async call

Skylsmoi 5 yıl önce
ebeveyn
işleme
ef53f8579c
2 değiştirilmiş dosya ile 25 ekleme ve 1 silme
  1. 10 0
      src/action.async.js
  2. 15 1
      src/container/Thread.jsx

+ 10 - 0
src/action.async.js Dosyayı Görüntüle

@@ -40,3 +40,13 @@ export const postThreadContent = (apiUrl, idWorkspace, idFolder, contentType, ne
40 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 Dosyayı Görüntüle

@@ -15,7 +15,8 @@ import {
15 15
   getThreadContent,
16 16
   getThreadComment,
17 17
   postThreadNewComment,
18
-  putThreadStatus
18
+  putThreadStatus,
19
+  putThreadContent
19 20
 } from '../action.async.js'
20 21
 
21 22
 class Thread extends React.Component {
@@ -91,6 +92,18 @@ class Thread extends React.Component {
91 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 107
   handleChangeNewComment = e => {
95 108
     const newComment = e.target.value
96 109
     this.setState({newComment})
@@ -146,6 +159,7 @@ class Thread extends React.Component {
146 159
           faIcon={config.faIcon}
147 160
           title={content.label}
148 161
           onClickCloseBtn={this.handleClickBtnCloseApp}
162
+          onValidateChangeTitle={this.handleSaveEditTitle}
149 163
         />
150 164
 
151 165
         <PopinFixedOption customClass={`wsContentThread`} i18n={i18n}>