2019-11-08 16:42:39 +00:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import { MiddlewareRegistry } from '../../base/redux';
|
|
|
|
|
2020-06-02 09:03:17 +00:00
|
|
|
import { CLIENT_RESIZED } from './actionTypes';
|
2019-11-08 16:42:39 +00:00
|
|
|
import { setAspectRatio, setReducedUI } from './actions';
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Middleware that handles widnow dimension changes and updates the aspect ratio and
|
|
|
|
* reduced UI modes accordingly.
|
|
|
|
*
|
|
|
|
* @param {Store} store - The redux store.
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
2020-06-02 09:03:17 +00:00
|
|
|
MiddlewareRegistry.register(({ dispatch }) => next => action => {
|
2019-11-08 16:42:39 +00:00
|
|
|
const result = next(action);
|
|
|
|
|
|
|
|
switch (action.type) {
|
2020-06-02 09:03:17 +00:00
|
|
|
case CLIENT_RESIZED: {
|
|
|
|
const { clientWidth: width, clientHeight: height } = action;
|
|
|
|
|
|
|
|
dispatch(setAspectRatio(width, height));
|
|
|
|
dispatch(setReducedUI(width, height));
|
2019-11-08 16:42:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
});
|