Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

middleware.web.ts 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import { IStore } from '../../app/types';
  2. import { PREJOIN_INITIALIZED } from '../../prejoin/actionTypes';
  3. import { setPrejoinPageVisibility } from '../../prejoin/actions';
  4. import { APP_WILL_MOUNT } from '../app/actionTypes';
  5. import { getJwtName } from '../jwt/functions';
  6. import MiddlewareRegistry from '../redux/MiddlewareRegistry';
  7. import { updateSettings } from './actions';
  8. import './middleware.any';
  9. /**
  10. * The middleware of the feature base/settings. Distributes changes to the state
  11. * of base/settings to the states of other features computed from the state of
  12. * base/settings.
  13. *
  14. * @param {Store} store - The redux store.
  15. * @returns {Function}
  16. */
  17. MiddlewareRegistry.register(store => next => action => {
  18. const result = next(action);
  19. switch (action.type) {
  20. case APP_WILL_MOUNT:
  21. _initializeShowPrejoin(store);
  22. break;
  23. case PREJOIN_INITIALIZED:
  24. _maybeUpdateDisplayName(store);
  25. break;
  26. }
  27. return result;
  28. });
  29. /**
  30. * Overwrites the showPrejoin flag based on cached used selection for showing prejoin screen.
  31. *
  32. * @param {Store} store - The redux store.
  33. * @private
  34. * @returns {void}
  35. */
  36. function _initializeShowPrejoin({ dispatch, getState }: IStore) {
  37. const { userSelectedSkipPrejoin } = getState()['features/base/settings'];
  38. if (userSelectedSkipPrejoin) {
  39. dispatch(setPrejoinPageVisibility(false));
  40. }
  41. }
  42. /**
  43. * Updates the display name to the one in JWT if there is one.
  44. *
  45. * @param {Store} store - The redux store.
  46. * @private
  47. * @returns {void}
  48. */
  49. function _maybeUpdateDisplayName({ dispatch, getState }: IStore) {
  50. const state = getState();
  51. const hasJwt = Boolean(state['features/base/jwt'].jwt);
  52. if (hasJwt) {
  53. const displayName = getJwtName(state);
  54. if (displayName) {
  55. dispatch(updateSettings({
  56. displayName
  57. }));
  58. }
  59. }
  60. }