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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import jitsiLocalStorage from '../../../modules/util/JitsiLocalStorage';
  2. import {
  3. HIDE_NOTIFICATION,
  4. SHOW_NOTIFICATION
  5. } from './actionTypes';
  6. import { NotificationWithToggle } from './components';
  7. /**
  8. * Removes the notification with the passed in id.
  9. *
  10. * @param {string} uid - The unique identifier for the notification to be
  11. * removed.
  12. * @returns {{
  13. * type: HIDE_NOTIFICATION,
  14. * uid: number
  15. * }}
  16. */
  17. export function hideNotification(uid) {
  18. return {
  19. type: HIDE_NOTIFICATION,
  20. uid
  21. };
  22. }
  23. /**
  24. * Queues a notification for display.
  25. *
  26. * @param {ReactComponent} component - The notification component to be
  27. * displayed.
  28. * @param {Object} props - The props needed to show the notification component.
  29. * @param {number} timeout - How long the notification should display before
  30. * automatically being hidden.
  31. * @returns {{
  32. * type: SHOW_NOTIFICATION,
  33. * component: ReactComponent,
  34. * props: Object,
  35. * timeout: number,
  36. * uid: number
  37. * }}
  38. */
  39. export function showNotification(component, props = {}, timeout) {
  40. return {
  41. type: SHOW_NOTIFICATION,
  42. component,
  43. props,
  44. timeout,
  45. uid: window.Date.now()
  46. };
  47. }
  48. /**
  49. * Displays a notification unless the passed in persistenceKey value exists in
  50. * local storage and has been set to "true".
  51. *
  52. * @param {string} persistenceKey - The local storage key to look up for whether
  53. * or not the notification should display.
  54. * @param {Object} props - The props needed to show the notification component.
  55. * @returns {Function}
  56. */
  57. export function maybeShowNotificationWithDoNotDisplay(persistenceKey, props) {
  58. return dispatch => {
  59. if (jitsiLocalStorage.getItem(persistenceKey) === 'true') {
  60. return;
  61. }
  62. const newProps = Object.assign({}, props, {
  63. onToggleSubmit: isToggled => {
  64. jitsiLocalStorage.setItem(persistenceKey, isToggled);
  65. }
  66. });
  67. dispatch({
  68. type: SHOW_NOTIFICATION,
  69. component: NotificationWithToggle,
  70. props: newProps,
  71. uid: window.Date.now()
  72. });
  73. };
  74. }