index.ts 826 B

12345678910111213141516171819202122232425262728
  1. /* eslint-disable @typescript-eslint/camelcase */
  2. import { Dispatch } from 'react';
  3. import { CHANGE_SCALE, TOGGLE_DISPLAY_MODE } from '../../constants/actionTypes';
  4. const applyMiddleware = (
  5. state: any, dispatch: Dispatch<any>,
  6. ) => (
  7. action: { type: string; payload?: any },
  8. ): void => {
  9. dispatch(action);
  10. switch (action.type) {
  11. case TOGGLE_DISPLAY_MODE: {
  12. if (action.payload === 'full') {
  13. const screenWidth = window.document.body.offsetWidth - 5;
  14. const originPdfWidth = state.viewport.width / state.scale;
  15. const rate = (screenWidth / originPdfWidth).toFixed(2);
  16. dispatch({ type: CHANGE_SCALE, payload: rate });
  17. } else {
  18. dispatch({ type: CHANGE_SCALE, payload: 1 });
  19. }
  20. break;
  21. }
  22. default:
  23. break;
  24. }
  25. };
  26. export default applyMiddleware;