Sfoglia il codice sorgente

[https://github.com/tracim/tracim/issues/641] apps htmldoc and thread now mark content as read upon loading data

Skylsmoi 5 anni fa
parent
commit
ed6d7a07cc

+ 10 - 0
frontend_app_html-document/src/action.async.js Vedi File

117
     method: 'PUT'
117
     method: 'PUT'
118
   })
118
   })
119
 }
119
 }
120
+
121
+export const putHtmlDocRead = (user, apiUrl, idWorkspace, idContent) => {
122
+  return fetch(`${apiUrl}/users/${user.user_id}/workspaces/${idWorkspace}/contents/${idContent}/read`, {
123
+    headers: {
124
+      'Authorization': 'Basic ' + user.auth,
125
+      ...FETCH_CONFIG.headers
126
+    },
127
+    method: 'PUT'
128
+  })
129
+}

+ 5 - 1
frontend_app_html-document/src/container/HtmlDocument.jsx Vedi File

26
   putHtmlDocIsArchived,
26
   putHtmlDocIsArchived,
27
   putHtmlDocIsDeleted,
27
   putHtmlDocIsDeleted,
28
   putHtmlDocRestoreArchived,
28
   putHtmlDocRestoreArchived,
29
-  putHtmlDocRestoreDeleted
29
+  putHtmlDocRestoreDeleted,
30
+  putHtmlDocRead
30
 } from '../action.async.js'
31
 } from '../action.async.js'
31
 
32
 
32
 class HtmlDocument extends React.Component {
33
 class HtmlDocument extends React.Component {
165
         console.log('Error loading Timeline.', e)
166
         console.log('Error loading Timeline.', e)
166
         this.setState({timeline: []})
167
         this.setState({timeline: []})
167
       })
168
       })
169
+
170
+    await Promise.all([fetchResultHtmlDocument, fetchResultComment, fetchResultRevision])
171
+    putHtmlDocRead(loggedUser, config.apiUrl, content.workspace_id, content.content_id) // mark as read after all requests are finished
168
   }
172
   }
169
 
173
 
170
   handleClickBtnCloseApp = () => {
174
   handleClickBtnCloseApp = () => {

+ 10 - 0
frontend_app_thread/src/action.async.js Vedi File

108
     method: 'PUT'
108
     method: 'PUT'
109
   })
109
   })
110
 }
110
 }
111
+
112
+export const putThreadRead = (user, apiUrl, idWorkspace, idContent) => {
113
+  return fetch(`${apiUrl}/users/${user.user_id}/workspaces/${idWorkspace}/contents/${idContent}/read`, {
114
+    headers: {
115
+      'Authorization': 'Basic ' + user.auth,
116
+      ...FETCH_CONFIG.headers
117
+    },
118
+    method: 'PUT'
119
+  })
120
+}

+ 20 - 15
frontend_app_thread/src/container/Thread.jsx Vedi File

22
   putThreadIsArchived,
22
   putThreadIsArchived,
23
   putThreadIsDeleted,
23
   putThreadIsDeleted,
24
   putThreadRestoreArchived,
24
   putThreadRestoreArchived,
25
-  putThreadRestoreDeleted
25
+  putThreadRestoreDeleted,
26
+  putThreadRead
26
 } from '../action.async.js'
27
 } from '../action.async.js'
27
 
28
 
28
 class Thread extends React.Component {
29
 class Thread extends React.Component {
108
       handleFetchResult(await fetchResultThread),
109
       handleFetchResult(await fetchResultThread),
109
       handleFetchResult(await fetchResultThreadComment)
110
       handleFetchResult(await fetchResultThreadComment)
110
     ])
111
     ])
111
-      .then(([resThread, resComment]) => this.setState({
112
-        content: resThread.body,
113
-        listMessage: resComment.body.map(c => ({
114
-          ...c,
115
-          timelineType: 'comment',
116
-          created: (new Date(c.created)).toLocaleString(),
117
-          author: {
118
-            ...c.author,
119
-            avatar_url: c.author.avatar_url
120
-              ? c.author.avatar_url
121
-              : generateAvatarFromPublicName(c.author.public_name)
122
-          }
123
-        }))
124
-      }))
112
+      .then(([resThread, resComment]) => {
113
+        this.setState({
114
+          content: resThread.body,
115
+          listMessage: resComment.body.map(c => ({
116
+            ...c,
117
+            timelineType: 'comment',
118
+            created: (new Date(c.created)).toLocaleString(),
119
+            author: {
120
+              ...c.author,
121
+              avatar_url: c.author.avatar_url
122
+                ? c.author.avatar_url
123
+                : generateAvatarFromPublicName(c.author.public_name)
124
+            }
125
+          }))
126
+        })
127
+
128
+        putThreadRead(loggedUser, config.apiUrl, content.workspace_id, content.content_id)
129
+      })
125
       .catch(e => console.log('Error loading Thread data.', e))
130
       .catch(e => console.log('Error loading Thread data.', e))
126
   }
131
   }
127
 
132