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.any.ts 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. import { IStore } from '../app/types';
  2. import {
  3. ADD_TO_OFFSET,
  4. ADD_TO_OFFSET_LEFT,
  5. ADD_TO_OFFSET_RIGHT,
  6. INIT_REORDER_STATS,
  7. INIT_SEARCH,
  8. INIT_UPDATE_STATS,
  9. RESET_SEARCH_CRITERIA,
  10. SET_PANNING,
  11. SET_TIMELINE_BOUNDARY,
  12. TOGGLE_FACE_EXPRESSIONS,
  13. UPDATE_SORTED_SPEAKER_STATS_IDS,
  14. UPDATE_STATS
  15. } from './actionTypes';
  16. import { MINIMUM_INTERVAL } from './constants';
  17. import { getCurrentDuration, getTimelineBoundaries } from './functions';
  18. import { ISpeakerStats } from './reducer';
  19. /**
  20. * Starts a search by criteria.
  21. *
  22. * @param {string} criteria - The search criteria.
  23. * @returns {Object}
  24. */
  25. export function initSearch(criteria: string) {
  26. return {
  27. type: INIT_SEARCH,
  28. criteria
  29. };
  30. }
  31. /**
  32. * Gets the new stats and triggers update.
  33. *
  34. * @param {Function} getSpeakerStats - Function to get the speaker stats.
  35. * @returns {Object}
  36. */
  37. export function initUpdateStats(getSpeakerStats: () => ISpeakerStats) {
  38. return {
  39. type: INIT_UPDATE_STATS,
  40. getSpeakerStats
  41. };
  42. }
  43. /**
  44. * Updates the stats with new stats.
  45. *
  46. * @param {Object} stats - The new stats.
  47. * @returns {Object}
  48. */
  49. export function updateStats(stats: Object) {
  50. return {
  51. type: UPDATE_STATS,
  52. stats
  53. };
  54. }
  55. /**
  56. * Updates the speaker stats order.
  57. *
  58. * @param {Array<string>} participantIds - Participant ids.
  59. * @returns {Object}
  60. */
  61. export function updateSortedSpeakerStatsIds(participantIds: Array<string>) {
  62. return {
  63. type: UPDATE_SORTED_SPEAKER_STATS_IDS,
  64. participantIds
  65. };
  66. }
  67. /**
  68. * Initiates reordering of the stats.
  69. *
  70. * @returns {Object}
  71. */
  72. export function initReorderStats() {
  73. return {
  74. type: INIT_REORDER_STATS
  75. };
  76. }
  77. /**
  78. * Resets the search criteria.
  79. *
  80. * @returns {Object}
  81. */
  82. export function resetSearchCriteria() {
  83. return {
  84. type: RESET_SEARCH_CRITERIA
  85. };
  86. }
  87. /**
  88. * Toggles the face expressions grid.
  89. *
  90. * @returns {Object}
  91. */
  92. export function toggleFaceExpressions() {
  93. return {
  94. type: TOGGLE_FACE_EXPRESSIONS
  95. };
  96. }
  97. /**
  98. * Adds a value to the boundary offset of the timeline.
  99. *
  100. * @param {number} value - The value to be added.
  101. * @param {number} left - The left boundary.
  102. * @param {number} right - The right boundary.
  103. * @param {number} currentDuration - The currentDuration of the conference.
  104. * @returns {Object}
  105. */
  106. export function addToOffset(value: number) {
  107. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  108. const state = getState();
  109. const { left, right } = getTimelineBoundaries(state);
  110. const currentDuration = getCurrentDuration(state) ?? 0;
  111. const newLeft = left + value;
  112. const newRight = right + value;
  113. if (newLeft >= 0 && newRight <= currentDuration) {
  114. dispatch({
  115. type: ADD_TO_OFFSET,
  116. value
  117. });
  118. } else if (newLeft < 0) {
  119. dispatch({
  120. type: ADD_TO_OFFSET,
  121. value: -left
  122. });
  123. } else if (newRight > currentDuration) {
  124. dispatch({
  125. type: ADD_TO_OFFSET,
  126. value: currentDuration - right
  127. });
  128. }
  129. };
  130. }
  131. /**
  132. * Adds the value to the offset of the left boundary for the timeline.
  133. *
  134. * @param {number} value - The new value for the offset.
  135. * @returns {Object}
  136. */
  137. export function addToOffsetLeft(value: number) {
  138. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  139. const state = getState();
  140. const { left, right } = getTimelineBoundaries(state);
  141. const newLeft = left + value;
  142. if (newLeft >= 0 && right - newLeft > MINIMUM_INTERVAL) {
  143. dispatch({
  144. type: ADD_TO_OFFSET_LEFT,
  145. value
  146. });
  147. } else if (newLeft < 0) {
  148. dispatch({
  149. type: ADD_TO_OFFSET_LEFT,
  150. value: -left
  151. });
  152. }
  153. };
  154. }
  155. /**
  156. * Adds the value to the offset of the right boundary for the timeline.
  157. *
  158. * @param {number} value - The new value for the offset.
  159. * @returns {Object}
  160. */
  161. export function addToOffsetRight(value: number) {
  162. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  163. const state = getState();
  164. const { left, right } = getTimelineBoundaries(state);
  165. const currentDuration = getCurrentDuration(state) ?? 0;
  166. const newRight = right + value;
  167. if (newRight <= currentDuration && newRight - left > MINIMUM_INTERVAL) {
  168. dispatch({
  169. type: ADD_TO_OFFSET_RIGHT,
  170. value
  171. });
  172. } else if (newRight > currentDuration) {
  173. dispatch({
  174. type: ADD_TO_OFFSET_RIGHT,
  175. value: currentDuration - right
  176. });
  177. }
  178. };
  179. }
  180. /**
  181. * Sets the current time boundary of the timeline, when zoomed in.
  182. *
  183. * @param {number} boundary - The current time boundary.
  184. * @returns {Object}
  185. */
  186. export function setTimelineBoundary(boundary: number) {
  187. return {
  188. type: SET_TIMELINE_BOUNDARY,
  189. boundary
  190. };
  191. }
  192. /**
  193. * Clears the current time boundary of the timeline, when zoomed out full.
  194. *
  195. * @returns {Object}
  196. */
  197. export function clearTimelineBoundary() {
  198. return {
  199. type: SET_TIMELINE_BOUNDARY,
  200. boundary: null
  201. };
  202. }
  203. /**
  204. * Sets the state of the timeline panning.
  205. *
  206. * @param {Object} panning - The state of the timeline panning.
  207. * @returns {Object}
  208. */
  209. export function setTimelinePanning(panning: { active: boolean; x: number; }) {
  210. return {
  211. type: SET_PANNING,
  212. panning
  213. };
  214. }