2021-09-09 22:46:41 +00:00
|
|
|
import {
|
|
|
|
PARTICIPANT_JOINED,
|
|
|
|
PARTICIPANT_KICKED,
|
|
|
|
PARTICIPANT_LEFT,
|
|
|
|
PARTICIPANT_UPDATED
|
|
|
|
} from '../base/participants/actionTypes';
|
2022-10-26 06:59:21 +00:00
|
|
|
import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
|
2021-09-09 22:46:41 +00:00
|
|
|
|
2021-11-10 17:49:53 +00:00
|
|
|
import {
|
|
|
|
INIT_SEARCH,
|
2021-12-28 14:35:21 +00:00
|
|
|
INIT_UPDATE_STATS,
|
|
|
|
RESET_SEARCH_CRITERIA
|
2021-11-10 17:49:53 +00:00
|
|
|
} from './actionTypes';
|
2022-09-28 07:51:53 +00:00
|
|
|
import { initReorderStats, updateSortedSpeakerStatsIds, updateStats } from './actions';
|
|
|
|
import { filterBySearchCriteria, getPendingReorder, getSortedSpeakerStatsIds, resetHiddenStats } from './functions';
|
2021-09-09 22:46:41 +00:00
|
|
|
|
|
|
|
MiddlewareRegistry.register(({ dispatch, getState }) => next => action => {
|
|
|
|
const result = next(action);
|
|
|
|
|
|
|
|
switch (action.type) {
|
|
|
|
case INIT_SEARCH: {
|
|
|
|
const state = getState();
|
|
|
|
const stats = filterBySearchCriteria(state);
|
|
|
|
|
|
|
|
dispatch(updateStats(stats));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case INIT_UPDATE_STATS:
|
|
|
|
if (action.getSpeakerStats) {
|
|
|
|
const state = getState();
|
|
|
|
const speakerStats = { ...action.getSpeakerStats() };
|
|
|
|
const stats = filterBySearchCriteria(state, speakerStats);
|
|
|
|
const pendingReorder = getPendingReorder(state);
|
|
|
|
|
2022-09-28 07:51:53 +00:00
|
|
|
if (pendingReorder) {
|
|
|
|
dispatch(updateSortedSpeakerStatsIds(getSortedSpeakerStatsIds(state, stats)));
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch(updateStats(stats));
|
2021-09-09 22:46:41 +00:00
|
|
|
}
|
2022-09-28 07:51:53 +00:00
|
|
|
|
2021-09-09 22:46:41 +00:00
|
|
|
break;
|
2021-12-28 14:35:21 +00:00
|
|
|
|
|
|
|
case RESET_SEARCH_CRITERIA: {
|
|
|
|
const state = getState();
|
|
|
|
const stats = resetHiddenStats(state);
|
|
|
|
|
|
|
|
dispatch(updateStats(stats));
|
|
|
|
break;
|
|
|
|
}
|
2021-09-09 22:46:41 +00:00
|
|
|
case PARTICIPANT_JOINED:
|
|
|
|
case PARTICIPANT_LEFT:
|
|
|
|
case PARTICIPANT_KICKED:
|
|
|
|
case PARTICIPANT_UPDATED: {
|
|
|
|
dispatch(initReorderStats());
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
});
|