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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // @flow
  2. import {
  3. RESET_NB_UNREAD_POLLS,
  4. RECEIVE_ANSWER,
  5. RECEIVE_POLL,
  6. REGISTER_VOTE,
  7. RETRACT_VOTE
  8. } from './actionTypes';
  9. import type { Answer, Poll } from './types';
  10. /**
  11. * Action to signal that a new poll was received.
  12. *
  13. * @param {string} pollId - The id of the incoming poll.
  14. * @param {Poll} poll - The incoming Poll object.
  15. * @param {boolean} notify - Whether to send or not a notification.
  16. * @returns {{
  17. * type: RECEIVE_POLL,
  18. * poll: Poll,
  19. * pollId: string,
  20. * notify: boolean
  21. * }}
  22. */
  23. export const receivePoll = (pollId: string, poll: Poll, notify: boolean) => {
  24. return {
  25. type: RECEIVE_POLL,
  26. poll,
  27. pollId,
  28. notify
  29. };
  30. };
  31. /**
  32. * Action to signal that a new answer was received.
  33. *
  34. * @param {string} pollId - The id of the incoming poll.
  35. * @param {Answer} answer - The incoming Answer object.
  36. * @returns {{
  37. * type: RECEIVE_ANSWER,
  38. * answer: Answer,
  39. * pollId: string
  40. * }}
  41. */
  42. export const receiveAnswer = (pollId: string, answer: Answer) => {
  43. return {
  44. type: RECEIVE_ANSWER,
  45. answer,
  46. pollId
  47. };
  48. };
  49. /**
  50. * Action to register a vote on a poll.
  51. *
  52. * @param {string} pollId - The id of the poll.
  53. * @param {?Array<boolean>} answers - The new answers.
  54. * @returns {{
  55. * type: REGISTER_VOTE,
  56. * answers: ?Array<boolean>,
  57. * pollId: string
  58. * }}
  59. */
  60. export const registerVote = (pollId: string, answers: Array<boolean> | null) => {
  61. return {
  62. type: REGISTER_VOTE,
  63. answers,
  64. pollId
  65. };
  66. };
  67. /**
  68. * Action to retract a vote on a poll.
  69. *
  70. * @param {string} pollId - The id of the poll.
  71. * @returns {{
  72. * type: RETRACT_VOTE,
  73. * pollId: string
  74. * }}
  75. */
  76. export const retractVote = (pollId: string) => {
  77. return {
  78. type: RETRACT_VOTE,
  79. pollId
  80. };
  81. };
  82. /**
  83. * Action to signal the closing of the polls tab.
  84. *
  85. * @returns {{
  86. * type: POLL_TAB_CLOSED
  87. * }}
  88. */
  89. export function resetNbUnreadPollsMessages() {
  90. return {
  91. type: RESET_NB_UNREAD_POLLS
  92. };
  93. }