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.

actions.js 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import {
  2. HIDE_DIALOG,
  3. OPEN_DIALOG
  4. } from './actionTypes';
  5. /**
  6. * Signals Dialog to close its dialog.
  7. *
  8. * @returns {{
  9. * type: HIDE_DIALOG
  10. * }}
  11. */
  12. export function hideDialog() {
  13. return {
  14. type: HIDE_DIALOG
  15. };
  16. }
  17. /**
  18. * Signals Dialog to open dialog.
  19. *
  20. * @param {Object} component - The component to display as dialog.
  21. * @param {Object} componentProps - The properties needed for that component.
  22. * @returns {Object}
  23. */
  24. export function openDialog(component, componentProps) {
  25. return {
  26. type: OPEN_DIALOG,
  27. component,
  28. componentProps
  29. };
  30. }
  31. /**
  32. * Signals Dialog to open a dialog with the specified component if the component
  33. * is not already open. If it is open, then Dialog is signaled to close
  34. * its dialog.
  35. *
  36. * @param {Object} component - The component to display as dialog.
  37. * @param {Object} componentProps - The properties needed for that component.
  38. * @returns {Object}
  39. */
  40. export function toggleDialog(component, componentProps) {
  41. return (dispatch, getState) => {
  42. const state = getState();
  43. const dialogState = state['features/base/dialog'];
  44. if (dialogState.component === component) {
  45. dispatch(hideDialog());
  46. } else {
  47. dispatch(openDialog(component, componentProps));
  48. }
  49. };
  50. }