Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

actions.ts 2.7KB

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