workspaceList.js 1.5KB

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