Browse Source

app now handles multi users

Skylsmoi 5 years ago
parent
commit
ff74658588
3 changed files with 40 additions and 23 deletions
  1. 30 12
      src/action.async.js
  2. 9 9
      src/container/Thread.jsx
  3. 1 2
      src/helper.js

+ 30 - 12
src/action.async.js View File

@@ -1,38 +1,53 @@
1 1
 import { FETCH_CONFIG } from './helper.js'
2 2
 
3
-export const getThreadContent = (apiUrl, idWorkspace, idContent) =>
3
+export const getThreadContent = (user, apiUrl, idWorkspace, idContent) =>
4 4
   fetch(`${apiUrl}/workspaces/${idWorkspace}/threads/${idContent}`, {
5
-    ...FETCH_CONFIG,
5
+    headers: {
6
+      ...FETCH_CONFIG.headers,
7
+      'Authorization': 'Basic ' + user.auth
8
+    },
6 9
     method: 'GET'
7 10
   })
8 11
 
9
-export const getThreadComment = (apiUrl, idWorkspace, idContent) =>
12
+export const getThreadComment = (user, apiUrl, idWorkspace, idContent) =>
10 13
   fetch(`${apiUrl}/workspaces/${idWorkspace}/contents/${idContent}/comments`, {
11
-    ...FETCH_CONFIG,
14
+    headers: {
15
+      ...FETCH_CONFIG.headers,
16
+      'Authorization': 'Basic ' + user.auth
17
+    },
12 18
     method: 'GET'
13 19
   })
14 20
 
15
-export const postThreadNewComment = (apiUrl, idWorkspace, idContent, newComment) =>
21
+export const postThreadNewComment = (user, apiUrl, idWorkspace, idContent, newComment) =>
16 22
   fetch(`${apiUrl}/workspaces/${idWorkspace}/contents/${idContent}/comments`, {
17
-    ...FETCH_CONFIG,
23
+    headers: {
24
+      ...FETCH_CONFIG.headers,
25
+      'Authorization': 'Basic ' + user.auth
26
+    },
18 27
     method: 'POST',
19 28
     body: JSON.stringify({
20 29
       raw_content: newComment
21 30
     })
22 31
   })
23 32
 
24
-export const putThreadStatus = (apiUrl, idWorkspace, idContent, newStatus) =>
33
+export const putThreadStatus = (user, apiUrl, idWorkspace, idContent, newStatus) =>
25 34
   fetch(`${apiUrl}/workspaces/${idWorkspace}/threads/${idContent}/status`, {
26
-    ...FETCH_CONFIG,
35
+    headers: {
36
+      ...FETCH_CONFIG.headers,
37
+      'Authorization': 'Basic ' + user.auth
38
+    },
27 39
     method: 'PUT',
28 40
     body: JSON.stringify({
29 41
       status: newStatus
30 42
     })
31 43
   })
32 44
 
33
-export const postThreadContent = (apiUrl, idWorkspace, idFolder, contentType, newContentName) =>
45
+export const postThreadContent = (user, apiUrl, idWorkspace, idFolder, contentType, newContentName) =>
34 46
   fetch(`${apiUrl}/workspaces/${idWorkspace}/contents`, {
35
-    ...FETCH_CONFIG,
47
+    headers: {
48
+      ...FETCH_CONFIG.headers,
49
+      'Authorization': 'Basic ' + user.auth
50
+    },
36 51
     method: 'POST',
37 52
     body: JSON.stringify({
38 53
       parent_id: idFolder,
@@ -41,9 +56,12 @@ export const postThreadContent = (apiUrl, idWorkspace, idFolder, contentType, ne
41 56
     })
42 57
   })
43 58
 
44
-export const putThreadContent = (apiUrl, idWorkspace, idContent, label) =>
59
+export const putThreadContent = (user, apiUrl, idWorkspace, idContent, label) =>
45 60
   fetch(`${apiUrl}/workspaces/${idWorkspace}/threads/${idContent}`, {
46
-    ...FETCH_CONFIG,
61
+    headers: {
62
+      ...FETCH_CONFIG.headers,
63
+      'Authorization': 'Basic ' + user.auth
64
+    },
47 65
     method: 'PUT',
48 66
     body: JSON.stringify({
49 67
       label: label,

+ 9 - 9
src/container/Thread.jsx View File

@@ -67,12 +67,12 @@ class Thread extends React.Component {
67 67
   }
68 68
 
69 69
   loadContent = async () => {
70
-    const { content, config } = this.state
70
+    const { loggedUser, content, config } = this.state
71 71
 
72 72
     if (content.content_id === '-1') return // debug case
73 73
 
74
-    const fetchResultThread = getThreadContent(config.apiUrl, content.workspace_id, content.content_id)
75
-    const fetchResultThreadComment = getThreadComment(config.apiUrl, content.workspace_id, content.content_id)
74
+    const fetchResultThread = getThreadContent(loggedUser, config.apiUrl, content.workspace_id, content.content_id)
75
+    const fetchResultThreadComment = getThreadComment(loggedUser, config.apiUrl, content.workspace_id, content.content_id)
76 76
 
77 77
     Promise.all([
78 78
       handleFetchResult(await fetchResultThread),
@@ -95,9 +95,9 @@ class Thread extends React.Component {
95 95
   }
96 96
 
97 97
   handleSaveEditTitle = async newTitle => {
98
-    const { config, content } = this.state
98
+    const { loggedUser, config, content } = this.state
99 99
 
100
-    const fetchResultSaveThread = putThreadContent(config.apiUrl, content.workspace_id, content.content_id, newTitle)
100
+    const fetchResultSaveThread = putThreadContent(loggedUser, config.apiUrl, content.workspace_id, content.content_id, newTitle)
101 101
 
102 102
     handleFetchResult(await fetchResultSaveThread)
103 103
       .then(resSave => {
@@ -112,9 +112,9 @@ class Thread extends React.Component {
112 112
   }
113 113
 
114 114
   handleClickValidateNewCommentBtn = async () => {
115
-    const { config, content, newComment } = this.state
115
+    const { loggedUser, config, content, newComment } = this.state
116 116
 
117
-    const fetchResultSaveNewComment = await postThreadNewComment(config.apiUrl, content.workspace_id, content.content_id, newComment)
117
+    const fetchResultSaveNewComment = await postThreadNewComment(loggedUser, config.apiUrl, content.workspace_id, content.content_id, newComment)
118 118
 
119 119
     handleFetchResult(await fetchResultSaveNewComment)
120 120
       .then(resSave => {
@@ -131,9 +131,9 @@ class Thread extends React.Component {
131 131
   handleToggleWysiwyg = () => this.setState(prev => ({timelineWysiwyg: !prev.timelineWysiwyg}))
132 132
 
133 133
   handleChangeStatus = async newStatus => {
134
-    const { config, content } = this.state
134
+    const { loggedUser, config, content } = this.state
135 135
 
136
-    const fetchResultSaveEditStatus = putThreadStatus(config.apiUrl, content.workspace_id, content.content_id, newStatus)
136
+    const fetchResultSaveEditStatus = putThreadStatus(loggedUser, config.apiUrl, content.workspace_id, content.content_id, newStatus)
137 137
 
138 138
     handleFetchResult(await fetchResultSaveEditStatus)
139 139
       .then(resSave => {

+ 1 - 2
src/helper.js View File

@@ -1,8 +1,7 @@
1 1
 export const FETCH_CONFIG = {
2 2
   headers: {
3 3
     'Accept': 'application/json',
4
-    'Content-Type': 'application/json',
5
-    'Authorization': 'Basic ' + btoa(`${'admin@admin.admin'}:${'admin@admin.admin'}`)
4
+    'Content-Type': 'application/json'
6 5
   }
7 6
 }
8 7