jiti-meet/react/features/overlay/reducer.ts

85 lines
2.7 KiB
TypeScript
Raw Normal View History

import { CONFIG_WILL_LOAD, LOAD_CONFIG_ERROR, SET_CONFIG } from '../base/config/actionTypes';
import ReducerRegistry from '../base/redux/ReducerRegistry';
import { assign, set } from '../base/redux/functions';
import {
MEDIA_PERMISSION_PROMPT_VISIBILITY_CHANGED,
SET_FATAL_ERROR
} from './actionTypes';
export interface IOverlayState {
browser?: string;
fatalError?: Error;
isMediaPermissionPromptVisible?: boolean;
loadConfigOverlayVisible?: boolean;
}
/**
* Reduces the redux actions of the feature overlay.
*
* FIXME: these pieces of state should probably be in a different place.
*/
2022-09-05 09:05:07 +00:00
ReducerRegistry.register<IOverlayState>('features/overlay', (state = {}, action): IOverlayState => {
switch (action.type) {
2019-04-09 15:53:12 +00:00
case CONFIG_WILL_LOAD:
return _setShowLoadConfigOverlay(state, Boolean(action.room));
case LOAD_CONFIG_ERROR:
case SET_CONFIG:
return _setShowLoadConfigOverlay(state, false);
2019-04-09 15:53:12 +00:00
case MEDIA_PERMISSION_PROMPT_VISIBILITY_CHANGED:
return _mediaPermissionPromptVisibilityChanged(state, action);
case SET_FATAL_ERROR:
return _setFatalError(state, action);
}
return state;
});
/**
* Reduces a specific redux action MEDIA_PERMISSION_PROMPT_VISIBILITY_CHANGED of
2017-02-19 00:42:11 +00:00
* the feature overlay.
*
* @param {Object} state - The redux state of the feature overlay.
* @param {Action} action - The redux action to reduce.
* @private
2017-02-19 00:42:11 +00:00
* @returns {Object} The new state of the feature overlay after the reduction of
* the specified action.
*/
2017-10-04 22:36:09 +00:00
function _mediaPermissionPromptVisibilityChanged(
state: IOverlayState,
{ browser, isVisible }: { browser?: string; isVisible?: boolean; }) {
return assign(state, {
2017-10-04 22:36:09 +00:00
browser,
isMediaPermissionPromptVisible: isVisible
});
}
/**
2019-04-09 15:53:12 +00:00
* Sets the {@code LoadConfigOverlay} overlay visible or not.
*
* @param {Object} state - The redux state of the feature overlay.
2019-04-09 15:53:12 +00:00
* @param {boolean} show - Whether to show or not the overlay.
2017-02-19 00:42:11 +00:00
* @returns {Object} The new state of the feature overlay after the reduction of
* the specified action.
*/
function _setShowLoadConfigOverlay(state: IOverlayState, show?: boolean) {
2019-04-09 15:53:12 +00:00
return set(state, 'loadConfigOverlayVisible', show);
}
/**
* Reduces a specific redux action {@code SET_FATAL_ERROR} of the feature
* overlay.
*
* @param {Object} state - The redux state of the feature overlay.
* @param {Error} fatalError - If the value is set it indicates that a fatal
* error has occurred and that the reload screen is to be displayed.
* @returns {Object}
* @private
*/
function _setFatalError(state: IOverlayState, { fatalError }: { fatalError?: Error; }) {
return set(state, 'fatalError', fatalError);
}