您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

actions.js 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import jitsiLocalStorage from '../../../modules/util/JitsiLocalStorage';
  2. import {
  3. HIDE_NOTIFICATION,
  4. SET_NOTIFICATIONS_ENABLED,
  5. SHOW_NOTIFICATION
  6. } from './actionTypes';
  7. import {
  8. Notification,
  9. NotificationWithToggle
  10. } from './components';
  11. import { NOTIFICATION_TYPE } from './constants';
  12. /**
  13. * Removes the notification with the passed in id.
  14. *
  15. * @param {string} uid - The unique identifier for the notification to be
  16. * removed.
  17. * @returns {{
  18. * type: HIDE_NOTIFICATION,
  19. * uid: number
  20. * }}
  21. */
  22. export function hideNotification(uid) {
  23. return {
  24. type: HIDE_NOTIFICATION,
  25. uid
  26. };
  27. }
  28. /**
  29. * Stops notifications from being displayed.
  30. *
  31. * @param {boolean} enabled - Whether or not notifications should display.
  32. * @returns {{
  33. * type: SET_NOTIFICATIONS_ENABLED,
  34. * enabled: boolean
  35. * }}
  36. */
  37. export function setNotificationsEnabled(enabled) {
  38. return {
  39. type: SET_NOTIFICATIONS_ENABLED,
  40. enabled
  41. };
  42. }
  43. /**
  44. * Queues an error notification for display.
  45. *
  46. * @param {Object} props - The props needed to show the notification component.
  47. * @returns {Object}
  48. */
  49. export function showErrorNotification(props) {
  50. return showNotification(Notification, {
  51. ...props,
  52. appearance: NOTIFICATION_TYPE.ERROR
  53. });
  54. }
  55. /**
  56. * Queues a notification for display.
  57. *
  58. * @param {ReactComponent} component - The notification component to be
  59. * displayed.
  60. * @param {Object} props - The props needed to show the notification component.
  61. * @param {number} timeout - How long the notification should display before
  62. * automatically being hidden.
  63. * @returns {{
  64. * type: SHOW_NOTIFICATION,
  65. * component: ReactComponent,
  66. * props: Object,
  67. * timeout: number,
  68. * uid: number
  69. * }}
  70. */
  71. export function showNotification(component, props = {}, timeout) {
  72. return {
  73. type: SHOW_NOTIFICATION,
  74. component,
  75. props,
  76. timeout,
  77. uid: window.Date.now()
  78. };
  79. }
  80. /**
  81. * Queues a warning notification for display.
  82. *
  83. * @param {Object} props - The props needed to show the notification component.
  84. * @returns {Object}
  85. */
  86. export function showWarningNotification(props) {
  87. return showNotification(Notification, {
  88. ...props,
  89. appearance: NOTIFICATION_TYPE.WARNING
  90. });
  91. }
  92. /**
  93. * Displays a notification unless the passed in persistenceKey value exists in
  94. * local storage and has been set to "true".
  95. *
  96. * @param {string} persistenceKey - The local storage key to look up for whether
  97. * or not the notification should display.
  98. * @param {Object} props - The props needed to show the notification component.
  99. * @returns {Function}
  100. */
  101. export function maybeShowNotificationWithDoNotDisplay(persistenceKey, props) {
  102. return dispatch => {
  103. if (jitsiLocalStorage.getItem(persistenceKey) === 'true') {
  104. return;
  105. }
  106. const newProps = Object.assign({}, props, {
  107. onToggleSubmit: isToggled => {
  108. jitsiLocalStorage.setItem(persistenceKey, isToggled);
  109. }
  110. });
  111. dispatch({
  112. type: SHOW_NOTIFICATION,
  113. component: NotificationWithToggle,
  114. props: newProps,
  115. uid: window.Date.now()
  116. });
  117. };
  118. }