You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

reducer.ts 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import ReducerRegistry from '../base/redux/ReducerRegistry';
  2. import { ADD_FILE, UPDATE_FILE_UPLOAD_PROGRESS, _FILE_LIST_RECEIVED, _FILE_REMOVED } from './actionTypes';
  3. import { IFileMetadata } from './types';
  4. export interface IFileSharingState {
  5. files: Map<string, IFileMetadata>;
  6. }
  7. const DEFAULT_STATE = {
  8. files: new Map<string, IFileMetadata>()
  9. };
  10. ReducerRegistry.register<IFileSharingState>('features/file-sharing',
  11. (state = DEFAULT_STATE, action): IFileSharingState => {
  12. switch (action.type) {
  13. case ADD_FILE: {
  14. const newFiles = new Map(state.files);
  15. newFiles.set(action.file.fileId, action.file);
  16. return {
  17. files: newFiles
  18. };
  19. }
  20. case _FILE_REMOVED: {
  21. const newFiles = new Map(state.files);
  22. newFiles.delete(action.fileId);
  23. return {
  24. files: newFiles
  25. };
  26. }
  27. case UPDATE_FILE_UPLOAD_PROGRESS: {
  28. const newFiles = new Map(state.files);
  29. const file = newFiles.get(action.fileId);
  30. if (file) {
  31. newFiles.set(action.fileId, { ...file, progress: action.progress });
  32. }
  33. return {
  34. files: newFiles
  35. };
  36. }
  37. case _FILE_LIST_RECEIVED: {
  38. return {
  39. files: new Map(Object.entries(action.files))
  40. };
  41. }
  42. default:
  43. return state;
  44. }
  45. });