Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

actions.any.ts 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { IStore } from '../app/types';
  2. import { doGetJSON } from '../base/util/httpUtils';
  3. import {
  4. SET_DYNAMIC_BRANDING_DATA,
  5. SET_DYNAMIC_BRANDING_FAILED,
  6. SET_DYNAMIC_BRANDING_READY
  7. } from './actionTypes';
  8. import { getDynamicBrandingUrl } from './functions.any';
  9. import logger from './logger';
  10. /**
  11. * Fetches custom branding data.
  12. * If there is no data or the request fails, sets the `customizationReady` flag
  13. * so the defaults can be displayed.
  14. *
  15. * @returns {Function}
  16. */
  17. export function fetchCustomBrandingData() {
  18. return async function(dispatch: IStore['dispatch'], getState: IStore['getState']) {
  19. const state = getState();
  20. const { customizationReady } = state['features/dynamic-branding'];
  21. if (!customizationReady) {
  22. const url = await getDynamicBrandingUrl(state);
  23. if (url) {
  24. try {
  25. const res = await doGetJSON(url);
  26. return dispatch(setDynamicBrandingData(res));
  27. } catch (err) {
  28. logger.error('Error fetching branding data', err);
  29. return dispatch(setDynamicBrandingFailed());
  30. }
  31. }
  32. dispatch(setDynamicBrandingReady());
  33. }
  34. };
  35. }
  36. /**
  37. * Action used to set the user customizations.
  38. *
  39. * @param {Object} value - The custom data to be set.
  40. * @returns {Object}
  41. */
  42. export function setDynamicBrandingData(value: Object) {
  43. return {
  44. type: SET_DYNAMIC_BRANDING_DATA,
  45. value
  46. };
  47. }
  48. /**
  49. * Action used to signal the branding elements are ready to be displayed.
  50. *
  51. * @returns {Object}
  52. */
  53. export function setDynamicBrandingReady() {
  54. return {
  55. type: SET_DYNAMIC_BRANDING_READY
  56. };
  57. }
  58. /**
  59. * Action used to signal the branding request failed.
  60. *
  61. * @returns {Object}
  62. */
  63. export function setDynamicBrandingFailed() {
  64. return {
  65. type: SET_DYNAMIC_BRANDING_FAILED
  66. };
  67. }