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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import _ from 'lodash';
  2. import ReducerRegistry from '../base/redux/ReducerRegistry';
  3. import {
  4. INIT_REORDER_STATS,
  5. INIT_SEARCH,
  6. RESET_SEARCH_CRITERIA,
  7. TOGGLE_FACE_EXPRESSIONS,
  8. UPDATE_SORTED_SPEAKER_STATS_IDS,
  9. UPDATE_STATS
  10. } from './actionTypes';
  11. /**
  12. * The initial state of the feature speaker-stats.
  13. *
  14. * @type {Object}
  15. */
  16. const INITIAL_STATE = {
  17. stats: {},
  18. isOpen: false,
  19. pendingReorder: true,
  20. criteria: null,
  21. showFaceExpressions: false,
  22. sortedSpeakerStatsIds: []
  23. };
  24. export interface ISpeakerStatsState {
  25. criteria: string | null;
  26. isOpen: boolean;
  27. pendingReorder: boolean;
  28. showFaceExpressions: boolean;
  29. sortedSpeakerStatsIds: Array<string>;
  30. stats: Object;
  31. }
  32. ReducerRegistry.register<ISpeakerStatsState>('features/speaker-stats',
  33. (state = INITIAL_STATE, action): ISpeakerStatsState => {
  34. switch (action.type) {
  35. case INIT_SEARCH:
  36. return _updateCriteria(state, action);
  37. case UPDATE_STATS:
  38. return _updateStats(state, action);
  39. case INIT_REORDER_STATS:
  40. return _initReorderStats(state);
  41. case UPDATE_SORTED_SPEAKER_STATS_IDS:
  42. return _updateSortedSpeakerStats(state, action);
  43. case RESET_SEARCH_CRITERIA:
  44. return _updateCriteria(state, { criteria: null });
  45. case TOGGLE_FACE_EXPRESSIONS: {
  46. return {
  47. ...state,
  48. showFaceExpressions: !state.showFaceExpressions
  49. };
  50. }
  51. }
  52. return state;
  53. });
  54. /**
  55. * Reduces a specific Redux action INIT_SEARCH of the feature
  56. * speaker-stats.
  57. *
  58. * @param {Object} state - The Redux state of the feature speaker-stats.
  59. * @param {Action} action - The Redux action INIT_SEARCH to reduce.
  60. * @private
  61. * @returns {Object} The new state after the reduction of the specified action.
  62. */
  63. function _updateCriteria(state: ISpeakerStatsState, { criteria }: { criteria: string | null; }) {
  64. return _.assign(
  65. {},
  66. state,
  67. { criteria }
  68. );
  69. }
  70. /**
  71. * Reduces a specific Redux action UPDATE_STATS of the feature speaker-stats.
  72. *
  73. * @param {Object} state - The Redux state of the feature speaker-stats.
  74. * @param {Action} action - The Redux action UPDATE_STATS to reduce.
  75. * @private
  76. * @returns {Object} - The new state after the reduction of the specified action.
  77. */
  78. function _updateStats(state: ISpeakerStatsState, { stats }: { stats: any; }) {
  79. return {
  80. ...state,
  81. stats
  82. };
  83. }
  84. /**
  85. * Reduces a specific Redux action UPDATE_SORTED_SPEAKER_STATS_IDS of the feature speaker-stats.
  86. *
  87. * @param {Object} state - The Redux state of the feature speaker-stats.
  88. * @param {Action} action - The Redux action UPDATE_SORTED_SPEAKER_STATS_IDS to reduce.
  89. * @private
  90. * @returns {Object} The new state after the reduction of the specified action.
  91. */
  92. function _updateSortedSpeakerStats(state: ISpeakerStatsState, { participantIds }: { participantIds: Array<string>; }) {
  93. return {
  94. ...state,
  95. sortedSpeakerStatsIds: participantIds,
  96. pendingReorder: false
  97. };
  98. }
  99. /**
  100. * Reduces a specific Redux action INIT_REORDER_STATS of the feature
  101. * speaker-stats.
  102. *
  103. * @param {Object} state - The Redux state of the feature speaker-stats.
  104. * @private
  105. * @returns {Object} The new state after the reduction of the specified action.
  106. */
  107. function _initReorderStats(state: ISpeakerStatsState) {
  108. return _.assign(
  109. {},
  110. state,
  111. { pendingReorder: true }
  112. );
  113. }