Browse Source

began refactor of action-creator.sync naming

Skylsmoi 6 years ago
parent
commit
8e3dd3e063

+ 23 - 17
frontend/src/action-creator.sync.js View File

@@ -1,14 +1,20 @@
1
+export const SET = 'Set'
2
+export const UPDATE = 'Update'
3
+export const ADD = 'Add'
4
+export const REMOVE = 'Remove'
5
+
1 6
 export const TIMEZONE = 'Timezone'
2
-export const setTimezone = timezone => ({ type: `Set/${TIMEZONE}`, timezone })
7
+export const setTimezone = timezone => ({ type: `${SET}/${TIMEZONE}`, timezone })
3 8
 
4 9
 export const FLASH_MESSAGE = 'FlashMessage'
5 10
 export const newFlashMessage = (msgText = '', msgType = 'info', msgDelay = 5000) => dispatch => {
6 11
   msgDelay !== 0 && window.setTimeout(() => dispatch(removeFlashMessage(msgText)), msgDelay)
7 12
   return dispatch(addFlashMessage({message: msgText, type: msgType}))
8 13
 }
9
-export const addFlashMessage = msg => ({ type: `Add/${FLASH_MESSAGE}`, msg })
10
-export const removeFlashMessage = msg => ({ type: `Remove/${FLASH_MESSAGE}`, msg })
14
+export const addFlashMessage = msg => ({ type: `${ADD}/${FLASH_MESSAGE}`, msg })
15
+export const removeFlashMessage = msg => ({ type: `${REMOVE}/${FLASH_MESSAGE}`, msg })
11 16
 
17
+export const USER = 'User'
12 18
 export const USER_LOGIN = 'User/Login'
13 19
 export const USER_LOGOUT = 'User/Logout'
14 20
 export const USER_DATA = 'User/Data'
@@ -16,30 +22,30 @@ export const USER_ROLE = 'User/Role'
16 22
 export const USER_CONNECTED = 'User/Connected'
17 23
 export const USER_DISCONNECTED = 'User/Disconnected'
18 24
 export const USER_LANG = 'User/Lang'
19
-export const setUserConnected = user => ({ type: `Set/${USER_CONNECTED}`, user })
20
-export const setUserDisconnected = () => ({ type: `Set/${USER_DISCONNECTED}` })
21
-export const updateUserData = userData => ({ type: `Update/${USER_DATA}`, data: userData })
22
-export const setUserRole = userRole => ({ type: `Set/${USER_ROLE}`, userRole }) // this actually update workspaceList state
23
-export const setUserLang = lang => ({ type: `Set/${USER_LANG}`, lang })
25
+export const setUserConnected = user => ({ type: `${SET}/${USER}/Connected`, user })
26
+export const setUserDisconnected = () => ({ type: `${SET}/${USER}/Disconnected` })
27
+export const updateUserData = userData => ({ type: `${UPDATE}/${USER}/Data`, data: userData })
28
+export const setUserRole = userRole => ({ type: `${SET}/${USER}/Role`, userRole }) // this actually update workspaceList state
29
+export const setUserLang = lang => ({ type: `${SET}/${USER}/Lang`, lang })
24 30
 export const updateUserWorkspaceSubscriptionNotif = (workspaceId, subscriptionNotif) =>
25
-  ({ type: `Update/${USER_ROLE}/SubscriptionNotif`, workspaceId, subscriptionNotif })
31
+  ({ type: `${UPDATE}/${USER_ROLE}/SubscriptionNotif`, workspaceId, subscriptionNotif })
26 32
 
27 33
 export const WORKSPACE = 'Workspace'
28
-export const setWorkspaceContent = (workspaceContent, filterStr = '') => ({ type: `Set/${WORKSPACE}/Content`, workspaceContent, filterStr })
29
-export const updateWorkspaceFilter = filterList => ({ type: `Update/${WORKSPACE}/Filter`, filterList })
34
+export const setWorkspaceContent = (workspaceContent, filterStr = '') => ({ type: `${SET}/${WORKSPACE}/Content`, workspaceContent, filterStr })
35
+export const updateWorkspaceFilter = filterList => ({ type: `${UPDATE}/${WORKSPACE}/Filter`, filterList })
30 36
 
31 37
 export const FOLDER = 'Folder'
32
-export const setFolderData = (folderId, content) => ({ type: `Set/${WORKSPACE}/${FOLDER}/Content`, folderId, content })
38
+export const setFolderData = (folderId, content) => ({ type: `${SET}/${WORKSPACE}/${FOLDER}/Content`, folderId, content })
33 39
 
34 40
 export const WORKSPACE_LIST = 'WorkspaceList'
35
-export const updateWorkspaceListData = workspaceList => ({ type: `Update/${WORKSPACE_LIST}`, workspaceList })
36
-export const setWorkspaceListIsOpenInSidebar = (workspaceId, isOpenInSidebar) => ({ type: `Set/${WORKSPACE_LIST}/isOpenInSidebar`, workspaceId, isOpenInSidebar })
41
+export const updateWorkspaceListData = workspaceList => ({ type: `${UPDATE}/${WORKSPACE_LIST}`, workspaceList })
42
+export const setWorkspaceListIsOpenInSidebar = (workspaceId, isOpenInSidebar) => ({ type: `${SET}/${WORKSPACE_LIST}/isOpenInSidebar`, workspaceId, isOpenInSidebar })
37 43
 
38 44
 export const APP_LIST = 'App/List'
39
-export const setAppList = appList => ({ type: `Set/${APP_LIST}`, appList })
45
+export const setAppList = appList => ({ type: `${SET}/${APP_LIST}`, appList })
40 46
 
41 47
 export const CONTENT_TYPE_LIST = 'ContentType/List'
42
-export const setContentTypeList = contentTypeList => ({ type: `Set/${CONTENT_TYPE_LIST}`, contentTypeList })
48
+export const setContentTypeList = contentTypeList => ({ type: `${SET}/${CONTENT_TYPE_LIST}`, contentTypeList })
43 49
 
44 50
 export const LANG = 'Lang'
45
-export const updateLangList = langList => ({ type: `Update/${LANG}`, langList })
51
+export const updateLangList = langList => ({ type: `${UPDATE}/${LANG}`, langList })

+ 2 - 2
frontend/src/reducer/app.js View File

@@ -1,8 +1,8 @@
1
-import { APP_LIST } from '../action-creator.sync.js'
1
+import { SET, APP_LIST } from '../action-creator.sync.js'
2 2
 
3 3
 export default function app (state = [], action) {
4 4
   switch (action.type) {
5
-    case `Set/${APP_LIST}`:
5
+    case `${SET}/${APP_LIST}`:
6 6
       return action.appList.map(a => ({
7 7
         label: a.label,
8 8
         slug: a.slug,

+ 2 - 2
frontend/src/reducer/contentType.js View File

@@ -1,8 +1,8 @@
1
-import { CONTENT_TYPE_LIST } from '../action-creator.sync.js'
1
+import { SET, CONTENT_TYPE_LIST } from '../action-creator.sync.js'
2 2
 
3 3
 export function contentType (state = [], action) {
4 4
   switch (action.type) {
5
-    case `Set/${CONTENT_TYPE_LIST}`:
5
+    case `${SET}/${CONTENT_TYPE_LIST}`:
6 6
       return action.contentTypeList.map(ct => ({
7 7
         label: ct.label,
8 8
         slug: ct.slug,

+ 3 - 5
frontend/src/reducer/flashMessage.js View File

@@ -1,16 +1,14 @@
1
-import {
2
-  FLASH_MESSAGE
3
-} from '../action-creator.sync.js'
1
+import { ADD, REMOVE, FLASH_MESSAGE } from '../action-creator.sync.js'
4 2
 
5 3
 export default function flashMessage (state = [], action) {
6 4
   switch (action.type) {
7
-    case `Add/${FLASH_MESSAGE}`:
5
+    case `${ADD}/${FLASH_MESSAGE}`:
8 6
       return [...state, {
9 7
         message: action.msg.message,
10 8
         type: action.msg.type || 'info' // may be info, success, danger
11 9
       }]
12 10
 
13
-    case `Remove/${FLASH_MESSAGE}`:
11
+    case `${REMOVE}/${FLASH_MESSAGE}`:
14 12
       return state.filter(fm => fm.message === action.message)
15 13
 
16 14
     default:

+ 2 - 2
frontend/src/reducer/lang.js View File

@@ -1,4 +1,4 @@
1
-import { LANG } from '../action-creator.sync.js'
1
+import { UPDATE, LANG } from '../action-creator.sync.js'
2 2
 import flagEn from '../img/flag_en.png'
3 3
 import flagFr from '../img/flag_fr.png'
4 4
 
@@ -12,7 +12,7 @@ const defaultLang = [{
12 12
 
13 13
 export function lang (state = defaultLang, action) {
14 14
   switch (action.type) {
15
-    case `Update/${LANG}`:
15
+    case `${UPDATE}/${LANG}`:
16 16
       return action.langList
17 17
 
18 18
     // Côme - 2018/07/30 - deprecated, lang active is saved in user reducer

+ 2 - 2
frontend/src/reducer/timezone.js View File

@@ -1,8 +1,8 @@
1
-import { TIMEZONE } from '../action-creator.sync.js'
1
+import { SET, TIMEZONE } from '../action-creator.sync.js'
2 2
 
3 3
 export function timezone (state = [], action) {
4 4
   switch (action.type) {
5
-    case `Set/${TIMEZONE}`:
5
+    case `${SET}/${TIMEZONE}`:
6 6
       return action.timezone
7 7
 
8 8
     default:

+ 6 - 4
frontend/src/reducer/user.js View File

@@ -1,4 +1,6 @@
1 1
 import {
2
+  SET,
3
+  UPDATE,
2 4
   USER_CONNECTED,
3 5
   USER_DISCONNECTED,
4 6
   USER_DATA,
@@ -25,20 +27,20 @@ const defaultUser = {
25 27
 
26 28
 export default function user (state = defaultUser, action) {
27 29
   switch (action.type) {
28
-    case `Set/${USER_CONNECTED}`:
30
+    case `${SET}/${USER_CONNECTED}`:
29 31
       return {
30 32
         ...state,
31 33
         ...action.user,
32 34
         avatar_url: 'https://www.algoo.fr/static/images/people_images/PERSO_SEUL.png' // @FIXME use avatar from api when db handles it
33 35
       }
34 36
 
35
-    case `Set/${USER_DISCONNECTED}`:
37
+    case `${SET}/${USER_DISCONNECTED}`:
36 38
       return defaultUser
37 39
 
38
-    case `Update/${USER_DATA}`:
40
+    case `${UPDATE}/${USER_DATA}`:
39 41
       return {...state, ...action.data}
40 42
 
41
-    case `Set/${USER_LANG}`:
43
+    case `${SET}/${USER_LANG}`:
42 44
       return {...state, lang: action.lang}
43 45
 
44 46
     default:

+ 5 - 3
frontend/src/reducer/workspaceContent.js View File

@@ -1,11 +1,13 @@
1 1
 import {
2
+  SET,
3
+  UPDATE,
2 4
   WORKSPACE,
3 5
   FOLDER
4 6
 } from '../action-creator.sync.js'
5 7
 
6 8
 export default function workspace (state = [], action) {
7 9
   switch (action.type) {
8
-    case `Set/${WORKSPACE}/Content`:
10
+    case `${SET}/${WORKSPACE}/Content`:
9 11
       return action.workspaceContent.map(wsc => ({
10 12
         id: wsc.content_id,
11 13
         label: wsc.label,
@@ -20,10 +22,10 @@ export default function workspace (state = [], action) {
20 22
         subContentTypeSlug: wsc.sub_content_type_slug
21 23
       }))
22 24
 
23
-    case `Update/${WORKSPACE}/Filter`: // not used anymore ?
25
+    case `${UPDATE}/${WORKSPACE}/Filter`: // not used anymore ?
24 26
       return {...state, filter: action.filterList}
25 27
 
26
-    case `Set/${WORKSPACE}/${FOLDER}/Content`:
28
+    case `${SET}/${WORKSPACE}/${FOLDER}/Content`:
27 29
       const setFolderContent = (contentItem, action) => {
28 30
         if (contentItem.id === action.folderId) return {...contentItem, content: action.content}
29 31
 

+ 6 - 4
frontend/src/reducer/workspaceList.js View File

@@ -1,4 +1,6 @@
1 1
 import {
2
+  SET,
3
+  UPDATE,
2 4
   WORKSPACE_LIST,
3 5
   USER_ROLE
4 6
 } from '../action-creator.sync.js'
@@ -7,7 +9,7 @@ const handleRouteFromApi = route => route.startsWith('/#') ? route.slice(2) : ro
7 9
 
8 10
 export function workspaceList (state = [], action) {
9 11
   switch (action.type) {
10
-    case `Update/${WORKSPACE_LIST}`:
12
+    case `${UPDATE}/${WORKSPACE_LIST}`:
11 13
       return action.workspaceList.map(ws => ({
12 14
         id: ws.workspace_id,
13 15
         label: ws.label,
@@ -23,13 +25,13 @@ export function workspaceList (state = [], action) {
23 25
         isOpenInSidebar: false
24 26
       }))
25 27
 
26
-    case `Set/${WORKSPACE_LIST}/isOpenInSidebar`:
28
+    case `${SET}/${WORKSPACE_LIST}/isOpenInSidebar`:
27 29
       return state.map(ws => ws.id === action.workspaceId
28 30
         ? {...ws, isOpenInSidebar: action.isOpenInSidebar}
29 31
         : ws
30 32
       )
31 33
 
32
-    case `Set/${USER_ROLE}`: // not used yet
34
+    case `${SET}/${USER_ROLE}`: // not used yet
33 35
       return state.map(ws => {
34 36
         const foundWorkspace = action.userRole.find(r => ws.id === r.workspace.id) || {role: '', subscribed_to_notif: ''}
35 37
         return {
@@ -39,7 +41,7 @@ export function workspaceList (state = [], action) {
39 41
         }
40 42
       })
41 43
 
42
-    case `Update/${USER_ROLE}/SubscriptionNotif`: // not used yet
44
+    case `${UPDATE}/${USER_ROLE}/SubscriptionNotif`: // not used yet
43 45
       return state.map(ws => ws.id === action.workspaceId
44 46
         ? {...ws, notif: action.subscriptionNotif}
45 47
         : ws