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 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import ReducerRegistry from '../base/redux/ReducerRegistry';
  2. import { assign } from '../base/redux/functions';
  3. import {
  4. CANCEL_LOGIN,
  5. STOP_WAIT_FOR_OWNER,
  6. UPGRADE_ROLE_FINISHED,
  7. UPGRADE_ROLE_STARTED,
  8. WAIT_FOR_OWNER
  9. } from './actionTypes';
  10. export interface IAuthenticationState {
  11. error?: Object|undefined;
  12. progress?: number|undefined;
  13. thenableWithCancel?: Object|undefined;
  14. waitForOwnerTimeoutID?: number;
  15. }
  16. /**
  17. * Listens for actions which change the state of the authentication feature.
  18. *
  19. * @param {Object} state - The Redux state of the authentication feature.
  20. * @param {Object} action - Action object.
  21. * @param {string} action.type - Type of action.
  22. * @returns {Object}
  23. */
  24. ReducerRegistry.register('features/authentication', (state: IAuthenticationState = {}, action: any) => {
  25. switch (action.type) {
  26. case CANCEL_LOGIN:
  27. return assign(state, {
  28. error: undefined,
  29. progress: undefined,
  30. thenableWithCancel: undefined
  31. });
  32. case STOP_WAIT_FOR_OWNER:
  33. return assign(state, {
  34. error: undefined,
  35. waitForOwnerTimeoutID: undefined
  36. });
  37. case UPGRADE_ROLE_FINISHED: {
  38. let { thenableWithCancel } = action;
  39. if (state.thenableWithCancel === thenableWithCancel) {
  40. const { error, progress } = action;
  41. // An error interrupts the process of authenticating and upgrading
  42. // the role of the local participant/user i.e. the process is no
  43. // more. Obviously, the process seizes to exist also when it does
  44. // its whole job.
  45. if (error || progress === 1) {
  46. thenableWithCancel = undefined;
  47. }
  48. return assign(state, {
  49. error,
  50. progress: progress || undefined,
  51. thenableWithCancel
  52. });
  53. }
  54. break;
  55. }
  56. case UPGRADE_ROLE_STARTED:
  57. return assign(state, {
  58. error: undefined,
  59. progress: undefined,
  60. thenableWithCancel: action.thenableWithCancel
  61. });
  62. case WAIT_FOR_OWNER:
  63. return assign(state, {
  64. waitForOwnerTimeoutID: action.waitForOwnerTimeoutID
  65. });
  66. }
  67. return state;
  68. });