Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

reducer.js 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // @flow
  2. import { ReducerRegistry, set } from '../base/redux';
  3. import { PersistenceRegistry } from '../base/storage';
  4. import {
  5. CLEAR_CALENDAR_INTEGRATION,
  6. SET_CALENDAR_AUTH_STATE,
  7. SET_CALENDAR_AUTHORIZATION,
  8. SET_CALENDAR_ERROR,
  9. SET_CALENDAR_EVENTS,
  10. SET_CALENDAR_INTEGRATION,
  11. SET_CALENDAR_PROFILE_EMAIL,
  12. SET_LOADING_CALENDAR_EVENTS
  13. } from './actionTypes';
  14. /**
  15. * The default state of the calendar feature.
  16. *
  17. * @type {Object}
  18. */
  19. const DEFAULT_STATE = {
  20. authorization: undefined,
  21. events: [],
  22. integrationReady: false,
  23. integrationType: undefined,
  24. msAuthState: undefined
  25. };
  26. /**
  27. * Constant for the Redux subtree of the calendar feature.
  28. *
  29. * NOTE: This feature can be disabled and in that case, accessing this subtree
  30. * directly will return undefined and will need a bunch of repetitive type
  31. * checks in other features. Make sure you take care of those checks, or
  32. * consider using the {@code isCalendarEnabled} value to gate features if
  33. * needed.
  34. */
  35. const STORE_NAME = 'features/calendar-sync';
  36. /**
  37. * NOTE: Never persist the authorization value as it's needed to remain a
  38. * runtime value to see if we need to re-request the calendar permission from
  39. * the user.
  40. */
  41. PersistenceRegistry.register(STORE_NAME, {
  42. integrationType: true,
  43. msAuthState: true
  44. });
  45. ReducerRegistry.register(STORE_NAME, (state = DEFAULT_STATE, action) => {
  46. switch (action.type) {
  47. case CLEAR_CALENDAR_INTEGRATION:
  48. return DEFAULT_STATE;
  49. case SET_CALENDAR_AUTH_STATE: {
  50. if (!action.msAuthState) {
  51. // received request to delete the state
  52. return set(state, 'msAuthState', undefined);
  53. }
  54. return set(state, 'msAuthState', {
  55. ...state.msAuthState,
  56. ...action.msAuthState
  57. });
  58. }
  59. case SET_CALENDAR_AUTHORIZATION:
  60. return set(state, 'authorization', action.authorization);
  61. case SET_CALENDAR_ERROR:
  62. return set(state, 'error', action.error);
  63. case SET_CALENDAR_EVENTS:
  64. return set(state, 'events', action.events);
  65. case SET_CALENDAR_INTEGRATION:
  66. return {
  67. ...state,
  68. integrationReady: action.integrationReady,
  69. integrationType: action.integrationType
  70. };
  71. case SET_CALENDAR_PROFILE_EMAIL:
  72. return set(state, 'profileEmail', action.email);
  73. case SET_LOADING_CALENDAR_EVENTS:
  74. return set(state, 'isLoadingEvents', action.isLoadingEvents);
  75. }
  76. return state;
  77. });