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.ts 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. import {
  2. CHANGE_VOTE,
  3. CLEAR_POLLS,
  4. EDIT_POLL,
  5. RECEIVE_ANSWER,
  6. RECEIVE_POLL,
  7. REGISTER_VOTE,
  8. REMOVE_POLL,
  9. RESET_NB_UNREAD_POLLS,
  10. SAVE_POLL
  11. } from './actionTypes';
  12. import { IAnswer, IPoll } from './types';
  13. /**
  14. * Action to signal that existing polls needs to be cleared from state.
  15. *
  16. * @returns {{
  17. * type: CLEAR_POLLS
  18. * }}
  19. */
  20. export const clearPolls = () => {
  21. return {
  22. type: CLEAR_POLLS
  23. };
  24. };
  25. /**
  26. * Action to signal that a poll's vote will be changed.
  27. *
  28. * @param {string} pollId - The id of the incoming poll.
  29. * @param {boolean} value - The value of the 'changing' state.
  30. * @returns {{
  31. * type: CHANGE_VOTE,
  32. * pollId: string,
  33. * value: boolean
  34. * }}
  35. */
  36. export const setVoteChanging = (pollId: string, value: boolean) => {
  37. return {
  38. type: CHANGE_VOTE,
  39. pollId,
  40. value
  41. };
  42. };
  43. /**
  44. * Action to signal that a new poll was received.
  45. *
  46. * @param {string} pollId - The id of the incoming poll.
  47. * @param {IPoll} poll - The incoming Poll object.
  48. * @param {boolean} notify - Whether to send or not a notification.
  49. * @returns {{
  50. * type: RECEIVE_POLL,
  51. * pollId: string,
  52. * poll: IPoll,
  53. * notify: boolean
  54. * }}
  55. */
  56. export const receivePoll = (pollId: string, poll: IPoll, notify: boolean) => {
  57. return {
  58. type: RECEIVE_POLL,
  59. pollId,
  60. poll,
  61. notify
  62. };
  63. };
  64. /**
  65. * Action to signal that a new answer was received.
  66. *
  67. * @param {string} pollId - The id of the incoming poll.
  68. * @param {IAnswer} answer - The incoming Answer object.
  69. * @returns {{
  70. * type: RECEIVE_ANSWER,
  71. * pollId: string,
  72. * answer: IAnswer
  73. * }}
  74. */
  75. export const receiveAnswer = (pollId: string, answer: IAnswer) => {
  76. return {
  77. type: RECEIVE_ANSWER,
  78. pollId,
  79. answer
  80. };
  81. };
  82. /**
  83. * Action to register a vote on a poll.
  84. *
  85. * @param {string} pollId - The id of the poll.
  86. * @param {?Array<boolean>} answers - The new answers.
  87. * @returns {{
  88. * type: REGISTER_VOTE,
  89. * pollId: string,
  90. * answers: ?Array<boolean>
  91. * }}
  92. */
  93. export const registerVote = (pollId: string, answers: Array<boolean> | null) => {
  94. return {
  95. type: REGISTER_VOTE,
  96. pollId,
  97. answers
  98. };
  99. };
  100. /**
  101. * Action to signal the number reset of unread polls.
  102. *
  103. * @returns {{
  104. * type: RESET_NB_UNREAD_POLLS
  105. * }}
  106. */
  107. export function resetNbUnreadPollsMessages() {
  108. return {
  109. type: RESET_NB_UNREAD_POLLS
  110. };
  111. }
  112. /**
  113. * Action to signal saving a poll.
  114. *
  115. * @param {string} pollId - The id of the poll that gets to be saved.
  116. * @param {IPoll} poll - The Poll object that gets to be saved.
  117. * @returns {{
  118. * type: SAVE_POLL,
  119. * meetingId: string,
  120. * pollId: string,
  121. * poll: IPoll
  122. * }}
  123. */
  124. export function savePoll(pollId: string, poll: IPoll) {
  125. return {
  126. type: SAVE_POLL,
  127. pollId,
  128. poll
  129. };
  130. }
  131. /**
  132. * Action to signal editing a poll.
  133. *
  134. * @param {string} pollId - The id of the poll that gets to be edited.
  135. * @param {boolean} editing - Whether the poll is in edit mode or not.
  136. * @returns {{
  137. * type: EDIT_POLL,
  138. * pollId: string,
  139. * editing: boolean
  140. * }}
  141. */
  142. export function editPoll(pollId: string, editing: boolean) {
  143. return {
  144. type: EDIT_POLL,
  145. pollId,
  146. editing
  147. };
  148. }
  149. /**
  150. * Action to signal that existing polls needs to be removed.
  151. *
  152. * @param {string} pollId - The id of the poll that gets to be removed.
  153. * @param {IPoll} poll - The incoming Poll object.
  154. * @returns {{
  155. * type: REMOVE_POLL,
  156. * pollId: string,
  157. * poll: IPoll
  158. * }}
  159. */
  160. export const removePoll = (pollId: string, poll: IPoll) => {
  161. return {
  162. type: REMOVE_POLL,
  163. pollId,
  164. poll
  165. };
  166. };