12345678910111213141516171819202122232425262728 |
- /* eslint-disable @typescript-eslint/camelcase */
- import { Dispatch } from 'react';
- import { CHANGE_SCALE, TOGGLE_DISPLAY_MODE } from '../../constants/actionTypes';
- const applyMiddleware = (
- state: any, dispatch: Dispatch<any>,
- ) => (
- action: { type: string; payload?: any },
- ): void => {
- dispatch(action);
- switch (action.type) {
- case TOGGLE_DISPLAY_MODE: {
- if (action.payload === 'full') {
- const screenWidth = window.document.body.offsetWidth - 5;
- const originPdfWidth = state.viewport.width / state.scale;
- const rate = (screenWidth / originPdfWidth).toFixed(2);
- dispatch({ type: CHANGE_SCALE, payload: rate });
- } else {
- dispatch({ type: CHANGE_SCALE, payload: 1 });
- }
- break;
- }
- default:
- break;
- }
- };
- export default applyMiddleware;
|