reducers.ts 937 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { FolderState } from 'app/types';
  2. import { Action, ActionTypes } from './actions';
  3. import { processAclItems } from 'app/core/utils/acl';
  4. export const inititalState: FolderState = {
  5. id: 0,
  6. uid: 'loading',
  7. title: 'loading',
  8. url: '',
  9. canSave: false,
  10. hasChanged: false,
  11. version: 1,
  12. permissions: [],
  13. };
  14. export const folderReducer = (state = inititalState, action: Action): FolderState => {
  15. switch (action.type) {
  16. case ActionTypes.LoadFolder:
  17. return {
  18. ...state,
  19. ...action.payload,
  20. hasChanged: false,
  21. };
  22. case ActionTypes.SetFolderTitle:
  23. return {
  24. ...state,
  25. title: action.payload,
  26. hasChanged: action.payload.trim().length > 0,
  27. };
  28. case ActionTypes.LoadFolderPermissions:
  29. return {
  30. ...state,
  31. permissions: processAclItems(action.payload),
  32. };
  33. }
  34. return state;
  35. };
  36. export default {
  37. folder: folderReducer,
  38. };