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.

reducer.ts 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // @ts-ignore
  2. import { ReducerRegistry } from '../base/redux';
  3. import {
  4. TOGGLE_REACTIONS_VISIBLE,
  5. SET_REACTION_QUEUE,
  6. ADD_REACTION_BUFFER,
  7. FLUSH_REACTION_BUFFER,
  8. SHOW_SOUNDS_NOTIFICATION
  9. } from './actionTypes';
  10. import { ReactionEmojiProps } from './constants';
  11. interface IReactionsState {
  12. /**
  13. * The indicator that determines whether the reactions menu is visible.
  14. */
  15. visible: boolean,
  16. /**
  17. * An array that contains the reactions buffer to be sent.
  18. */
  19. buffer: Array<string>,
  20. /**
  21. * A number, non-zero value which identifies the timer created by a call
  22. * to setTimeout().
  23. */
  24. timeoutID: number|null,
  25. /**
  26. * The array of reactions to animate.
  27. */
  28. queue: Array<ReactionEmojiProps>,
  29. /**
  30. * Whether or not the disable reaction sounds notification was shown.
  31. */
  32. notificationDisplayed: boolean
  33. }
  34. export interface ReactionsAction extends Partial<IReactionsState> {
  35. /**
  36. * The message to be added to the chat.
  37. */
  38. message?: string,
  39. /**
  40. * The reaction to be added to buffer.
  41. */
  42. reaction?: string,
  43. /**
  44. * The reactions to be added to the animation queue.
  45. */
  46. reactions?: Array<string>,
  47. /**
  48. * The action type.
  49. */
  50. type: string
  51. }
  52. /**
  53. * Returns initial state for reactions' part of Redux store.
  54. *
  55. * @private
  56. * @returns {IReactionsState}
  57. */
  58. function _getInitialState(): IReactionsState {
  59. return {
  60. visible: false,
  61. buffer: [],
  62. timeoutID: null,
  63. queue: [],
  64. notificationDisplayed: false
  65. };
  66. }
  67. ReducerRegistry.register(
  68. 'features/reactions',
  69. (state: IReactionsState = _getInitialState(), action: ReactionsAction) => {
  70. switch (action.type) {
  71. case TOGGLE_REACTIONS_VISIBLE:
  72. return {
  73. ...state,
  74. visible: !state.visible
  75. };
  76. case ADD_REACTION_BUFFER:
  77. return {
  78. ...state,
  79. buffer: action.buffer,
  80. timeoutID: action.timeoutID
  81. };
  82. case FLUSH_REACTION_BUFFER:
  83. return {
  84. ...state,
  85. buffer: [],
  86. timeoutID: null
  87. };
  88. case SET_REACTION_QUEUE: {
  89. return {
  90. ...state,
  91. queue: action.queue
  92. };
  93. }
  94. case SHOW_SOUNDS_NOTIFICATION: {
  95. return {
  96. ...state,
  97. notificationDisplayed: true
  98. };
  99. }
  100. }
  101. return state;
  102. });