選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

actions.js 2.5KB

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