Browse Source

app now handles multi users

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

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

67
   }
67
   }
68
 
68
 
69
   loadContent = async () => {
69
   loadContent = async () => {
70
-    const { content, config } = this.state
70
+    const { loggedUser, content, config } = this.state
71
 
71
 
72
     if (content.content_id === '-1') return // debug case
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
     Promise.all([
77
     Promise.all([
78
       handleFetchResult(await fetchResultThread),
78
       handleFetchResult(await fetchResultThread),
95
   }
95
   }
96
 
96
 
97
   handleSaveEditTitle = async newTitle => {
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
     handleFetchResult(await fetchResultSaveThread)
102
     handleFetchResult(await fetchResultSaveThread)
103
       .then(resSave => {
103
       .then(resSave => {
112
   }
112
   }
113
 
113
 
114
   handleClickValidateNewCommentBtn = async () => {
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
     handleFetchResult(await fetchResultSaveNewComment)
119
     handleFetchResult(await fetchResultSaveNewComment)
120
       .then(resSave => {
120
       .then(resSave => {
131
   handleToggleWysiwyg = () => this.setState(prev => ({timelineWysiwyg: !prev.timelineWysiwyg}))
131
   handleToggleWysiwyg = () => this.setState(prev => ({timelineWysiwyg: !prev.timelineWysiwyg}))
132
 
132
 
133
   handleChangeStatus = async newStatus => {
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
     handleFetchResult(await fetchResultSaveEditStatus)
138
     handleFetchResult(await fetchResultSaveEditStatus)
139
       .then(resSave => {
139
       .then(resSave => {

+ 1 - 2
src/helper.js View File

1
 export const FETCH_CONFIG = {
1
 export const FETCH_CONFIG = {
2
   headers: {
2
   headers: {
3
     'Accept': 'application/json',
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