2018-02-14 18:28:22 +00:00
|
|
|
// @flow
|
|
|
|
|
2017-10-13 16:13:46 +00:00
|
|
|
import { ReducerRegistry, set } from '../redux';
|
|
|
|
|
2020-01-24 16:28:47 +00:00
|
|
|
import { CLIENT_RESIZED, SET_ASPECT_RATIO, SET_REDUCED_UI } from './actionTypes';
|
2017-10-13 16:13:46 +00:00
|
|
|
import { ASPECT_RATIO_NARROW } from './constants';
|
|
|
|
|
2020-01-24 16:28:47 +00:00
|
|
|
const {
|
|
|
|
innerHeight = 0,
|
|
|
|
innerWidth = 0
|
|
|
|
} = window;
|
|
|
|
|
2017-11-07 14:28:08 +00:00
|
|
|
/**
|
2018-02-14 18:28:22 +00:00
|
|
|
* The default/initial redux state of the feature base/responsive-ui.
|
2017-11-07 14:28:08 +00:00
|
|
|
*/
|
2018-02-14 18:28:22 +00:00
|
|
|
const DEFAULT_STATE = {
|
2018-02-02 13:39:27 +00:00
|
|
|
aspectRatio: ASPECT_RATIO_NARROW,
|
2020-01-24 16:28:47 +00:00
|
|
|
clientHeight: innerHeight,
|
|
|
|
clientWidth: innerWidth,
|
2018-02-02 13:39:27 +00:00
|
|
|
reducedUI: false
|
2017-10-13 16:13:46 +00:00
|
|
|
};
|
|
|
|
|
2019-11-08 16:42:39 +00:00
|
|
|
ReducerRegistry.register('features/base/responsive-ui', (state = DEFAULT_STATE, action) => {
|
|
|
|
switch (action.type) {
|
2020-01-24 16:28:47 +00:00
|
|
|
case CLIENT_RESIZED: {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
clientWidth: action.clientWidth,
|
|
|
|
clientHeight: action.clientHeight
|
|
|
|
};
|
|
|
|
}
|
2019-11-08 16:42:39 +00:00
|
|
|
case SET_ASPECT_RATIO:
|
|
|
|
return set(state, 'aspectRatio', action.aspectRatio);
|
2018-02-02 13:39:27 +00:00
|
|
|
|
2019-11-08 16:42:39 +00:00
|
|
|
case SET_REDUCED_UI:
|
|
|
|
return set(state, 'reducedUI', action.reducedUI);
|
|
|
|
}
|
2017-10-13 16:13:46 +00:00
|
|
|
|
2019-11-08 16:42:39 +00:00
|
|
|
return state;
|
|
|
|
});
|