2021-09-09 22:46:41 +00:00
|
|
|
import _ from 'lodash';
|
|
|
|
|
2022-09-01 11:00:49 +00:00
|
|
|
import ReducerRegistry from '../base/redux/ReducerRegistry';
|
2021-09-09 22:46:41 +00:00
|
|
|
|
|
|
|
import {
|
2021-12-13 14:11:07 +00:00
|
|
|
INIT_REORDER_STATS,
|
2022-09-27 07:10:28 +00:00
|
|
|
INIT_SEARCH,
|
2021-12-28 14:35:21 +00:00
|
|
|
RESET_SEARCH_CRITERIA,
|
2022-09-27 07:10:28 +00:00
|
|
|
TOGGLE_FACE_EXPRESSIONS,
|
2022-09-28 07:51:53 +00:00
|
|
|
UPDATE_SORTED_SPEAKER_STATS_IDS,
|
2022-09-27 07:10:28 +00:00
|
|
|
UPDATE_STATS
|
2021-09-09 22:46:41 +00:00
|
|
|
} from './actionTypes';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The initial state of the feature speaker-stats.
|
|
|
|
*
|
|
|
|
* @type {Object}
|
|
|
|
*/
|
|
|
|
const INITIAL_STATE = {
|
|
|
|
stats: {},
|
2021-11-10 17:49:53 +00:00
|
|
|
isOpen: false,
|
2021-09-09 22:46:41 +00:00
|
|
|
pendingReorder: true,
|
2021-12-28 14:35:21 +00:00
|
|
|
criteria: null,
|
2022-09-28 07:51:53 +00:00
|
|
|
showFaceExpressions: false,
|
|
|
|
sortedSpeakerStatsIds: []
|
2021-09-09 22:46:41 +00:00
|
|
|
};
|
|
|
|
|
2022-09-01 11:00:49 +00:00
|
|
|
export interface ISpeakerStatsState {
|
2022-09-08 09:52:36 +00:00
|
|
|
criteria: string | null;
|
2022-09-01 11:00:49 +00:00
|
|
|
isOpen: boolean;
|
|
|
|
pendingReorder: boolean;
|
|
|
|
showFaceExpressions: boolean;
|
2022-09-28 07:51:53 +00:00
|
|
|
sortedSpeakerStatsIds: Array<string>;
|
2022-09-01 11:00:49 +00:00
|
|
|
stats: Object;
|
|
|
|
}
|
|
|
|
|
2022-09-05 09:05:07 +00:00
|
|
|
ReducerRegistry.register<ISpeakerStatsState>('features/speaker-stats',
|
|
|
|
(state = INITIAL_STATE, action): ISpeakerStatsState => {
|
2021-09-09 22:46:41 +00:00
|
|
|
switch (action.type) {
|
|
|
|
case INIT_SEARCH:
|
|
|
|
return _updateCriteria(state, action);
|
|
|
|
case UPDATE_STATS:
|
|
|
|
return _updateStats(state, action);
|
|
|
|
case INIT_REORDER_STATS:
|
|
|
|
return _initReorderStats(state);
|
2022-09-28 07:51:53 +00:00
|
|
|
case UPDATE_SORTED_SPEAKER_STATS_IDS:
|
|
|
|
return _updateSortedSpeakerStats(state, action);
|
2021-12-13 14:11:07 +00:00
|
|
|
case RESET_SEARCH_CRITERIA:
|
|
|
|
return _updateCriteria(state, { criteria: null });
|
2022-04-06 09:10:31 +00:00
|
|
|
case TOGGLE_FACE_EXPRESSIONS: {
|
2021-12-28 14:35:21 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2022-04-06 09:10:31 +00:00
|
|
|
showFaceExpressions: !state.showFaceExpressions
|
2021-12-28 14:35:21 +00:00
|
|
|
};
|
|
|
|
}
|
2021-09-09 22:46:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reduces a specific Redux action INIT_SEARCH of the feature
|
|
|
|
* speaker-stats.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state of the feature speaker-stats.
|
|
|
|
* @param {Action} action - The Redux action INIT_SEARCH to reduce.
|
|
|
|
* @private
|
|
|
|
* @returns {Object} The new state after the reduction of the specified action.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
function _updateCriteria(state: ISpeakerStatsState, { criteria }: { criteria: string | null; }) {
|
2021-09-09 22:46:41 +00:00
|
|
|
return _.assign(
|
|
|
|
{},
|
|
|
|
state,
|
2021-11-04 21:10:43 +00:00
|
|
|
{ criteria }
|
2021-09-09 22:46:41 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-09-28 07:51:53 +00:00
|
|
|
* Reduces a specific Redux action UPDATE_STATS of the feature speaker-stats.
|
2021-09-09 22:46:41 +00:00
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state of the feature speaker-stats.
|
|
|
|
* @param {Action} action - The Redux action UPDATE_STATS to reduce.
|
|
|
|
* @private
|
|
|
|
* @returns {Object} - The new state after the reduction of the specified action.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
function _updateStats(state: ISpeakerStatsState, { stats }: { stats: any; }) {
|
2022-09-28 07:51:53 +00:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
stats
|
|
|
|
};
|
|
|
|
}
|
2021-09-09 22:46:41 +00:00
|
|
|
|
2022-09-28 07:51:53 +00:00
|
|
|
/**
|
|
|
|
* Reduces a specific Redux action UPDATE_SORTED_SPEAKER_STATS_IDS of the feature speaker-stats.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state of the feature speaker-stats.
|
|
|
|
* @param {Action} action - The Redux action UPDATE_SORTED_SPEAKER_STATS_IDS to reduce.
|
|
|
|
* @private
|
|
|
|
* @returns {Object} The new state after the reduction of the specified action.
|
|
|
|
*/
|
|
|
|
function _updateSortedSpeakerStats(state: ISpeakerStatsState, { participantIds }: { participantIds: Array<string>; }) {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
sortedSpeakerStatsIds: participantIds,
|
|
|
|
pendingReorder: false
|
|
|
|
};
|
2021-09-09 22:46:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reduces a specific Redux action INIT_REORDER_STATS of the feature
|
|
|
|
* speaker-stats.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state of the feature speaker-stats.
|
|
|
|
* @private
|
|
|
|
* @returns {Object} The new state after the reduction of the specified action.
|
|
|
|
*/
|
2022-09-01 11:00:49 +00:00
|
|
|
function _initReorderStats(state: ISpeakerStatsState) {
|
2021-09-09 22:46:41 +00:00
|
|
|
return _.assign(
|
|
|
|
{},
|
|
|
|
state,
|
2021-11-04 21:10:43 +00:00
|
|
|
{ pendingReorder: true }
|
2021-09-09 22:46:41 +00:00
|
|
|
);
|
|
|
|
}
|