Browse Source

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

Skylsmoi 5 years ago
parent
commit
ed6d7a07cc

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

@@ -117,3 +117,13 @@ export const putHtmlDocRestoreDeleted = (user, apiUrl, idWorkspace, idContent) =
117 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 View File

@@ -26,7 +26,8 @@ import {
26 26
   putHtmlDocIsArchived,
27 27
   putHtmlDocIsDeleted,
28 28
   putHtmlDocRestoreArchived,
29
-  putHtmlDocRestoreDeleted
29
+  putHtmlDocRestoreDeleted,
30
+  putHtmlDocRead
30 31
 } from '../action.async.js'
31 32
 
32 33
 class HtmlDocument extends React.Component {
@@ -165,6 +166,9 @@ class HtmlDocument extends React.Component {
165 166
         console.log('Error loading Timeline.', e)
166 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 174
   handleClickBtnCloseApp = () => {

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

@@ -108,3 +108,13 @@ export const putThreadRestoreDeleted = (user, apiUrl, idWorkspace, idContent) =>
108 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 View File

@@ -22,7 +22,8 @@ import {
22 22
   putThreadIsArchived,
23 23
   putThreadIsDeleted,
24 24
   putThreadRestoreArchived,
25
-  putThreadRestoreDeleted
25
+  putThreadRestoreDeleted,
26
+  putThreadRead
26 27
 } from '../action.async.js'
27 28
 
28 29
 class Thread extends React.Component {
@@ -108,20 +109,24 @@ class Thread extends React.Component {
108 109
       handleFetchResult(await fetchResultThread),
109 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 130
       .catch(e => console.log('Error loading Thread data.', e))
126 131
   }
127 132