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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // @flow
  2. import {
  3. CHANGE_VOTE,
  4. CLEAR_POLLS,
  5. RESET_NB_UNREAD_POLLS,
  6. RECEIVE_ANSWER,
  7. RECEIVE_POLL,
  8. REGISTER_VOTE,
  9. RETRACT_VOTE
  10. } from './actionTypes';
  11. import type { Answer, Poll } from './types';
  12. /**
  13. * Action to signal that existing polls needs to be cleared from state.
  14. *
  15. * @returns {{
  16. * type: CLEAR_POLLS
  17. * }}
  18. */
  19. export const clearPolls = () => {
  20. return { type: CLEAR_POLLS };
  21. };
  22. /**
  23. * Action to signal that a poll's vote will be changed.
  24. *
  25. * @param {string} pollId - The id of the incoming poll.
  26. * @param {boolean} value - The value of the 'changing' state.
  27. * @returns {{
  28. * type: CHANGE_VOTE,
  29. * pollId: string,
  30. * value: boolean
  31. * }}
  32. */
  33. export const setVoteChanging = (pollId: string, value: boolean) => {
  34. return {
  35. type: CHANGE_VOTE,
  36. pollId,
  37. value
  38. };
  39. };
  40. /**
  41. * Action to signal that a new poll was received.
  42. *
  43. * @param {string} pollId - The id of the incoming poll.
  44. * @param {Poll} poll - The incoming Poll object.
  45. * @param {boolean} notify - Whether to send or not a notification.
  46. * @returns {{
  47. * type: RECEIVE_POLL,
  48. * poll: Poll,
  49. * pollId: string,
  50. * notify: boolean
  51. * }}
  52. */
  53. export const receivePoll = (pollId: string, poll: Poll, notify: boolean) => {
  54. return {
  55. type: RECEIVE_POLL,
  56. poll,
  57. pollId,
  58. notify
  59. };
  60. };
  61. /**
  62. * Action to signal that a new answer was received.
  63. *
  64. * @param {string} pollId - The id of the incoming poll.
  65. * @param {Answer} answer - The incoming Answer object.
  66. * @returns {{
  67. * type: RECEIVE_ANSWER,
  68. * answer: Answer,
  69. * pollId: string
  70. * }}
  71. */
  72. export const receiveAnswer = (pollId: string, answer: Answer) => {
  73. return {
  74. type: RECEIVE_ANSWER,
  75. answer,
  76. pollId
  77. };
  78. };
  79. /**
  80. * Action to register a vote on a poll.
  81. *
  82. * @param {string} pollId - The id of the poll.
  83. * @param {?Array<boolean>} answers - The new answers.
  84. * @returns {{
  85. * type: REGISTER_VOTE,
  86. * answers: ?Array<boolean>,
  87. * pollId: string
  88. * }}
  89. */
  90. export const registerVote = (pollId: string, answers: Array<boolean> | null) => {
  91. return {
  92. type: REGISTER_VOTE,
  93. answers,
  94. pollId
  95. };
  96. };
  97. /**
  98. * Action to retract a vote on a poll.
  99. *
  100. * @param {string} pollId - The id of the poll.
  101. * @returns {{
  102. * type: RETRACT_VOTE,
  103. * pollId: string
  104. * }}
  105. */
  106. export const retractVote = (pollId: string) => {
  107. return {
  108. type: RETRACT_VOTE,
  109. pollId
  110. };
  111. };
  112. /**
  113. * Action to signal the closing of the polls tab.
  114. *
  115. * @returns {{
  116. * type: POLL_TAB_CLOSED
  117. * }}
  118. */
  119. export function resetNbUnreadPollsMessages() {
  120. return {
  121. type: RESET_NB_UNREAD_POLLS
  122. };
  123. }