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
+export const SET = 'Set'
2
+export const UPDATE = 'Update'
3
+export const ADD = 'Add'
4
+export const REMOVE = 'Remove'
5
+
1
 export const TIMEZONE = 'Timezone'
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
 export const FLASH_MESSAGE = 'FlashMessage'
9
 export const FLASH_MESSAGE = 'FlashMessage'
5
 export const newFlashMessage = (msgText = '', msgType = 'info', msgDelay = 5000) => dispatch => {
10
 export const newFlashMessage = (msgText = '', msgType = 'info', msgDelay = 5000) => dispatch => {
6
   msgDelay !== 0 && window.setTimeout(() => dispatch(removeFlashMessage(msgText)), msgDelay)
11
   msgDelay !== 0 && window.setTimeout(() => dispatch(removeFlashMessage(msgText)), msgDelay)
7
   return dispatch(addFlashMessage({message: msgText, type: msgType}))
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
 export const USER_LOGIN = 'User/Login'
18
 export const USER_LOGIN = 'User/Login'
13
 export const USER_LOGOUT = 'User/Logout'
19
 export const USER_LOGOUT = 'User/Logout'
14
 export const USER_DATA = 'User/Data'
20
 export const USER_DATA = 'User/Data'
16
 export const USER_CONNECTED = 'User/Connected'
22
 export const USER_CONNECTED = 'User/Connected'
17
 export const USER_DISCONNECTED = 'User/Disconnected'
23
 export const USER_DISCONNECTED = 'User/Disconnected'
18
 export const USER_LANG = 'User/Lang'
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
 export const updateUserWorkspaceSubscriptionNotif = (workspaceId, subscriptionNotif) =>
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
 export const WORKSPACE = 'Workspace'
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
 export const FOLDER = 'Folder'
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
 export const WORKSPACE_LIST = 'WorkspaceList'
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
 export const APP_LIST = 'App/List'
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
 export const CONTENT_TYPE_LIST = 'ContentType/List'
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
 export const LANG = 'Lang'
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
-import { APP_LIST } from '../action-creator.sync.js'
1
+import { SET, APP_LIST } from '../action-creator.sync.js'
2
 
2
 
3
 export default function app (state = [], action) {
3
 export default function app (state = [], action) {
4
   switch (action.type) {
4
   switch (action.type) {
5
-    case `Set/${APP_LIST}`:
5
+    case `${SET}/${APP_LIST}`:
6
       return action.appList.map(a => ({
6
       return action.appList.map(a => ({
7
         label: a.label,
7
         label: a.label,
8
         slug: a.slug,
8
         slug: a.slug,

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

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

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

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
 export default function flashMessage (state = [], action) {
3
 export default function flashMessage (state = [], action) {
6
   switch (action.type) {
4
   switch (action.type) {
7
-    case `Add/${FLASH_MESSAGE}`:
5
+    case `${ADD}/${FLASH_MESSAGE}`:
8
       return [...state, {
6
       return [...state, {
9
         message: action.msg.message,
7
         message: action.msg.message,
10
         type: action.msg.type || 'info' // may be info, success, danger
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
       return state.filter(fm => fm.message === action.message)
12
       return state.filter(fm => fm.message === action.message)
15
 
13
 
16
     default:
14
     default:

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

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

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

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

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

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

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

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

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

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